[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<xpath expr="//div[hasclass('o_portal_my_details')]" position="inside">
|
||||
<t t-set="partner" t-value="request.env.user.partner_id"/>
|
||||
<t t-set="acquirers_allowing_tokenization"
|
||||
t-value="request.env['payment.acquirer'].sudo()._get_compatible_acquirers(request.env.company.id, partner.id, allow_tokenization=True)"/>
|
||||
t-value="request.env['payment.acquirer'].sudo()._get_compatible_acquirers(request.env.company.id, partner.id, allow_tokenization=True, is_validation=True)"/>
|
||||
<t t-set="existing_tokens" t-value="partner.payment_token_ids + partner.commercial_partner_id.sudo().payment_token_ids"/>
|
||||
<!-- Only show the link if a token can be created or if one already exists -->
|
||||
<div t-if="acquirers_allowing_tokenization or existing_tokens"
|
||||
|
||||
Reference in New Issue
Block a user