From ca6fcfb65c44bcd2017303dd90d5e72786d5b447 Mon Sep 17 00:00:00 2001 From: "Valeriya(vchu)" Date: Thu, 1 Feb 2024 16:09:51 +0100 Subject: [PATCH] [FIX] payment_stripe: handle errors on load and submit Steps to reproduce: 1) Try to make a payment with the amount less than 0.50$ (minimum amount required in Stripe) 2) Stripe inline form fails to load 3) One can still click pay and see the traceback After this commit the error are handled and displayed on the form loading and on the form submit. opw-3634316 closes odoo/odoo#152307 Signed-off-by: Antoine Vandevenne (anv) --- addons/payment_stripe/i18n/payment_stripe.pot | 7 +++++++ .../payment_stripe/static/src/js/payment_form.js | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/addons/payment_stripe/i18n/payment_stripe.pot b/addons/payment_stripe/i18n/payment_stripe.pot index 2067a400b76..1f461b9a18a 100644 --- a/addons/payment_stripe/i18n/payment_stripe.pot +++ b/addons/payment_stripe/i18n/payment_stripe.pot @@ -15,6 +15,13 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: payment_stripe +#. odoo-javascript +#: code:addons/payment_stripe/static/src/js/payment_form.js:0 +#, python-format +msgid "Cannot display the payment form" +msgstr "" + #. module: payment_stripe #: model:ir.model.fields,field_description:payment_stripe.field_payment_provider__code msgid "Code" diff --git a/addons/payment_stripe/static/src/js/payment_form.js b/addons/payment_stripe/static/src/js/payment_form.js index 5975f671568..658de37d274 100644 --- a/addons/payment_stripe/static/src/js/payment_form.js +++ b/addons/payment_stripe/static/src/js/payment_form.js @@ -87,6 +87,9 @@ paymentForm.include({ const paymentElement = this.stripeElements[paymentOptionId].create( 'payment', paymentElementOptions ); + paymentElement.on('loaderror', response => { + this._displayErrorDialog(_t("Cannot display the payment form"), response.error.message); + }); paymentElement.mount(stripeInlineForm); const tokenizationCheckbox = inlineForm.querySelector( @@ -126,13 +129,14 @@ paymentForm.include({ // Trigger form validation and wallet collection. const _super = this._super.bind(this); - const { error: submitError } = await this.stripeElements[paymentOptionId].submit(); - if (submitError) { - this._displayErrorDialog(_t("Incorrect payment details")); + try { + await this.stripeElements[paymentOptionId].submit(); + } catch (error) { + this._displayErrorDialog(_t("Incorrect payment details"), error.message); this._enableButton(); - } else { // There is no invalid input, resume the generic flow. - return await _super(...arguments); + return } + return await _super(...arguments); }, /**