From 6df3cdaaa7fc6ed75dc1c7241953f98727842967 Mon Sep 17 00:00:00 2001 From: "Antoine Vandevenne (anv)" Date: Fri, 9 Jul 2021 07:17:28 +0000 Subject: [PATCH] [IMP] payment: make the distinction between tokenization and validation Before this commit, it was not possible for an acquirer to support tokenization while not supporting validation because the acquirer would be thought to be compatible with either flow based on the `support_tokenization` field. This was a false assumption because some acquirers, such as Ogone, can offer to tokenize a payment method in payment with redirection flow while not allowing tokenizing a payment method for future usage, without payment. Note that this was not an issue for acquirers supporting the direct payment flow because they could either support validation natively, or seamlessly charge a small amount and refund it immediately to tokenize a payment method. This commit makes it possible for a module implementing the validation operation to filter acquirers based on whether they support it, regardless of their support for tokenization. task-2494916 --- addons/payment/controllers/portal.py | 2 +- addons/payment/models/payment_acquirer.py | 4 +++- addons/payment/views/payment_portal_templates.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index bf0312bd613..88b3b7c08b5 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -157,7 +157,7 @@ class PaymentPortal(portal.CustomerPortal): """ partner = request.env.user.partner_id acquirers_sudo = request.env['payment.acquirer'].sudo()._get_compatible_acquirers( - request.env.company.id, partner.id, force_tokenization=True + request.env.company.id, partner.id, force_tokenization=True, is_validation=True ) tokens = set(partner.payment_token_ids).union( partner.commercial_partner_id.sudo().payment_token_ids diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index f4baccbd7a7..5daccfe1890 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -271,7 +271,8 @@ class PaymentAcquirer(models.Model): @api.model def _get_compatible_acquirers( - self, company_id, partner_id, currency_id=None, force_tokenization=False, **kwargs + self, company_id, partner_id, currency_id=None, force_tokenization=False, + is_validation=False, **kwargs ): """ Select and return the acquirers matching the criteria. @@ -282,6 +283,7 @@ class PaymentAcquirer(models.Model): :param int partner_id: The partner making the payment, as a `res.partner` id :param int currency_id: The payment currency if known beforehand, as a `res.currency` id :param bool force_tokenization: Whether only acquirers allowing tokenization can be matched + :param bool is_validation: Whether the operation is a validation :param dict kwargs: Optional data. This parameter is not used here :return: The compatible acquirers :rtype: recordset of `payment.acquirer` diff --git a/addons/payment/views/payment_portal_templates.xml b/addons/payment/views/payment_portal_templates.xml index 7703b29fa6d..c60f24ac88b 100644 --- a/addons/payment/views/payment_portal_templates.xml +++ b/addons/payment/views/payment_portal_templates.xml @@ -6,7 +6,7 @@ + t-value="request.env['payment.acquirer'].sudo()._get_compatible_acquirers(request.env.company.id, partner.id, allow_tokenization=True, is_validation=True)"/>