diff options
Diffstat (limited to 'addons/payment_authorize/controllers/main.py')
| -rw-r--r-- | addons/payment_authorize/controllers/main.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py index 6b0aae9bf6a..9614327401a 100644 --- a/addons/payment_authorize/controllers/main.py +++ b/addons/payment_authorize/controllers/main.py @@ -3,8 +3,9 @@ import pprint import logging from werkzeug import urls, utils -from odoo import http +from odoo import http, _ from odoo.http import request +from odoo.exceptions import ValidationError _logger = logging.getLogger(__name__) @@ -35,11 +36,35 @@ class AuthorizeController(http.Controller): def authorize_s2s_create_json(self, **kwargs): acquirer_id = int(kwargs.get('acquirer_id')) 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 @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 = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))).s2s_process(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) + token = acquirer.s2s_process(kwargs) + except ValidationError as e: + message = e.args[0] + if isinstance(message, dict) and 'missing_fields' in message: + msg = _("The transaction cannot be processed because some contact details are missing or invalid: ") + message = msg + ', '.join(message['missing_fields']) + '. ' + if request.env.user._is_public(): + message += _("Please sign in to complete your profile.") + # update message if portal mode = b2b + if request.env['ir.config_parameter'].sudo().get_param('auth_signup.allow_uninvited', 'False').lower() == 'false': + message += _("If you don't have any account, please ask your salesperson to update your profile. ") + else: + message += _("Please complete your profile. ") + + return { + 'error': message + } if not token: res = { |
