[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) <anv@odoo.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user