From be2ce0522e52afc3a9fd39f164e56bcc1f369790 Mon Sep 17 00:00:00 2001 From: nie Date: Mon, 11 Jan 2021 16:49:23 +0000 Subject: [PATCH] [FIX] payment_authorize: Show UserError to user Steps: - Install website_sale and payment_authorize - Set up a tunnel (e.g. ngrok) - Log in to Authorize.Net backend - Go to Account > Response/Receipt URLs > Add Url - Enter the tunnel URL - In Odoo, go to Website > Configuration > eCommerce > Payment Acquirers - Edit "Authorize.Net" - Credentials tab: - State: Test Mode - API Login Id, Transaction and Signature key - Save, then Generate Client Key - Configuration tab: - Payment Flow: Payment from Odoo - Stop the server - Replace https://github.com/odoo/odoo/blob/1b9b99dc2643910c1412b564affccf02ba1e55d9/addons/payment_authorize/models/authorize_request.py#L46 with `resp = {'messages': {'resultCode': 'Error', 'message': [{'code': 'E00027', 'text': 'An error occurred during processing. Call Merchant Service Provider.'}]}}` - Restart the server - Go to "Website" > "Go to Website" > Shop - Add a product to the basket - Check out the basket - Choose "Credit Card (powered by Authorize) Test Mode" - Pay Now - Enter any card data (e.g. 4111 1111 1111 1111 - 01/22 - 900) Bug: When the Pay Now process is done, the customer is redirected to `/shop?error=invalid_token_id`. No errors are shown. Explanation: The patch simulates an error from Authorize.Net happening during their process. Using the special card numbers won't trigger the wanted behavior. When getting an error from Authorize.net, a `UserError` is raised. This error is then caught in the controller to return a formatted message. However, returning a dict in this part of the code embeds it inside `{'result': [...]}`. The error message is, thus, not blocking the form's redirection and the user gets redirected to the form action, i.e. `/shop/payment/token`. This route requires `pm_id`, but, in this scenario, it's an empty string. This leads to another redirection to `/shop/?error=invalid_token_id` as seen here: https://github.com/odoo/odoo/blob/1b9b99dc2643910c1412b564affccf02ba1e55d9/addons/website_sale/controllers/main.py#L938-L941 Letting the error bubble up forces the backend to return a blocking error response. This makes the fronted display the Authorize.Net error underneath the provider selection, and prevents it from redirecting. opw:2419260 closes odoo/odoo#64482 X-original-commit: 2636b9f5059808b443be67b06fca129cf9d3a913 Signed-off-by: backspac --- addons/payment_authorize/controllers/main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py index 4417f0408bb..cf917adffcb 100644 --- a/addons/payment_authorize/controllers/main.py +++ b/addons/payment_authorize/controllers/main.py @@ -55,10 +55,6 @@ class AuthorizeController(http.Controller): return { 'error': message } - except UserError as e: - return { - 'error': e.args[0], - } if not token: res = {