[IMP] payment, *: replace providers with payment methods in payment forms

Before this commit, the payment providers (e.g., Stripe, Adyen...)
available for payment were displayed on the payment forms. The customer
had to select one to process their payment. After that, the customer had
to select their preferred payment method (e.g., Credit Card,
Bancontact...) from a list of payment methods supported by the selected
provider over which the website administrator had close to no control.
This was making the payment forms confusing because the payment methods
were displayed sometimes more than once, if at all, in a non-controlled
order, and behind the selection of a payment provider that customers
should not have to deal with.

As the payment method was selected in an iframe or directly on the
provider's website, the information on the selection payment method was
not available in Odoo. This posed many problems, among which were the
impossibility of assessing whether a specific feature (e.g.,
tokenization, refunds, manual capture...) was available, not being able
to easily identify payment tokens through the payment method logo,
listing available payment methods on the website, sorting and
fine-grained configuration of the available payment method, subpar
payment method-specific display on the payment form (e.g., PayPal that
requires displaying a "Pay with PayPal" button), etc.

In this commit, the payment providers are thus replaced by the payment
methods on the payment forms. All contextually available (depending on
the country, currency, requested feature...) payment methods are
displayed one after the other on a single-level list and in the order
configured by the website administrator. Each payment method is
"powered by" (i.e., linked) to a single payment provider: the first one,
by model order, to support it. This allows, for example, offering the
PayPal payment method through Mollie, which charges low processing fees,
while also offering Klarna through Stripe, which supports more payment
methods but charges higher processing fees.

While doing so, the two different payment forms, "Checkout" and
"Manage", are also merged together in a new, configurable case-by-case,
payment form that is entirely redesigned to offer a better user
experience.

After payment, the information on the selected payment method is saved
on the transaction and eventual payment record and updated with the
information received from the provider.

task-2882677

closes odoo/odoo#120446

