From 861290ce40282f3c53b59f7035c2747f6dea1ca7 Mon Sep 17 00:00:00 2001 From: "Valeriya(vchu)" Date: Mon, 6 Nov 2023 16:00:27 +0100 Subject: [PATCH] [FIX] payment_stripe: instantiate stripe object only once Steps to reproduce: 1. Activate Stripe and at least two payment methods 2. Click on the first pm 3. Click on the second pm 3. Select again the first one and try to pay The bug was caused by reinstantiation of stripeJS for each payment method. So that each stripe element was created from different stripeJS object which raised the following error from Stripe: "Invalid value for stripe.confirmPayment(): the 'elements' provided was created by a different Stripe instance. Please use the same Stripe instance to create the 'elements' and call stripe.confirmPayment()" After this commit StripeJS object is instantiated only once. closes odoo/odoo#141247 Signed-off-by: Antoine Vandevenne (anv) --- addons/payment_stripe/static/src/js/payment_form.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/payment_stripe/static/src/js/payment_form.js b/addons/payment_stripe/static/src/js/payment_form.js index 5c830b85439..5975f671568 100644 --- a/addons/payment_stripe/static/src/js/payment_form.js +++ b/addons/payment_stripe/static/src/js/payment_form.js @@ -48,6 +48,13 @@ paymentForm.include({ stripeInlineForm.dataset['stripeInlineFormValues'] ); + // Instantiate Stripe object if needed. + this.stripeJS ??= Stripe( + this.stripeInlineFormValues['publishable_key'], + // The values required by Stripe Connect are inserted into the dataset. + new StripeOptions()._prepareStripeOptions(stripeInlineForm.dataset), + ); + // Instantiate the elements. let elementsOptions = { appearance: { theme: 'stripe' }, @@ -69,11 +76,6 @@ paymentForm.include({ elementsOptions.mode = 'setup'; elementsOptions.setupFutureUsage = 'off_session'; } - this.stripeJS = Stripe( - this.stripeInlineFormValues['publishable_key'], - // The values required by Stripe Connect are inserted into the dataset. - new StripeOptions()._prepareStripeOptions(stripeInlineForm.dataset), - ); this.stripeElements[paymentOptionId] = this.stripeJS.elements(elementsOptions); // Instantiate the payment element.