From 19525b4b4a05121e07ba14cbf203fec218e7c8ed Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Mon, 24 Jun 2024 16:00:26 -0300 Subject: [PATCH] Fix: make Stripe Element gateway work with the API keys connection method (#7415) --- .../stripePaymentElementGateway.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx index 24f93cb9d4..3e5a0573cb 100644 --- a/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx +++ b/src/PaymentGateways/Gateways/Stripe/StripePaymentElementGateway/stripePaymentElementGateway.tsx @@ -91,6 +91,7 @@ interface StripeGateway extends Gateway { } /** + * @unreleased Use only stripeKey to load the Stripe script (when stripeConnectedAccountId is missing) to prevent errors when the account is connected through API keys * @since 3.12.1 updated afterCreatePayment response type to include billing details address * @since 3.0.0 */ @@ -99,7 +100,7 @@ const stripePaymentElementGateway: StripeGateway = { initialize() { const {stripeKey, stripeConnectedAccountId, formId} = this.settings; - if (!stripeKey || !stripeConnectedAccountId) { + if (!stripeKey && !stripeConnectedAccountId) { throw new Error('Stripe gateway settings are missing. Check your Stripe settings.'); } @@ -109,9 +110,14 @@ const stripePaymentElementGateway: StripeGateway = { * Create the Stripe object and pass our api keys * @see https://stripe.com/docs/payments/accept-a-payment-deferred */ - stripePromise = loadStripe(stripeKey, { - stripeAccount: stripeConnectedAccountId, - }); + stripePromise = loadStripe( + stripeKey, + stripeConnectedAccountId + ? { + stripeAccount: stripeConnectedAccountId, + } + : {} + ); }, beforeCreatePayment: async function (values): Promise { if (!this.stripe || !this.elements) {