Related: odoo/upgrade#5103
Related: odoo/documentation#5717
Related: odoo/enterprise#40666
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
Co-authored-by: Anita (anko) <anko@odoo.com>
Co-authored-by: Brieuc-brd <brd@odoo.com>
Co-authored-by: Valeriya (vchu) <vchu@odoo.com>
This commit is contained in:
Antoine Vandevenne (anv)
2023-09-22 13:32:53 +00:00
committed by Valeriya(vchu)
co-authored by Anita Brieuc-brd Valeriya
parent ec1d70617f
commit 7e012dd544
337 changed files with 8176 additions and 3678 deletions
+1 -1
View File
@@ -62,7 +62,7 @@
<menuitem id="menu_action_account_journal_group_list" action="action_account_journal_group_list" groups="account.group_account_manager" sequence="7"/>
<menuitem id="menu_action_tax_group" action="action_tax_group" sequence="8" groups="base.group_no_one"/>
</menuitem>
<menuitem id="root_payment_menu" name="Payments" groups="account.group_account_manager" sequence="4"/>
<menuitem id="root_payment_menu" name="Online Payments" groups="account.group_account_manager" sequence="4"/>
<menuitem id="account_management_menu" name="Management" groups="account.group_account_manager" sequence="5">
<menuitem id="menu_product_product_categories" action="product.product_category_action_form" sequence="3"/>
<menuitem id="menu_action_rounding_form_view" action="rounding_list_action" groups="account.group_cash_rounding" sequence="4"/>
+1 -1
View File
@@ -16,10 +16,10 @@
'views/account_payment_menus.xml',
'views/account_portal_templates.xml',
'views/payment_templates.xml',
'views/account_move_views.xml',
'views/account_journal_views.xml',
'views/account_payment_views.xml',
'views/payment_form_templates.xml',
'views/payment_provider_views.xml',
'views/payment_transaction_views.xml',
@@ -80,26 +80,24 @@ class PaymentPortal(payment_portal.PaymentPortal):
})
return super().payment_pay(*args, amount=amount, access_token=access_token, **kwargs)
def _get_custom_rendering_context_values(self, invoice_id=None, **kwargs):
""" Override of `payment` to add the invoice id in the custom rendering context values.
def _get_extra_payment_form_values(self, invoice_id=None, **kwargs):
""" Override of `payment` to add the invoice id to the payment form values.
:param int invoice_id: The invoice for which a payment id made, as an `account.move` id.
:param dict kwargs: Optional data. This parameter is not used here.
:return: The extended rendering context values.
:rtype: dict
"""
rendering_context_values = super()._get_custom_rendering_context_values(
invoice_id=invoice_id, **kwargs
)
form_values = super()._get_extra_payment_form_values(invoice_id=invoice_id, **kwargs)
if invoice_id:
rendering_context_values['invoice_id'] = invoice_id
form_values['invoice_id'] = invoice_id
# Interrupt the payment flow if the invoice has been canceled.
invoice_sudo = request.env['account.move'].sudo().browse(invoice_id)
if invoice_sudo.state == 'cancel':
rendering_context_values['amount'] = 0.0
form_values['amount'] = 0.0
return rendering_context_values
return form_values
def _create_transaction(self, *args, invoice_id=None, custom_create_values=None, **kwargs):
""" Override of `payment` to add the invoice id in the custom create values.
+23 -10
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.http import request
@@ -8,7 +7,7 @@ from odoo.addons.payment.controllers.portal import PaymentPortal
from odoo.addons.portal.controllers.portal import _build_url_w_params
class PortalAccount(portal.PortalAccount):
class PortalAccount(portal.PortalAccount, PaymentPortal):
def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
values = super()._invoice_get_page_view_values(invoice, access_token, **kwargs)
@@ -24,15 +23,21 @@ class PortalAccount(portal.PortalAccount):
partner_sudo = request.env.user.partner_id if logged_in else invoice.partner_id
invoice_company = invoice.company_id or request.env.company
# Select all the payment methods and tokens that match the payment context.
providers_sudo = request.env['payment.provider'].sudo()._get_compatible_providers(
invoice_company.id,
partner_sudo.id,
invoice.amount_total,
currency_id=invoice.currency_id.id
) # In sudo mode to read the fields of providers and partner (if not logged in)
) # In sudo mode to read the fields of providers and partner (if logged out).
payment_methods_sudo = request.env['payment.method'].sudo()._get_compatible_payment_methods(
providers_sudo.ids,
partner_sudo.id,
currency_id=invoice.currency_id.id,
) # In sudo mode to read the fields of providers.
tokens_sudo = request.env['payment.token'].sudo()._get_available_tokens(
providers_sudo.ids, partner_sudo.id
) # In sudo mode to read the partner's tokens (if logged out).
) # In sudo mode to read the partner's tokens (if logged out) and provider fields.
# Make sure that the partner's company matches the invoice's company.
company_mismatch = not PaymentPortal._can_partner_pay_in_company(
@@ -44,17 +49,25 @@ class PortalAccount(portal.PortalAccount):
'expected_company': invoice_company,
}
payment_form_values = {
'providers': providers_sudo,
'tokens': tokens_sudo,
'show_tokenize_input': PaymentPortal._compute_show_tokenize_input_mapping(
'show_tokenize_input_mapping': PaymentPortal._compute_show_tokenize_input_mapping(
providers_sudo
),
}
payment_context = {
'amount': invoice.amount_residual,
'currency': invoice.currency_id,
'partner_id': partner_sudo.id,
'access_token': access_token,
'providers_sudo': providers_sudo,
'payment_methods_sudo': payment_methods_sudo,
'tokens_sudo': tokens_sudo,
'transaction_route': f'/invoice/transaction/{invoice.id}/',
'landing_route': _build_url_w_params(invoice.access_url, {'access_token': access_token})
'landing_route': invoice.get_portal_url(),
'access_token': access_token,
}
values.update(**portal_page_values, **payment_form_values)
values.update(
**portal_page_values,
**payment_form_values,
**payment_context,
**self._get_extra_payment_form_values(**kwargs),
)
return values
@@ -48,7 +48,11 @@ class AccountPayment(models.Model):
def _compute_amount_available_for_refund(self):
for payment in self:
tx_sudo = payment.payment_transaction_id.sudo()
if tx_sudo.provider_id.support_refund and tx_sudo.operation != 'refund':
if (
tx_sudo.provider_id.support_refund
and tx_sudo.payment_method_id.support_refund
and tx_sudo.operation != 'refund'
):
# Only consider refund transactions that are confirmed by summing the amounts of
# payments linked to such refund transactions. Indeed, should a refund transaction
# be stuck forever in a transient state (due to webhook failure, for example), the
@@ -192,6 +196,7 @@ class AccountPayment(models.Model):
self.ensure_one()
return {
'provider_id': self.payment_token_id.provider_id.id,
'payment_method_id': self.payment_token_id.payment_method_id.id,
'reference': self.ref,
'amount': self.amount,
'currency_id': self.currency_id.id,
@@ -1,33 +1,25 @@
/** @odoo-module **/
import checkoutForm from '@payment/js/checkout_form';
import manageForm from '@payment/js/manage_form';
import paymentForm from '@payment/js/payment_form';
const PaymentMixin = {
paymentForm.include({
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
// #=== PAYMENT FLOW ===#
/**
* Add `invoice_id` to the transaction route params if it is provided.
* Add `invoice_id` to the params for the RPC to the transaction route.
*
* @override method from @payment/js/payment_form_mixin
* @override method from @payment/js/payment_form
* @private
* @param {string} code - The provider code of the selected payment option.
* @param {number} paymentOptionId - The id of the selected payment option.
* @param {string} flow - The online payment flow of the selected payment option.
* @return {object} The extended transaction route params.
*/
_prepareTransactionRouteParams: function (code, paymentOptionId, flow) {
_prepareTransactionRouteParams() {
const transactionRouteParams = this._super(...arguments);
return {
...transactionRouteParams,
'invoice_id': this.txContext.invoiceId ? parseInt(this.txContext.invoiceId) : null,
'invoice_id': this.paymentContext['invoiceId']
? parseInt(this.paymentContext['invoiceId']) : null,
};
},
};
checkoutForm.include(PaymentMixin);
manageForm.include(PaymentMixin);
});
@@ -16,7 +16,7 @@ class TestFlows(AccountPaymentCommon, PaymentHttpCommon):
# Pay for this invoice (no impact even if amounts do not match)
route_values = self._prepare_pay_values()
route_values['invoice_id'] = self.invoice.id
tx_context = self._get_tx_checkout_context(**route_values)
tx_context = self._get_portal_pay_context(**route_values)
self.assertEqual(tx_context['invoice_id'], self.invoice.id)
# payment/transaction
@@ -33,8 +33,10 @@ class TestFlows(AccountPaymentCommon, PaymentHttpCommon):
]
}
route_values.update({
'provider_id': self.provider.id,
'payment_method_id': self.payment_method_id,
'token_id': None,
'flow': 'direct',
'payment_option_id': self.provider.id,
'tokenization_requested': False,
})
with mute_logger('odoo.addons.payment.models.payment_transaction'):
@@ -8,7 +8,6 @@
<menuitem action="payment.action_payment_method"
id="payment_method_menu"
parent="account.root_payment_menu"
groups="base.group_no_one"
sequence="15"/>
<menuitem action="payment.action_payment_token"
id="payment_token_menu"
@@ -44,13 +44,14 @@
<div t-if="company_mismatch">
<t t-call="payment.company_mismatch_warning"/>
</div>
<div t-elif="providers or tokens" id="payment_method" class="text-start col-md-13">
<t t-call="payment.checkout"/>
</div>
<div t-else="" class="alert alert-warning">
<strong>No suitable payment option could be found.</strong><br/>
If you believe that it is an error, please contact the website administrator.
<div t-elif="not payment_methods_sudo and not tokens_sudo"
class="alert alert-warning"
>
<strong>No suitable payment method could be found.</strong><br/>
If you believe that it is an error, please contact the website
administrator.
</div>
<t t-else="" t-call="payment.form"/>
</div>
</div>
</div>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Include account-related values to the payment form to pass them to the client. -->
<template id="payment_form_inherit" inherit_id="payment.form">
<xpath expr="//form[@id='o_payment_form']" position="attributes">
<attribute name="t-att-data-invoice-id">invoice_id</attribute>
</xpath>
</template>
</odoo>
@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Include account-related values in payment checkout form to pass them to the client -->
<template id="payment_checkout_inherit" inherit_id="payment.checkout">
<xpath expr="//form[@name='o_payment_checkout']" position="attributes">
<attribute name="t-att-data-invoice-id">invoice_id</attribute>
</xpath>
</template>
<!-- Include account-related values in payment manage form to pass them to the client -->
<template id="payment_manage_inherit" inherit_id="payment.manage">
<xpath expr="//form[@name='o_payment_manage']" position="attributes">
<attribute name="t-att-data-invoice-id">invoice_id</attribute>
</xpath>
</template>
</odoo>
@@ -26,7 +26,11 @@ class PaymentRefundWizard(models.TransientModel):
string="Refund Amount", compute='_compute_amount_to_refund', store=True, readonly=False
)
currency_id = fields.Many2one(string="Currency", related='transaction_id.currency_id')
support_refund = fields.Selection(related='transaction_id.provider_id.support_refund')
support_refund = fields.Selection(
string="Type of Refund Supported",
selection=[('full_only', "Full Only"), ('partial', "Partial")],
compute='_compute_support_refund',
)
has_pending_refund = fields.Boolean(
string="Has a pending refund", compute='_compute_has_pending_refund'
)
@@ -51,6 +55,18 @@ class PaymentRefundWizard(models.TransientModel):
for wizard in self:
wizard.amount_to_refund = wizard.amount_available_for_refund
@api.depends('transaction_id.provider_id', 'transaction_id.payment_method_id')
def _compute_support_refund(self):
for wizard in self:
p_support_refund = wizard.transaction_id.provider_id.support_refund
pm_support_refund = wizard.transaction_id.payment_method_id.support_refund
if not p_support_refund or not pm_support_refund:
wizard.support_refund = False
elif p_support_refund == 'full_only' or pm_support_refund == 'full_only':
wizard.support_refund = 'full_only'
else: # Both support partial refunds.
wizard.support_refund = 'partial'
@api.depends('payment_id') # To always trigger the compute
def _compute_has_pending_refund(self):
for wizard in self:
+1
View File
@@ -210,6 +210,7 @@ class TestSwissQR(AccountTestInvoicingCommon):
})
payment_transaction = self.env['payment.transaction'].create({
'provider_id': provider.id,
'payment_method_id': self.env.ref('payment.payment_method_unknown').id,
'sale_order_ids': [order.id],
'partner_id': self.env['res.partner'].search([("name", '=', 'Partner')])[0].id,
'amount': 100,
+11 -12
View File
@@ -7,38 +7,37 @@
'summary': "The payment engine used by payment provider modules.",
'depends': ['onboarding', 'portal'],
'data': [
# Record data.
'data/onboarding_data.xml',
'data/payment_method_data.xml',
'data/payment_provider_data.xml',
'data/payment_cron.xml',
'views/payment_portal_templates.xml',
'views/payment_templates.xml',
# QWeb templates.
'views/express_checkout_templates.xml',
'views/payment_form_templates.xml',
'views/portal_templates.xml',
'views/payment_provider_views.xml',
# Model views.
'views/payment_method_views.xml',
'views/payment_provider_views.xml', # Depends on `action_payment_method`.
'views/payment_transaction_views.xml',
'views/payment_token_views.xml', # Depends on `action_payment_transaction_linked_to_token`
'views/payment_token_views.xml', # Depends on `action_payment_transaction_linked_to_token`.
'views/res_partner_views.xml',
# Security.
'security/ir.model.access.csv',
'security/payment_security.xml',
# Wizard views.
'wizards/payment_capture_wizard_views.xml',
'wizards/payment_link_wizard_views.xml',
'wizards/payment_onboarding_views.xml',
],
'assets': {
'web.assets_frontend': [
'payment/static/src/scss/payment_templates.scss',
'payment/static/src/scss/payment_form.scss',
'payment/static/lib/jquery.payment/jquery.payment.js',
'payment/static/src/js/checkout_form.js',
'payment/static/src/js/express_checkout_form.js',
'payment/static/src/js/manage_form.js',
'payment/static/src/js/payment_form_mixin.js',
'payment/static/src/js/post_processing.js',
'payment/static/src/xml/*.xml',
'payment/static/src/**/*',
],
'web.assets_backend': [
'payment/static/src/scss/payment_provider.scss',
+100 -65
View File
@@ -1,10 +1,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import urllib.parse
import werkzeug
from odoo import _, http
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.exceptions import AccessError, ValidationError
from odoo.http import request
from odoo.addons.payment import utils as payment_utils
@@ -38,7 +39,7 @@ class PaymentPortal(portal.CustomerPortal):
)
def payment_pay(
self, reference=None, amount=None, currency_id=None, partner_id=None, company_id=None,
provider_id=None, access_token=None, **kwargs
access_token=None, **kwargs
):
""" Display the payment form with optional filtering of payment options.
@@ -47,26 +48,27 @@ class PaymentPortal(portal.CustomerPortal):
In addition to the desired filtering, a second one ensures that none of the following
rules is broken:
- Public users are not allowed to save their payment method as a token.
- Payments made by public users should either *not* be made on behalf of a specific
partner or have an access token validating the partner, amount and currency.
We let access rights and security rules do their job for logged in users.
:param str reference: The custom prefix to compute the full reference
:param str amount: The amount to pay
:param str currency_id: The desired currency, as a `res.currency` id
:param str partner_id: The partner making the payment, as a `res.partner` id
:param str company_id: The related company, as a `res.company` id
:param str provider_id: The desired provider, as a `payment.provider` id
:param str access_token: The access token used to authenticate the partner
- Public users are not allowed to save their payment method as a token.
- Payments made by public users should either *not* be made on behalf of a specific partner
or have an access token validating the partner, amount and currency.
We let access rights and security rules do their job for logged users.
:param str reference: The custom prefix to compute the full reference.
:param str amount: The amount to pay.
:param str currency_id: The desired currency, as a `res.currency` id.
:param str partner_id: The partner making the payment, as a `res.partner` id.
:param str company_id: The related company, as a `res.company` id.
:param str access_token: The access token used to authenticate the partner.
:param dict kwargs: Optional data passed to helper methods.
:return: The rendered checkout form
:return: The rendered payment form.
:rtype: str
:raise: werkzeug.exceptions.NotFound if the access token is invalid
:raise werkzeug.exceptions.NotFound: If the access token is invalid.
"""
# Cast numeric parameters as int or float and void them if their str value is malformed
currency_id, provider_id, partner_id, company_id = tuple(map(
self._cast_as_int, (currency_id, provider_id, partner_id, company_id)
currency_id, partner_id, company_id = tuple(map(
self._cast_as_int, (currency_id, partner_id, company_id)
))
amount = self._cast_as_float(amount)
@@ -106,15 +108,18 @@ class PaymentPortal(portal.CustomerPortal):
if not currency or not currency.active:
raise werkzeug.exceptions.NotFound() # The currency must exist and be active.
# Select all providers and tokens that match the constraints
# Select all the payment methods and tokens that match the payment context.
providers_sudo = request.env['payment.provider'].sudo()._get_compatible_providers(
company_id, partner_sudo.id, amount, currency_id=currency.id, **kwargs
) # In sudo mode to read the fields of providers and partner (if not logged in)
if provider_id in providers_sudo.ids: # Only keep the desired provider if it's suitable
providers_sudo = providers_sudo.browse(provider_id)
) # In sudo mode to read the fields of providers and partner (if logged out).
payment_methods_sudo = request.env['payment.method'].sudo()._get_compatible_payment_methods(
providers_sudo.ids,
partner_sudo.id,
currency_id=currency.id,
) # In sudo mode to read the fields of providers.
tokens_sudo = request.env['payment.token'].sudo()._get_available_tokens(
providers_sudo.ids, partner_sudo.id
) # In sudo mode to be able to read tokens of other partners.
) # In sudo mode to be able to read tokens of other partners and the fields of providers.
# Make sure that the partner's company matches the company passed as parameter.
company_mismatch = not PaymentPortal._can_partner_pay_in_company(partner_sudo, company)
@@ -123,27 +128,34 @@ class PaymentPortal(portal.CustomerPortal):
access_token = payment_utils.generate_access_token(partner_sudo.id, amount, currency.id)
portal_page_values = {
'res_company': company, # Display the correct logo in a multi-company environment.
'company_mismatch': company_mismatch,
'expected_company': company,
'partner_is_different': partner_is_different,
}
payment_form_values = {
'providers': providers_sudo,
'tokens': tokens_sudo,
'show_tokenize_input': self._compute_show_tokenize_input_mapping(
'show_tokenize_input_mapping': PaymentPortal._compute_show_tokenize_input_mapping(
providers_sudo, **kwargs
),
}
payment_context = {
'reference_prefix': reference,
'amount': amount,
'currency': currency,
'partner_id': partner_sudo.id,
'access_token': access_token,
'providers_sudo': providers_sudo,
'payment_methods_sudo': payment_methods_sudo,
'tokens_sudo': tokens_sudo,
'transaction_route': '/payment/transaction',
'landing_route': '/payment/confirmation',
'res_company': company, # Display the correct logo in a multi-company environment
**self._get_custom_rendering_context_values(**kwargs),
'access_token': access_token,
}
rendering_context = {
**portal_page_values,
**payment_form_values,
**payment_context,
**self._get_extra_payment_form_values(**kwargs),
}
rendering_context = {**portal_page_values, **payment_form_values}
return request.render(self._get_payment_page_template_xmlid(**kwargs), rendering_context)
@staticmethod
@@ -176,33 +188,54 @@ class PaymentPortal(portal.CustomerPortal):
:rtype: str
"""
partner_sudo = request.env.user.partner_id # env.user is always sudoed
# Select all the payment methods and tokens that match the payment context.
providers_sudo = request.env['payment.provider'].sudo()._get_compatible_providers(
request.env.company.id,
partner_sudo.id,
0., # There is no amount to pay with validation transactions.
force_tokenization=True,
is_validation=True,
)
**kwargs,
) # In sudo mode to read the fields of providers and partner (if logged out).
payment_methods_sudo = request.env['payment.method'].sudo()._get_compatible_payment_methods(
providers_sudo.ids,
partner_sudo.id,
force_tokenization=True,
) # In sudo mode to read the fields of providers.
tokens_sudo = request.env['payment.token'].sudo()._get_available_tokens(
None, partner_sudo.id, is_validation=True
) # In sudo mode to read the commercial partner's and providers' fields.
access_token = payment_utils.generate_access_token(partner_sudo.id, None, None)
rendering_context = {
'providers': providers_sudo,
'tokens': request.env['payment.token'].sudo()._get_available_tokens(
None, partner_sudo.id, is_validation=True
), # In sudo mode to read the commercial partner's fields.
payment_form_values = {
'mode': 'validation',
'allow_token_selection': False,
'allow_token_deletion': True,
}
payment_context = {
'reference_prefix': payment_utils.singularize_reference_prefix(prefix='V'),
'partner_id': partner_sudo.id,
'access_token': access_token,
'providers_sudo': providers_sudo,
'payment_methods_sudo': payment_methods_sudo,
'tokens_sudo': tokens_sudo,
'transaction_route': '/payment/transaction',
'landing_route': '/my/payment_method',
**self._get_custom_rendering_context_values(**kwargs),
'access_token': access_token,
}
rendering_context = {
**payment_form_values,
**payment_context,
**self._get_extra_payment_form_values(**kwargs),
}
return request.render('payment.payment_methods', rendering_context)
def _get_custom_rendering_context_values(self, **kwargs):
""" Return a dict of additional rendering context values.
def _get_extra_payment_form_values(self, **kwargs):
""" Return a dict of extra payment form values to include in the rendering context.
:param dict kwargs: Optional data. This parameter is not used here
:return: The dict of additional rendering context values
:param dict kwargs: Optional data. This parameter is not used here.
:return: The dict of extra payment form values.
:rtype: dict
"""
return {}
@@ -231,38 +264,39 @@ class PaymentPortal(portal.CustomerPortal):
tx_sudo = self._create_transaction(
amount=amount, currency_id=currency_id, partner_id=partner_id, **kwargs
)
self._update_landing_route(tx_sudo, access_token) # Add the required parameters to the route
self._update_landing_route(tx_sudo, access_token) # Add the required params to the route.
return tx_sudo._get_processing_values()
def _create_transaction(
self, payment_option_id, reference_prefix, amount, currency_id, partner_id, flow,
tokenization_requested, landing_route, is_validation=False,
self, provider_id, payment_method_id, token_id, reference_prefix, amount, currency_id,
partner_id, flow, tokenization_requested, landing_route, is_validation=False,
custom_create_values=None, **kwargs
):
""" Create a draft transaction based on the payment context and return it.
:param int payment_option_id: The payment option handling the transaction, as a
`payment.provider` id or a `payment.token` id
:param str reference_prefix: The custom prefix to compute the full reference
:param float|None amount: The amount to pay in the given currency.
None if in a payment method validation operation
:param int|None currency_id: The currency of the transaction, as a `res.currency` id.
None if in a payment method validation operation
:param int partner_id: The partner making the payment, as a `res.partner` id
:param str flow: The online payment flow of the transaction: 'redirect', 'direct' or 'token'
:param bool tokenization_requested: Whether the user requested that a token is created
:param str landing_route: The route the user is redirected to after the transaction
:param bool is_validation: Whether the operation is a validation
:param dict custom_create_values: Additional create values overwriting the default ones
:param int provider_id: The provider of the provider payment method or token, as a
`payment.provider` id.
:param int|None payment_method_id: The payment method, if any, as a `payment.method` id.
:param int|None token_id: The token, if any, as a `payment.token` id.
:param str reference_prefix: The custom prefix to compute the full reference.
:param float|None amount: The amount to pay, or `None` if in a validation operation.
:param int|None currency_id: The currency of the amount, as a `res.currency` id, or `None`
if in a validation operation.
:param int partner_id: The partner making the payment, as a `res.partner` id.
:param str flow: The online payment flow of the transaction: 'redirect', 'direct' or 'token'.
:param bool tokenization_requested: Whether the user requested that a token is created.
:param str landing_route: The route the user is redirected to after the transaction.
:param bool is_validation: Whether the operation is a validation.
:param dict custom_create_values: Additional create values overwriting the default ones.
:param dict kwargs: Locally unused data passed to `_is_tokenization_required` and
`_compute_reference`
:return: The sudoed transaction that was created
:rtype: recordset of `payment.transaction`
:raise: UserError if the flow is invalid
`_compute_reference`.
:return: The sudoed transaction that was created.
:rtype: payment.transaction
:raise UserError: If the flow is invalid.
"""
# Prepare create values
if flow in ['redirect', 'direct']: # Direct payment or payment with redirection
provider_sudo = request.env['payment.provider'].sudo().browse(payment_option_id)
provider_sudo = request.env['payment.provider'].sudo().browse(provider_id)
token_id = None
tokenize = bool(
# Don't tokenize if the user tried to force it through the browser's developer tools
@@ -271,7 +305,7 @@ class PaymentPortal(portal.CustomerPortal):
and (provider_sudo._is_tokenization_required(**kwargs) or tokenization_requested)
)
elif flow == 'token': # Payment by token
token_sudo = request.env['payment.token'].sudo().browse(payment_option_id)
token_sudo = request.env['payment.token'].sudo().browse(token_id)
# Prevent from paying with a token that doesn't belong to the current partner (either
# the current user's partner if logged in, or the partner on behalf of whom the payment
@@ -281,10 +315,10 @@ class PaymentPortal(portal.CustomerPortal):
raise AccessError(_("You do not have access to this payment token."))
provider_sudo = token_sudo.provider_id
token_id = payment_option_id
payment_method_id = token_sudo.payment_method_id.id
tokenize = False
else:
raise UserError(
raise ValidationError(
_("The payment should either be direct, with redirection, or made by a token.")
)
@@ -301,6 +335,7 @@ class PaymentPortal(portal.CustomerPortal):
# Create the transaction
tx_sudo = request.env['payment.transaction'].sudo().create({
'provider_id': provider_sudo.id,
'payment_method_id': payment_method_id,
'reference': reference,
'amount': amount,
'currency_id': currency_id,
File diff suppressed because it is too large Load Diff
+284 -114
View File
@@ -3,87 +3,217 @@
<record id="payment_provider_adyen" model="payment.provider">
<field name="name">Adyen</field>
<field name="display_as">Credit Card (powered by Adyen)</field>
<field name="image_128" type="base64" file="payment_adyen/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_adyen"/>
<!-- https://www.adyen.com/payment-methods -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_visa'),
ref('payment.payment_method_discover'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_jcb'),
ref('payment.payment_method_unionpay'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_ach_direct_debit'),
ref('payment.payment_method_affirm'),
ref('payment.payment_method_afterpay'),
ref('payment.payment_method_alipay'),
ref('payment.payment_method_alipay_hk'),
ref('payment.payment_method_alma'),
ref('payment.payment_method_amazon_pay'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_bacs_direct_debit'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_benefit'),
ref('payment.payment_method_bizum'),
ref('payment.payment_method_blik'),
ref('payment.payment_method_card'),
ref('payment.payment_method_cash_app_pay'),
ref('payment.payment_method_clearpay'),
ref('payment.payment_method_dana'),
ref('payment.payment_method_duitnow'),
ref('payment.payment_method_elo'),
ref('payment.payment_method_eps'),
ref('payment.payment_method_fpx'),
ref('payment.payment_method_gcash'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_google_pay'),
ref('payment.payment_method_gopay'),
ref('payment.payment_method_hipercard'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_kakaopay'),
ref('payment.payment_method_klarna'),
ref('payment.payment_method_klarna_paynow'),
ref('payment.payment_method_klarna_pay_over_time'),
ref('payment.payment_method_knet'),
ref('payment.payment_method_mbway'),
ref('payment.payment_method_mobile_pay'),
ref('payment.payment_method_momo'),
ref('payment.payment_method_multibanco'),
ref('payment.payment_method_napas_card'),
ref('payment.payment_method_online_banking_czech_republic'),
ref('payment.payment_method_online_banking_india'),
ref('payment.payment_method_online_banking_slovakia'),
ref('payment.payment_method_online_banking_thailand'),
ref('payment.payment_method_open_banking'),
ref('payment.payment_method_p24'),
ref('payment.payment_method_paybright'),
ref('payment.payment_method_paysafecard'),
ref('payment.payment_method_paynow'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_paytm'),
ref('payment.payment_method_paytrail'),
ref('payment.payment_method_pix'),
ref('payment.payment_method_promptpay'),
ref('payment.payment_method_ratepay'),
ref('payment.payment_method_samsung_pay'),
ref('payment.payment_method_sepa_direct_debit'),
ref('payment.payment_method_sofort'),
ref('payment.payment_method_swish'),
ref('payment.payment_method_touch_n_go'),
ref('payment.payment_method_trustly'),
ref('payment.payment_method_twint'),
ref('payment.payment_method_upi'),
ref('payment.payment_method_vipps'),
ref('payment.payment_method_wallets_india'),
ref('payment.payment_method_walley'),
ref('payment.payment_method_wechat_pay'),
ref('payment.payment_method_zip'),
])]"
/>
</record>
<record id="payment_provider_aps" model="payment.provider">
<field name="name">Amazon Payment Services</field>
<field name="display_as">Amazon Payment Services</field>
<field name="image_128" type="base64" file="payment_aps/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_aps"/>
<!-- https://paymentservices.amazon.com/docs/EN/24.html -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_visa'),
ref('payment.payment_method_sadad'),
ref('payment.payment_method_mada'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_mada'),
ref('payment.payment_method_knet'),
ref('payment.payment_method_meeza'),
ref('payment.payment_method_naps'),
ref('payment.payment_method_omannet'),
ref('payment.payment_method_benefit'),
])]"
/>
</record>
<record id="payment_provider_asiapay" model="payment.provider">
<field name="name">Asiapay</field>
<field name="display_as">Credit Card (powered by Asiapay)</field>
<field name="image_128" type="base64" file="payment_asiapay/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_asiapay"/>
<!-- See https://www.asiapay.com/payment.html#option -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_visa'),
ref('payment.payment_method_unionpay'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_alipay'),
ref('payment.payment_method_wechat_pay'),
ref('payment.payment_method_poli'),
ref('payment.payment_method_afterpay'),
ref('payment.payment_method_clearpay'),
ref('payment.payment_method_humm'),
ref('payment.payment_method_zip'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_atome'),
ref('payment.payment_method_pace'),
ref('payment.payment_method_shopback'),
ref('payment.payment_method_grabpay'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_google_pay'),
ref('payment.payment_method_samsung_pay'),
ref('payment.payment_method_hoolah'),
ref('payment.payment_method_boost'),
ref('payment.payment_method_duitnow'),
ref('payment.payment_method_touch_n_go'),
ref('payment.payment_method_bancnet'),
ref('payment.payment_method_gcash'),
ref('payment.payment_method_paynow'),
ref('payment.payment_method_linepay'),
ref('payment.payment_method_bangkok_bank'),
ref('payment.payment_method_krungthai_bank'),
ref('payment.payment_method_uob'),
ref('payment.payment_method_scb'),
ref('payment.payment_method_bank_of_ayudhya'),
ref('payment.payment_method_kasikorn_bank'),
ref('payment.payment_method_rabbit_line_pay'),
ref('payment.payment_method_truemoney'),
ref('payment.payment_method_fpx'),
ref('payment.payment_method_fps'),
ref('payment.payment_method_hd'),
ref('payment.payment_method_maybank'),
ref('payment.payment_method_pay_id'),
ref('payment.payment_method_promptpay'),
ref('payment.payment_method_techcom'),
ref('payment.payment_method_tienphong'),
ref('payment.payment_method_ttb'),
ref('payment.payment_method_upi'),
ref('payment.payment_method_vietcom'),
ref('payment.payment_method_tendopay'),
ref('payment.payment_method_alipay_hk'),
ref('payment.payment_method_bharatqr'),
ref('payment.payment_method_masterpass'),
ref('payment.payment_method_momo'),
ref('payment.payment_method_octopus'),
ref('payment.payment_method_maya'),
ref('payment.payment_method_uatp'),
ref('payment.payment_method_tenpay'),
ref('payment.payment_method_enets'),
ref('payment.payment_method_jkopay'),
ref('payment.payment_method_payme'),
ref('payment.payment_method_tmb'),
])]"
/>
</record>
<record id="payment_provider_authorize" model="payment.provider">
<field name="name">Authorize.net</field>
<field name="display_as">Credit Card (powered by Authorize)</field>
<field name="image_128"
type="base64"
file="payment_authorize/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_authorize"/>
<!-- https://www.authorize.net/solutions/merchantsolutions/onlinemerchantaccount/ -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_discover'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_jcb'),
ref('payment.payment_method_visa'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_ach_direct_debit'),
ref('payment.payment_method_card'),
])]"
/>
</record>
<record id="payment_provider_buckaroo" model="payment.provider">
<field name="name">Buckaroo</field>
<field name="display_as">Credit Card (powered by Buckaroo)</field>
<field name="image_128"
type="base64"
file="payment_buckaroo/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_buckaroo"/>
<!-- https://www.buckaroo-payments.com/products/payment-methods/ -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_visa'),
ref('payment.payment_method_american_express'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_bank_reference'),
ref('payment.payment_method_card'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_afterpay'),
ref('payment.payment_method_sepa_direct_debit'),
ref('payment.payment_method_alipay'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_wechat_pay'),
ref('payment.payment_method_payconiq'),
ref('payment.payment_method_klarna'),
ref('payment.payment_method_trustly'),
ref('payment.payment_method_sofort'),
ref('payment.payment_method_in3'),
ref('payment.payment_method_tinka'),
ref('payment.payment_method_billink'),
ref('payment.payment_method_kbc_cbc'),
ref('payment.payment_method_belfius'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_p24'),
ref('payment.payment_method_poste_pay'),
ref('payment.payment_method_eps'),
ref('payment.payment_method_sepa_transfer'),
ref('payment.payment_method_visa_electron'),
ref('payment.payment_method_cartes_bancaires'),
])]"
/>
</record>
<record id="payment_provider_demo" model="payment.provider">
@@ -100,20 +230,27 @@
file="payment_flutterwave/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_flutterwave"/>
<!-- https://developer.flutterwave.com/docs/collecting-payments/payment-methods/ -->
<field name="payment_method_ids" eval="[(6, 0, [
ref('payment.payment_method_visa'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_mpesa'),
ref('payment.payment_method_airtel_money'),
ref('payment.payment_method_mtn_mobile_money'),
ref('payment.payment_method_barter_by_flutterwave'),
])]"/>
<field name="payment_method_ids"
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_mpesa'),
ref('payment.payment_method_mobile_money_ghana'),
ref('payment.payment_method_mobile_money_francophone_africa'),
ref('payment.payment_method_mobile_money_uganda'),
ref('payment.payment_method_mobile_money_rwanda'),
ref('payment.payment_method_mobile_money_zambia'),
ref('payment.payment_method_bank_transfer'),
ref('payment.payment_method_bank_account'),
ref('payment.payment_method_credit'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_ussd'),
ref('payment.payment_method_nqr_by_flutterwave'),
])]"
/>
</record>
<record id="payment_provider_mercado_pago" model="payment.provider">
<field name="name">Mercado Pago</field>
<field name="display_as">Credit Card (powered by Mercado Pago)</field>
<field name="image_128"
type="base64"
file="payment_mercado_pago/static/description/icon.png"/>
@@ -123,13 +260,12 @@
https://www.mercadopago.com.ar/developers/en/reference/payment_methods/_payment_methods/
-->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_visa'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_bbva_bancomer'),
ref('payment.payment_method_citibanamex')
])]"/>
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_bank_transfer'),
ref('payment.payment_method_paypal'),
])]"
/>
</record>
<record id="payment_provider_mollie" model="payment.provider">
@@ -137,21 +273,23 @@
<field name="image_128" type="base64" file="payment_mollie/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_mollie"/>
<!-- https://www.mollie.com/en/payments -->
<field name="payment_method_ids" eval="[(6, 0, [
ref('payment.payment_method_visa'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_eps'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_p24'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_sepa'),
ref('payment.payment_method_kbc')
])]"/>
<field name="payment_method_ids"
eval="[Command.set([
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_bank_transfer'),
ref('payment.payment_method_belfius'),
ref('payment.payment_method_card'),
ref('payment.payment_method_sepa_direct_debit'),
ref('payment.payment_method_eps'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_paysafecard'),
ref('payment.payment_method_p24'),
ref('payment.payment_method_sofort'),
])]"
/>
</record>
@@ -161,33 +299,25 @@
<field name="module_id" ref="base.module_payment_paypal"/>
<!-- https://www.paypal.com/us/selfhelp/article/Which-credit-cards-can-I-accept-with-PayPal-Merchant-Services-FAQ1525#business -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_discover'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_jcb'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_unionpay'),
ref('payment.payment_method_visa'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_paypal'),
])]"
/>
</record>
<record id="payment_provider_razorpay" model="payment.provider">
<field name="name">Razorpay</field>
<field name="display_as">Credit &amp; Debit Card, UPI (Powered by Razorpay)</field>
<field name="image_128" type="base64" file="payment_razorpay/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_razorpay"/>
<!-- https://razorpay.com/docs/payments/payment-methods/#supported-payment-methods -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_rupay'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_visa')
])]"/>
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_netbanking'),
ref('payment.payment_method_upi'),
ref('payment.payment_method_wallets_india'),
])]"
/>
</record>
<record id="payment_provider_sepa_direct_debit" model="payment.provider">
@@ -197,31 +327,41 @@
type="base64"
file="base/static/img/icons/payment_sepa_direct_debit.png"/>
<field name="module_id" ref="base.module_payment_sepa_direct_debit"/>
<field name="payment_method_ids"
eval="[Command.set([
ref('payment.payment_method_sepa_direct_debit'),
])]"
/>
</record>
<record id="payment_provider_sips" model="payment.provider">
<field name="name">Sips</field>
<field name="display_as">Credit Card (powered by Sips)</field>
<field name="image_128" type="base64" file="payment_sips/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_sips"/>
<!-- See http://sips.worldline.com/en-us/home/features/payment-types-and-acquirers.html -->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_discover'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_jcb'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_unionpay'),
ref('payment.payment_method_visa'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_card'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_sofort'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_kbc_cbc'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_samsung_pay'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_lyfpay'),
ref('payment.payment_method_lydia'),
ref('payment.payment_method_floa_bank'),
ref('payment.payment_method_cetelem'),
ref('payment.payment_method_cofidis'),
ref('payment.payment_method_frafinance'),
])]"
/>
</record>
<record id="payment_provider_stripe" model="payment.provider">
<field name="name">Stripe</field>
<field name="display_as">Credit &amp; Debit Card</field>
<field name="image_128" type="base64" file="payment_stripe/static/description/icon.png"/>
<field name="module_id" ref="base.module_payment_stripe"/>
<!--
@@ -229,15 +369,45 @@
See https://support.goteamup.com/hc/en-us/articles/115002089349-Which-cards-and-payment-types-can-I-accept-with-Stripe-
-->
<field name="payment_method_ids"
eval="[(6, 0, [
ref('payment.payment_method_maestro'),
ref('payment.payment_method_mastercard'),
ref('payment.payment_method_discover'),
ref('payment.payment_method_diners_club_intl'),
ref('payment.payment_method_jcb'),
ref('payment.payment_method_american_express'),
ref('payment.payment_method_visa'),
])]"/>
eval="[Command.set([
ref('payment.payment_method_ach_direct_debit'),
ref('payment.payment_method_acss_debit'),
ref('payment.payment_method_affirm'),
ref('payment.payment_method_afterpay'),
ref('payment.payment_method_alipay'),
ref('payment.payment_method_apple_pay'),
ref('payment.payment_method_bacs_direct_debit'),
ref('payment.payment_method_bancontact'),
ref('payment.payment_method_becs_direct_debit'),
ref('payment.payment_method_blik'),
ref('payment.payment_method_card'),
ref('payment.payment_method_cash_app_pay'),
ref('payment.payment_method_clearpay'),
ref('payment.payment_method_eps'),
ref('payment.payment_method_fpx'),
ref('payment.payment_method_giropay'),
ref('payment.payment_method_google_pay'),
ref('payment.payment_method_grabpay'),
ref('payment.payment_method_ideal'),
ref('payment.payment_method_klarna'),
ref('payment.payment_method_link'),
ref('payment.payment_method_mobile_pay'),
ref('payment.payment_method_multibanco'),
ref('payment.payment_method_netbanking'),
ref('payment.payment_method_p24'),
ref('payment.payment_method_paynow'),
ref('payment.payment_method_paypal'),
ref('payment.payment_method_pix'),
ref('payment.payment_method_promptpay'),
ref('payment.payment_method_revolut_pay'),
ref('payment.payment_method_sepa_direct_debit'),
ref('payment.payment_method_sepa_transfer'),
ref('payment.payment_method_sofort'),
ref('payment.payment_method_upi'),
ref('payment.payment_method_wechat_pay'),
ref('payment.payment_method_zip'),
])]"
/>
</record>
<record id="payment_provider_transfer" model="payment.provider">
+210 -9
View File
@@ -1,24 +1,225 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import _, api, fields, models, Command
from odoo.osv import expression
class PaymentMethod(models.Model):
_name = 'payment.method'
_description = 'Payment Method'
_order = 'sequence, name'
_description = "Payment Method"
_order = 'active desc, sequence, name'
name = fields.Char(string="Name", required=True)
code = fields.Char(
string="Code", help="The technical code of this payment method.", required=True
)
sequence = fields.Integer(string="Sequence", default=1)
primary_payment_method_id = fields.Many2one(
string="Primary Payment Method",
help="The primary payment method of the current payment method, if the latter is a brand."
"\nFor example, \"Card\" is the primary payment method of the card brand \"VISA\".",
comodel_name='payment.method',
)
brand_ids = fields.One2many(
string="Brands",
help="The brands of the payment methods that will be displayed on the payment form.",
comodel_name='payment.method',
inverse_name='primary_payment_method_id',
)
is_primary = fields.Boolean(
string="Is Primary Payment Method",
compute='_compute_is_primary',
search='_search_is_primary',
)
provider_ids = fields.Many2many(
string="Providers", comodel_name='payment.provider',
help="The list of providers supporting this payment method")
string="Providers",
help="The list of providers supporting this payment method.",
comodel_name='payment.provider',
)
active = fields.Boolean(string="Active", default=True)
image = fields.Image(
string="Image",
help="The base image used for this payment method; in a 64x64 px format.",
max_width=64,
max_height=64,
required=True,
help="This field holds the image used for this payment method, limited to 64x64 px")
)
image_payment_form = fields.Image(
string="Image displayed on the payment form", related='image', store=True, max_width=45,
max_height=30)
sequence = fields.Integer('Sequence', default=1)
string="The resized image displayed on the payment form.",
related='image',
store=True,
max_width=45,
max_height=30,
)
# Feature support fields.
support_tokenization = fields.Boolean(string="Tokenization Supported")
support_express_checkout = fields.Boolean(string="Express Checkout Supported")
support_refund = fields.Selection(
string="Type of Refund Supported",
selection=[('full_only', "Full Only"), ('partial', "Partial")],
)
supported_country_ids = fields.Many2many(
string="Supported Countries", comodel_name='res.country'
)
supported_currency_ids = fields.Many2many(
string="Supported Currencies", comodel_name='res.currency'
)
#=== COMPUTE METHODS ===#
def _compute_is_primary(self):
for payment_method in self:
payment_method.is_primary = not payment_method.primary_payment_method_id
def _search_is_primary(self, operator, value):
if operator == '=' and value is True:
return [('primary_payment_method_id', '=', False)]
elif operator == '=' and value is False:
return [('primary_payment_method_id', '!=', False)]
else:
raise NotImplementedError(_("Operation not supported."))
#=== ONCHANGE METHODS ===#
@api.onchange('provider_ids')
def _onchange_provider_ids_warn_before_disabling_tokens(self):
""" Display a warning about the consequences of detaching a payment method from a provider.
Let the user know that tokens related to a provider get archived if it is detached from the
payment methods associated with those tokens.
:return: A client action with the warning message, if any.
:rtype: dict
"""
detached_providers = self._origin.provider_ids.filtered(
lambda p: p.id not in self.provider_ids.ids
) # Cannot use recordset difference operation because self.provider_ids is a set of NewIds.
if detached_providers:
related_tokens = self.env['payment.token'].with_context(active_test=True).search([
('payment_method_id', 'in', (self._origin + self._origin.brand_ids).ids),
('provider_id', 'in', detached_providers.ids),
]) # Fix `active_test` in the context forwarded by the view.
if related_tokens:
return {
'warning': {
'title': _("Warning"),
'message': _(
"This action will also archive %s tokens that are registered with this "
"payment method. Archiving tokens is irreversible.", len(related_tokens)
)
}
}
@api.onchange('provider_ids')
def _onchange_provider_ids_warn_before_attaching_payment_method(self):
""" Display a warning before attaching a payment method to a provider.
:return: A client action with the warning message, if any.
:rtype: dict
"""
attached_providers = self.provider_ids.filtered(
lambda p: p.id.origin not in self._origin.provider_ids.ids
)
if attached_providers:
return {
'warning': {
'title': _("Warning"),
'message': _(
"Please make sure that %(payment_method)s is supported by %(provider)s.",
payment_method=self.name,
provider=', '.join(attached_providers.mapped('name'))
)
}
}
#=== CRUD METHODS ===#
def write(self, values):
# Handle payment methods being detached from providers.
if 'provider_ids' in values:
detached_provider_ids = [
vals[0] for command, *vals in values['provider_ids'] if command == Command.UNLINK
]
if detached_provider_ids:
linked_tokens = self.env['payment.token'].with_context(active_test=True).search([
('provider_id', 'in', detached_provider_ids),
('payment_method_id', 'in', (self + self.brand_ids).ids),
]) # Fix `active_test` in the context forwarded by the view.
linked_tokens.active = False
return super().write(values)
# === BUSINESS METHODS === #
def _get_compatible_payment_methods(
self, provider_ids, partner_id, currency_id=None, force_tokenization=False,
is_express_checkout=False
):
""" Search and return the payment methods matching the compatibility criteria.
The compatibility criteria are that payment methods must: be supported by at least one of
the providers; support the country of the partner if it exists; be primary payment methods
(not a brand). If provided, the optional keyword arguments further refine the criteria.
:param list provider_ids: The list of providers by which the payment methods must be at
least partially supported to be considered compatible, as a list
of `payment.provider` ids.
: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 payment methods supporting tokenization can be
matched.
:param bool is_express_checkout: Whether the payment is made through express checkout.
:return: The compatible payment methods.
:rtype: payment.method
"""
# Compute the base domain for compatible payment methods.
domain = [('provider_ids', 'in', provider_ids), ('is_primary', '=', True)]
# Handle the partner country; allow all countries if the list is empty.
partner = self.env['res.partner'].browse(partner_id)
if partner.country_id: # The partner country must either not be set or be supported.
domain = expression.AND([
domain, [
'|',
('supported_country_ids', '=', False),
('supported_country_ids', 'in', [partner.country_id.id]),
]
])
# Handle the supported currencies; allow all currencies if the list is empty.
if currency_id:
domain = expression.AND([
domain, [
'|',
('supported_currency_ids', '=', False),
('supported_currency_ids', 'in', [currency_id]),
]
])
# Handle tokenization support requirements.
if force_tokenization:
domain = expression.AND([domain, [('support_tokenization', '=', True)]])
# Handle express checkout.
if is_express_checkout:
domain = expression.AND([domain, [('support_express_checkout', '=', True)]])
# Search the payment methods matching the compatibility criteria.
compatible_payment_methods = self.env['payment.method'].search(domain)
return compatible_payment_methods
def _get_from_code(self, code, mapping=None):
""" Get the payment method corresponding to the given provider-specific code.
If a mapping is given, the search uses the generic payment method code that corresponds to
the given provider-specific code.
:param str code: The provider-specific code of the payment method to get.
:param dict mapping: A non-exhaustive mapping of generic payment method codes to
provider-specific codes.
:return: The corresponding payment method, if any.
:type: payment.method
"""
generic_to_specific_mapping = mapping or {}
specific_to_generic_mapping = {v: k for k, v in generic_to_specific_mapping.items()}
return self.search([('code', '=', specific_to_generic_mapping.get(code, code))], limit=1)
+24 -16
View File
@@ -49,7 +49,8 @@ class PaymentProvider(models.Model):
help="The main currency of the company, used to display monetary fields.",
)
payment_method_ids = fields.Many2many(
string="Supported Payment Methods", comodel_name='payment.method')
string="Supported Payment Methods", comodel_name='payment.method'
)
allow_tokenization = fields.Boolean(
string="Allow Saving Payment Methods",
help="This controls whether customers can save their payment methods as payment tokens.\n"
@@ -124,9 +125,6 @@ class PaymentProvider(models.Model):
)
# Message fields
display_as = fields.Char(
string="Displayed as", help="Description of the provider for customers",
translate=True)
pre_msg = fields.Html(
string="Help Message", help="The message displayed to explain and help the payment process",
translate=True)
@@ -183,7 +181,6 @@ class PaymentProvider(models.Model):
show_credentials_page = fields.Boolean(compute='_compute_view_configuration_fields')
show_allow_tokenization = fields.Boolean(compute='_compute_view_configuration_fields')
show_allow_express_checkout = fields.Boolean(compute='_compute_view_configuration_fields')
show_payment_method_ids = fields.Boolean(compute='_compute_view_configuration_fields')
show_pre_msg = fields.Boolean(compute='_compute_view_configuration_fields')
show_pending_msg = fields.Boolean(compute='_compute_view_configuration_fields')
show_auth_msg = fields.Boolean(compute='_compute_view_configuration_fields')
@@ -236,7 +233,6 @@ class PaymentProvider(models.Model):
- `show_credentials_page`: Whether the "Credentials" notebook page should be shown.
- `show_allow_tokenization`: Whether the `allow_tokenization` field should be shown.
- `show_allow_express_checkout`: Whether the `allow_express_checkout` field should be shown.
- `show_payment_method_ids`: Whether the `payment_method_ids` field should be shown.
- `show_pre_msg`: Whether the `pre_msg` field should be shown.
- `show_pending_msg`: Whether the `pending_msg` field should be shown.
- `show_auth_msg`: Whether the `auth_msg` field should be shown.
@@ -254,7 +250,6 @@ class PaymentProvider(models.Model):
'show_credentials_page': True,
'show_allow_tokenization': True,
'show_allow_express_checkout': True,
'show_payment_method_ids': True,
'show_pre_msg': True,
'show_pending_msg': True,
'show_auth_msg': True,
@@ -421,6 +416,17 @@ class PaymentProvider(models.Model):
else:
raise UserError(_("You cannot publish a disabled provider."))
def action_view_payment_methods(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _("Payment Methods"),
'res_model': 'payment.method',
'view_mode': 'tree',
'domain': [('id', 'in', self.with_context(active_test=False).payment_method_ids.ids)],
'context': {'active_test': False},
}
#=== BUSINESS METHODS ===#
@api.model
@@ -428,11 +434,12 @@ class PaymentProvider(models.Model):
self, company_id, partner_id, amount, currency_id=None, force_tokenization=False,
is_express_checkout=False, is_validation=False, **kwargs
):
""" Select and return the providers matching the criteria.
""" Search and return the providers matching the compatibility criteria.
The criteria are that providers must not be disabled, be in the company that is provided,
support the country of the partner if it exists, and be compatible with the currency if
provided. The criteria can be further refined by providing the keyword arguments.
The compatibility criteria are that providers must: not be disabled; be in the company that
is provided; support the country of the partner if it exists; be compatible with the
currency if provided. If provided, the optional keyword arguments further refine the
criteria.
:param int company_id: The company to which providers must belong, as a `res.company` id.
:param int partner_id: The partner making the payment, as a `res.partner` id.
@@ -443,7 +450,7 @@ class PaymentProvider(models.Model):
:param bool is_validation: Whether the operation is a validation.
:param dict kwargs: Optional data. This parameter is not used here.
:return: The compatible providers.
:rtype: recordset of `payment.provider`
:rtype: payment.provider
"""
# Compute the base domain for compatible providers.
domain = [
@@ -455,7 +462,7 @@ class PaymentProvider(models.Model):
if not self.env.user._is_internal():
domain = expression.AND([domain, [('is_published', '=', True)]])
# Handle partner country.
# Handle the partner country; allow all countries if the list is empty.
partner = self.env['res.partner'].browse(partner_id)
if partner.country_id: # The partner country must either not be set or be supported.
domain = expression.AND([
@@ -481,7 +488,7 @@ class PaymentProvider(models.Model):
]
])
# Handle the available currencies (only if supported currencies list is not empty).
# Handle the available currencies; allow all currencies if the list is empty.
if currency:
domain = expression.AND([
domain, [
@@ -499,6 +506,7 @@ class PaymentProvider(models.Model):
if is_express_checkout:
domain = expression.AND([domain, [('allow_express_checkout', '=', True)]])
# Search the providers matching the compatibility criteria.
compatible_providers = self.env['payment.provider'].search(domain)
return compatible_providers
@@ -520,10 +528,10 @@ class PaymentProvider(models.Model):
def _is_tokenization_required(self, **kwargs):
""" Return whether tokenizing the transaction is required given its context.
For a module to make the tokenization required based on the transaction context, it must
For a module to make the tokenization required based on the payment context, it must
override this method and return whether it is required.
:param dict kwargs: The transaction context. This parameter is not used here.
:param dict kwargs: The payment context. This parameter is not used here.
:return: Whether tokenizing the transaction is required.
:rtype: bool
"""
+16 -7
View File
@@ -13,19 +13,28 @@ class PaymentToken(models.Model):
_check_company_auto = True
provider_id = fields.Many2one(string="Provider", comodel_name='payment.provider', required=True)
provider_code = fields.Selection(related='provider_id.code')
provider_code = fields.Selection(string="Provider Code", related='provider_id.code')
company_id = fields.Many2one(
related='provider_id.company_id', store=True, index=True
) # Indexed to speed-up ORM searches (from ir_rule or others).
payment_method_id = fields.Many2one(
string="Payment Method", comodel_name='payment.method', readonly=True, required=True
)
payment_method_code = fields.Char(
string="Payment Method Code", related='payment_method_id.code'
)
payment_details = fields.Char(
string="Payment Details", help="The clear part of the payment method's payment details.",
)
partner_id = fields.Many2one(string="Partner", comodel_name='res.partner', required=True)
company_id = fields.Many2one( # Indexed to speed-up ORM searches (from ir_rule or others)
related='provider_id.company_id', store=True, index=True)
provider_ref = fields.Char(
string="Provider Reference", help="The provider reference of the token of the transaction",
required=True) # This is not the same thing as the provider reference of the transaction.
string="Provider Reference",
help="The provider reference of the token of the transaction.",
required=True,
) # This is not the same thing as the provider reference of the transaction.
transaction_ids = fields.One2many(
string="Payment Transactions", comodel_name='payment.transaction', inverse_name='token_id')
verified = fields.Boolean(string="Verified")
string="Payment Transactions", comodel_name='payment.transaction', inverse_name='token_id'
)
active = fields.Boolean(string="Active", default=True)
#=== COMPUTE METHODS ===#
+12 -3
View File
@@ -31,10 +31,18 @@ class PaymentTransaction(models.Model):
return self.env['res.lang'].get_installed()
provider_id = fields.Many2one(
string="Provider", comodel_name='payment.provider', readonly=True, required=True)
provider_code = fields.Selection(related='provider_id.code')
string="Provider", comodel_name='payment.provider', readonly=True, required=True
)
provider_code = fields.Selection(string="Provider Code", related='provider_id.code')
company_id = fields.Many2one( # Indexed to speed-up ORM searches (from ir_rule or others)
related='provider_id.company_id', store=True, index=True)
related='provider_id.company_id', store=True, index=True
)
payment_method_id = fields.Many2one(
string="Payment Method", comodel_name='payment.method', readonly=True, required=True
)
payment_method_code = fields.Char(
string="Payment Method Code", related='payment_method_id.code'
)
reference = fields.Char(
string="Reference", help="The internal reference of the transaction", readonly=True,
required=True) # Already has an index from the UNIQUE SQL constraint.
@@ -635,6 +643,7 @@ class PaymentTransaction(models.Model):
return self.create({
'provider_id': self.provider_id.id,
'payment_method_id': self.payment_method_id.id,
'reference': self._compute_reference(self.provider_code, prefix=reference_prefix),
'amount': amount,
'currency_id': self.currency_id.id,
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Some files were not shown because too many files have changed in this diff Show More