diff --git a/backend/app/DomainObjects/OrderDomainObject.php b/backend/app/DomainObjects/OrderDomainObject.php index 723e98b90..43826af07 100644 --- a/backend/app/DomainObjects/OrderDomainObject.php +++ b/backend/app/DomainObjects/OrderDomainObject.php @@ -286,4 +286,40 @@ public function isRefundable(): bool && $this->getPaymentProvider() === PaymentProviders::STRIPE->name && $this->getRefundStatus() !== OrderRefundStatus::REFUNDED->name; } + + public function getAddressLine1(): ?string + { + $address = $this->getAddress(); + return $address['address_line_1'] ?? null; + } + + public function getAddressLine2(): ?string + { + $address = $this->getAddress(); + return $address['address_line_2'] ?? null; + } + + public function getCity(): ?string + { + $address = $this->getAddress(); + return $address['city'] ?? null; + } + + public function getState(): ?string + { + $address = $this->getAddress(); + return $address['state_or_region'] ?? $address['state'] ?? null; + } + + public function getPostalCode(): ?string + { + $address = $this->getAddress(); + return $address['zip_or_postal_code'] ?? $address['postal_code'] ?? null; + } + + public function getCountryCode(): ?string + { + $address = $this->getAddress(); + return $address['country'] ?? null; + } } diff --git a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php index c4a6d2e63..fd20f93e7 100644 --- a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php +++ b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php @@ -110,6 +110,17 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO ); } + $description = sprintf( + 'Event tickets - Order %s - %s ticket(s) - %s', + $orderShortId, + count($order->getOrderItems()), + $account->getName() ?? 'Event Registration' + ); + + if (strlen($description) > 1000) { + $description = substr($description, 0, 997) . '...'; + } + $paymentIntent = $this->stripePaymentService->createPaymentIntentWithClient( $stripeClient, CreatePaymentIntentRequestDTO::fromArray([ @@ -119,6 +130,7 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO 'order' => $order, 'stripeAccountId' => $stripeAccountId, 'vatSettings' => $account->getAccountVatSetting(), + 'description' => $description, ]) ); diff --git a/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php b/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php index de4ac4b32..d6fdb9ea3 100644 --- a/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php +++ b/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php @@ -17,6 +17,7 @@ public function __construct( public readonly OrderDomainObject $order, public readonly ?string $stripeAccountId = null, public readonly ?AccountVatSettingDomainObject $vatSettings = null, + public readonly ?string $description = null, ) { } diff --git a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php index bd38c4f46..3f8ca35a1 100644 --- a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php +++ b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php @@ -80,6 +80,7 @@ public function createPaymentIntentWithClient( 'automatic_payment_methods' => [ 'enabled' => true, ], + ...($paymentIntentDTO->description ? ['description' => $paymentIntentDTO->description] : []), ...($applicationFee ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []), ], $this->getStripeAccountData($paymentIntentDTO)); @@ -154,11 +155,25 @@ private function upsertStripeCustomerWithClient( ]); if ($customer === null) { + $order = $paymentIntentDTO->order; + + $customerData = [ + 'email' => $order->getEmail(), + 'name' => $order->getFullName(), + ]; + + if ($order->getAddressLine1() && $order->getCountryCode()) { + $customerData['address'] = [ + 'line1' => $order->getAddressLine1(), + 'line2' => $order->getAddressLine2() ?? '', + 'city' => $order->getCity() ?? '', + 'state' => $order->getState() ?? '', + 'postal_code' => $order->getPostalCode() ?? '', + 'country' => $order->getCountryCode(), + ]; + } $stripeCustomer = $stripeClient->customers->create( - params: [ - 'email' => $paymentIntentDTO->order->getEmail(), - 'name' => $paymentIntentDTO->order->getFullName(), - ], + params: $customerData, opts: $this->getStripeAccountData($paymentIntentDTO) );