From 22df074e7b1bd68069f6959cd56fb9316f289e7d Mon Sep 17 00:00:00 2001 From: Jason Van Malder Date: Thu, 28 Nov 2019 11:28:00 +0000 Subject: [PATCH] [FIX] payment_stripe: fix bad request not displaying Reproduce the issue - Install eCommerce - Activate stripe, use testing credentials and select Configuration > Payment Flow > Payment from Odoo - Create a contact that has a trailing whitespace at the beginning of the email - Grant him portal access, and a password - Open your browser devtools - Login to the web shop with this portal user and buy an item using stripe 1. Error Dialog: Server Error (HTTP 500) 2. The exception received by the front-end is not clear 3. When the 500 error is fixed, we still have a error dialog => bad UX Cause 1. The raise was removed but we need to keep it because it allows the true error to be raised (bad request) 2. The "invalid email address: x" is lost when we raise the exception 3. In V13, all catch & guardedCatch open a error dialog if we don't set preventDefaulted to true on the error's event This commit changes restore the raise, change the error message and disable the error dialog for this case. OPW-2126196 closes odoo/odoo#41087 X-original-commit: b8d013285ba54c8d3ab4a3857604dfca3e479b39 Signed-off-by: Jason Van Malder --- addons/payment_stripe/models/payment.py | 3 +++ addons/payment_stripe/static/src/js/payment_form.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py index 1cb2adf97c1..39a8a67493e 100644 --- a/addons/payment_stripe/models/payment.py +++ b/addons/payment_stripe/models/payment.py @@ -69,6 +69,9 @@ class PaymentAcquirerStripe(models.Model): "Request data:\n%s\n" "Response body:\n%s", url, pprint.pformat(data), resp.text) + stripe_error = resp.json().get('error', {}).get('message', '') + error_msg = " " + (_("Stripe gave us the following info about the problem: '%s'") % stripe_error) + raise ValidationError(error_msg) return resp.json() def _create_stripe_session(self, kwargs): diff --git a/addons/payment_stripe/static/src/js/payment_form.js b/addons/payment_stripe/static/src/js/payment_form.js index 8671e67e4e9..5ed4200a88c 100644 --- a/addons/payment_stripe/static/src/js/payment_form.js +++ b/addons/payment_stripe/static/src/js/payment_form.js @@ -79,6 +79,9 @@ PaymentForm.include({ self.el.submit(); } }).guardedCatch(function (error) { + // We don't want to open the Error dialog since + // we already have a container displaying the error + error.event.preventDefault(); // if the rpc fails, pretty obvious self.enableButton(button); self.displayError(