From 6ed44181d081b3cfd8875dc82e4e155970cc07f5 Mon Sep 17 00:00:00 2001 From: Toufik Benjaa Date: Wed, 11 Jul 2018 17:47:29 +0200 Subject: [PATCH] [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 --- addons/account/controllers/portal.py | 2 + addons/account_payment/controllers/payment.py | 8 +- addons/account_payment/models/payment.py | 3 +- .../views/account_portal_templates.xml | 8 +- addons/payment/__manifest__.py | 1 + addons/payment/controllers/portal.py | 121 ++++++++++++-- addons/payment/data/payment_cron.xml | 14 ++ addons/payment/models/payment_acquirer.py | 60 +++++-- .../static/src/js/payment_processing.js | 125 +++++++++++++++ .../static/src/xml/payment_processing.xml | 150 ++++++++++++++++++ addons/payment/views/assets.xml | 1 + .../views/payment_portal_templates.xml | 6 +- addons/payment/views/payment_templates.xml | 123 +++++++------- addons/payment_adyen/controllers/main.py | 6 +- addons/payment_authorize/controllers/main.py | 21 ++- addons/payment_buckaroo/controllers/main.py | 2 +- addons/payment_ogone/controllers/main.py | 18 ++- addons/payment_paypal/controllers/main.py | 33 ++-- addons/payment_paypal/models/payment.py | 2 +- addons/payment_payumoney/controllers/main.py | 4 +- addons/payment_sips/controllers/main.py | 18 +-- addons/payment_stripe/controllers/main.py | 5 +- addons/payment_stripe/models/payment.py | 1 - addons/payment_transfer/controllers/main.py | 2 +- addons/sale/controllers/portal.py | 6 +- addons/sale/models/payment.py | 5 +- addons/sale/views/sale_portal_templates.xml | 2 +- .../static/src/js/website.tour.event_sale.js | 7 +- addons/website_sale/controllers/main.py | 26 ++- .../static/src/js/website_sale_tour_buy.js | 7 +- addons/website_sale/views/templates.xml | 26 +-- 31 files changed, 636 insertions(+), 177 deletions(-) create mode 100644 addons/payment/data/payment_cron.xml create mode 100644 addons/payment/static/src/js/payment_processing.js create mode 100644 addons/payment/static/src/xml/payment_processing.xml diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 0da2bd0ce5d..e66e6a68d35 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -3,6 +3,7 @@ from odoo import http, _ from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager +from odoo.addons.payment.controllers.portal import PaymentProcessing from odoo.exceptions import AccessError, MissingError from odoo.http import request @@ -87,6 +88,7 @@ class PortalAccount(CustomerPortal): return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download) values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) + PaymentProcessing.remove_payment_transaction(invoice_sudo.transaction_ids) return request.render("account.portal_invoice_page", values) # ------------------------------------------------------------ diff --git a/addons/account_payment/controllers/payment.py b/addons/account_payment/controllers/payment.py index 5c3f6f0ea31..c9ef4530f99 100644 --- a/addons/account_payment/controllers/payment.py +++ b/addons/account_payment/controllers/payment.py @@ -3,6 +3,7 @@ from odoo import http, _ from odoo.addons.portal.controllers.portal import _build_url_w_params +from odoo.addons.payment.controllers.portal import PaymentProcessing from odoo.http import request, route @@ -31,16 +32,17 @@ class PaymentPortal(http.Controller): save_token = False # we avoid to create a token for the public user vals = { 'acquirer_id': acquirer_id, + 'return_url': success_url, } if save_token: vals['type'] = 'form_save' transaction = invoice_sudo._create_payment_transaction(vals) + PaymentProcessing.add_payment_transaction(transaction) return transaction.render_invoice_button( invoice_sudo, - success_url, submit_txt=_('Pay & Confirm'), render_values={ 'type': 'form_save' if save_token else 'form', @@ -75,9 +77,11 @@ class PaymentPortal(http.Controller): vals = { 'payment_token_id': token.id, 'type': 'server2server', + 'return_url': success_url, } - invoice_sudo._create_payment_transaction(vals) + tx = invoice_sudo._create_payment_transaction(vals) + PaymentProcessing.add_payment_transaction(tx) params['success'] = 'pay_invoice' return request.redirect(_build_url_w_params(success_url, params)) diff --git a/addons/account_payment/models/payment.py b/addons/account_payment/models/payment.py index 5669d2b300d..7d20ec0d6b0 100644 --- a/addons/account_payment/models/payment.py +++ b/addons/account_payment/models/payment.py @@ -12,9 +12,8 @@ _logger = logging.getLogger(__name__) class PaymentTransaction(models.Model): _inherit = 'payment.transaction' - def render_invoice_button(self, invoice, return_url, submit_txt=None, render_values=None): + def render_invoice_button(self, invoice, submit_txt=None, render_values=None): values = { - 'return_url': return_url, 'partner_id': invoice.partner_id.id, } if render_values: diff --git a/addons/account_payment/views/account_portal_templates.xml b/addons/account_payment/views/account_portal_templates.xml index ffcbb7f99c6..0c7ddc0ce88 100644 --- a/addons/account_payment/views/account_portal_templates.xml +++ b/addons/account_payment/views/account_portal_templates.xml @@ -45,7 +45,7 @@