From 8aff186d35950a0495d4d4d48b74ecbc95c2a60e Mon Sep 17 00:00:00 2001 From: Jon Waldstein Date: Mon, 3 Jun 2024 16:24:06 -0400 Subject: [PATCH] Fix: return donation billing address in Stripe Payment Element Gateway (#7395) Co-authored-by: Jon Waldstein Co-authored-by: Jon Waldstein --- .../StripePaymentElementGateway.php | 12 +++++++++++- .../stripePaymentElementGateway.tsx | 12 ++++++++++++ .../TestStripePaymentElementGateway.php | 11 ++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/StripePaymentElementGateway.php b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/StripePaymentElementGateway.php index f9fcb0160f..48b97e2a6e 100644 --- a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/StripePaymentElementGateway.php +++ b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/StripePaymentElementGateway.php @@ -89,6 +89,8 @@ public function formSettings(int $formId): array } /** + * @unreleased updated to send billing address details to Stripe + * @since 3.0.0 * @inheritDoc * @throws ApiErrorException */ @@ -144,7 +146,15 @@ public function createPayment(Donation $donation, $gatewayData): GatewayCommand 'returnUrl' => $stripeGatewayData->successUrl, 'billingDetails' => [ 'name' => trim("$donation->firstName $donation->lastName"), - 'email' => $donation->email + 'email' => $donation->email, + 'address' => [ + 'city' => $donation->billingAddress->city, + 'country' => $donation->billingAddress->country, + 'line1' => $donation->billingAddress->address1, + 'line2' => $donation->billingAddress->address2, + 'postal_code' => $donation->billingAddress->zip, + 'state' => $donation->billingAddress->state, + ], ], ]); } diff --git a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx index 5c1a57adae..ae9478a996 100644 --- a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx +++ b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx @@ -89,6 +89,10 @@ interface StripeGateway extends Gateway { settings?: StripeSettings; } +/** + * @unreleased updated afterCreatePayment response type to include billing details address + * @since 3.0.0 + */ const stripePaymentElementGateway: StripeGateway = { id: 'stripe_payment_element', initialize() { @@ -135,6 +139,14 @@ const stripePaymentElementGateway: StripeGateway = { billingDetails: { name: string; email: string; + address?: { + city?: string; + country?: string; + line1?: string; + line2?: string; + postal_code?: string; + state?: string; + } }; }; }): Promise { diff --git a/tests/Feature/Gateways/Stripe/StripePaymentElement/TestStripePaymentElementGateway.php b/tests/Feature/Gateways/Stripe/StripePaymentElement/TestStripePaymentElementGateway.php index 16edc601da..c2133aa0e6 100644 --- a/tests/Feature/Gateways/Stripe/StripePaymentElement/TestStripePaymentElementGateway.php +++ b/tests/Feature/Gateways/Stripe/StripePaymentElement/TestStripePaymentElementGateway.php @@ -57,6 +57,7 @@ public function testFormSettingsShouldReturnData() } /** + * @unreleased updated to send billing address details to Stripe * @since 3.0.0 * * @throws \Give\Framework\Exceptions\Primitives\Exception @@ -140,7 +141,15 @@ public function testCreatePaymentShouldReturnRespondToBrowserCommand() 'returnUrl' => $gatewayData['successUrl'], 'billingDetails' => [ 'name' => trim("$donation->firstName $donation->lastName"), - 'email' => $donation->email + 'email' => $donation->email, + 'address' => [ + 'city' => $donation->billingAddress->city, + 'country' => $donation->billingAddress->country, + 'line1' => $donation->billingAddress->address1, + 'line2' => $donation->billingAddress->address2, + 'postal_code' => $donation->billingAddress->zip, + 'state' => $donation->billingAddress->state, + ], ] ]) );