[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) <anv@odoo.com>
This commit is contained in:
Valeriya(vchu)
2023-11-06 16:55:47 +00:00
parent ca3d390033
commit 861290ce40
@@ -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.