summaryrefslogtreecommitdiff
path: root/addons/payment_authorize
diff options
context:
space:
mode:
authorToufik Benjaa <tbe@odoo.com>2018-07-11 17:47:29 +0200
committerToufik Benjaa <tbe@odoo.com>2018-09-19 18:25:32 +0200
commit6ed44181d081b3cfd8875dc82e4e155970cc07f5 (patch)
tree5449ac99ea4191b9b747918d0d1d8702ebad3cc5 /addons/payment_authorize
parent46dc8ceef90ec5472b1aa4b45509f23d6c3e2624 (diff)
[IMP] payment_*: payment acquirers error handling
This commit aims to improve the user experience when using payment acquirers. There currently are no error feedback with some acquirers, which leaves the user wondering what is going on and what is the real status of its payment. In some cases, the user is currently being redirected to the home page even though the payment has failed. We want to make it more obvious to the user that something unexpected has happened by redirecting to an intermediate page that will provide good feedback on payments status. Another goal of this commit is to order acquirers by sequence instead of by flow and to select the first acquirer by default. This feature was already implmented in commit fe294fd43e521bd2d339e962f43acf46c3d4cb97, some UI adaptations were needed though. Related to task #36680 Closes #26958
Diffstat (limited to 'addons/payment_authorize')
-rw-r--r--addons/payment_authorize/controllers/main.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py
index 9614327401a..dd8d96f6e90 100644
--- a/addons/payment_authorize/controllers/main.py
+++ b/addons/payment_authorize/controllers/main.py
@@ -5,7 +5,7 @@ from werkzeug import urls, utils
from odoo import http, _
from odoo.http import request
-from odoo.exceptions import ValidationError
+from odoo.exceptions import ValidationError, UserError
_logger = logging.getLogger(__name__)
@@ -20,16 +20,14 @@ class AuthorizeController(http.Controller):
], type='http', auth='public', csrf=False)
def authorize_form_feedback(self, **post):
_logger.info('Authorize: entering form_feedback with post data %s', pprint.pformat(post))
- return_url = '/'
if post:
request.env['payment.transaction'].sudo().form_feedback(post, 'authorize')
- return_url = post.pop('return_url', '/')
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
# Authorize.Net is expecting a response to the POST sent by their server.
# This response is in the form of a URL that Authorize.Net will pass on to the
# client's browser to redirect them to the desired location need javascript.
return request.render('payment_authorize.payment_authorize_redirect', {
- 'return_url': urls.url_join(base_url, return_url)
+ 'return_url': urls.url_join(base_url, "/payment/process")
})
@http.route(['/payment/authorize/s2s/create_json'], type='json', auth='public')
@@ -38,13 +36,18 @@ class AuthorizeController(http.Controller):
acquirer = request.env['payment.acquirer'].browse(acquirer_id)
if not kwargs.get('partner_id'):
kwargs = dict(kwargs, partner_id=request.env.user.partner_id.id)
- return acquirer.s2s_process(kwargs).id
+ try:
+ return acquirer.s2s_process(kwargs).id
+ except (ValidationError, UserError) as e:
+ return {
+ 'error': e.name,
+ }
@http.route(['/payment/authorize/s2s/create_json_3ds'], type='json', auth='public', csrf=False)
def authorize_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
token = False
acquirer = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id')))
-
+
try:
if not kwargs.get('partner_id'):
kwargs = dict(kwargs, partner_id=request.env.user.partner_id.id)
@@ -65,6 +68,10 @@ class AuthorizeController(http.Controller):
return {
'error': message
}
+ except UserError as e:
+ return {
+ 'error': e.name,
+ }
if not token:
res = {
@@ -91,4 +98,4 @@ class AuthorizeController(http.Controller):
acquirer_id = int(post.get('acquirer_id'))
acquirer = request.env['payment.acquirer'].browse(acquirer_id)
acquirer.s2s_process(post)
- return utils.redirect(post.get('return_url', '/'))
+ return utils.redirect("/payment/process")