Prechádzať zdrojové kódy

Send shipping address to Stripe; update name sent to Stripe to include legal entity name if available

Alan Lam 1 rok pred
rodič
commit
4a0dab652f
1 zmenil súbory, kde vykonal 20 pridanie a 7 odobranie
  1. 20 7
      engine/helpers/stripe_helper.php

+ 20 - 7
engine/helpers/stripe_helper.php

@@ -29,10 +29,28 @@ class StripeHelper {
 	public function createOrUpdateCustomer(Location $location): Customer {
 		$customer = $location->getCustomer();
 
+		if($location->legal_entity_name) {
+			$name = sprintf("%s - %s (%s)", $customer->name, $location->name, $location->legal_entity_name);
+		}
+		else {
+			$name = sprintf("%s - %s", $customer->name, $location->name);
+		}
+
 		$data = [
-			"name" => $customer->name . " - " . $location->name,
+			"name" => $name,
 			"email" => $location->email,
 			"phone" => $location->phone,
+			"shipping" => array_filter([
+				"address" => array_filter([
+					"city" => $location->city,
+					"line1" => $location->address_1,
+					"line2" => $location->address_2,
+					"postal_code" => $location->postal_code,
+					"state" => $location->county,
+				]),
+				"name" => $name,
+				"phone" => $location->phone,
+			]),
 			"metadata" => [
 				"location_id" => $location->id,
 			]
@@ -59,12 +77,7 @@ class StripeHelper {
 	 */
 	public function createInvoice(Test $test, string $price): Invoice {
 		$location = $test->getLocation();
-		if($location->stripe_customer_id) {
-			$customer = $this->client->customers->retrieve($location->stripe_customer_id);
-		}
-		else {
-			$customer = $this->createOrUpdateCustomer($location);
-		}
+		$customer = $this->createOrUpdateCustomer($location);
 
 		if($test->stripe_invoice_id) {
 			return $this->client->invoices->retrieve($test->stripe_invoice_id);