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>
70 lines
3.2 KiB
Python
70 lines
3.2 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.tests import tagged
|
|
from odoo.tools import mute_logger
|
|
|
|
from odoo.addons.payment import utils as payment_utils
|
|
from odoo.addons.payment_aps.controllers.main import APSController
|
|
from odoo.addons.payment_aps.tests.common import APSCommon
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestPaymentTransaction(APSCommon):
|
|
|
|
def test_reference_contains_only_valid_characters(self):
|
|
""" Test that transaction references are made of only alphanumerics and/or '-' and '_'. """
|
|
for prefix in (None, '', 'S0001', 'INV/20222/001', 'dummy ref'):
|
|
reference = self.env['payment.transaction']._compute_reference('aps', prefix=prefix)
|
|
self.assertRegex(reference, r'^[\w-]+$')
|
|
|
|
def test_no_item_missing_from_rendering_values(self):
|
|
""" Test that the rendered values are conform to the transaction fields. """
|
|
tx = self._create_transaction(flow='redirect')
|
|
|
|
converted_amount = payment_utils.to_minor_currency_units(self.amount, self.currency)
|
|
expected_values = {
|
|
'command': 'PURCHASE',
|
|
'access_code': self.provider.aps_access_code,
|
|
'merchant_identifier': self.provider.aps_merchant_identifier,
|
|
'merchant_reference': tx.reference,
|
|
'payment_option': 'UNKNOWN',
|
|
'amount': str(converted_amount),
|
|
'currency': self.currency.name,
|
|
'language': tx.partner_lang[:2],
|
|
'customer_email': tx.partner_id.email_normalized,
|
|
'return_url': self._build_url(APSController._return_url),
|
|
'signature': 'c9b9f35a607606c045f8882e762a4a4a35572cf230fe1cd45fa18d7c8681aeb9',
|
|
'api_url': self.provider._aps_get_api_url(),
|
|
}
|
|
self.assertDictEqual(tx._get_specific_rendering_values(None), expected_values)
|
|
|
|
@mute_logger('odoo.addons.payment.models.payment_transaction')
|
|
def test_no_input_missing_from_redirect_form(self):
|
|
""" Test that the no key is not omitted from the rendering values. """
|
|
tx = self._create_transaction(flow='redirect')
|
|
expected_input_keys = [
|
|
'command',
|
|
'access_code',
|
|
'merchant_identifier',
|
|
'merchant_reference',
|
|
'amount',
|
|
'currency',
|
|
'language',
|
|
'customer_email',
|
|
'signature',
|
|
'payment_option',
|
|
'return_url',
|
|
]
|
|
processing_values = tx._get_processing_values()
|
|
form_info = self._extract_values_from_html_form(processing_values['redirect_form_html'])
|
|
self.assertEqual(form_info['action'], 'https://sbcheckout.payfort.com/FortAPI/paymentPage')
|
|
self.assertEqual(form_info['method'], 'post')
|
|
self.assertListEqual(list(form_info['inputs'].keys()), expected_input_keys)
|
|
|
|
def test_processing_notification_data_confirms_transaction(self):
|
|
""" Test that the transaction state is set to 'done' when the notification data indicate a
|
|
successful payment. """
|
|
tx = self._create_transaction(flow='redirect')
|
|
tx._process_notification_data(self.notification_data)
|
|
self.assertEqual(tx.state, 'done')
|