From 06523ff6758591602002ba079ebb26b6eb94644b Mon Sep 17 00:00:00 2001 From: "Anita (anko)" Date: Mon, 6 Nov 2023 17:01:29 +0100 Subject: [PATCH] [IMP] payment(_*): activate default payment methods When user enables or tests payment provider it will automatically enable most used payment method in that provider. closes odoo/odoo#140907 Signed-off-by: anko-odoo --- addons/payment_adyen/const.py | 11 +++++++++ .../payment_adyen/models/payment_provider.py | 7 ++++++ addons/payment_alipay/const.py | 10 ++++++++ .../payment_alipay/models/payment_provider.py | 9 ++++++++ addons/payment_aps/const.py | 11 +++++++++ addons/payment_aps/models/payment_provider.py | 9 ++++++++ addons/payment_asiapay/const.py | 11 +++++++++ .../models/payment_provider.py | 7 ++++++ addons/payment_authorize/const.py | 12 ++++++++++ .../models/payment_provider.py | 8 +++++++ addons/payment_buckaroo/const.py | 12 ++++++++++ .../models/payment_provider.py | 13 +++++++++-- addons/payment_flutterwave/const.py | 12 ++++++++++ .../models/payment_provider.py | 11 +++++++-- addons/payment_mercado_pago/const.py | 23 +++++++++++++++++++ .../models/payment_provider.py | 11 +++++++-- addons/payment_mollie/const.py | 12 ++++++++++ .../payment_mollie/models/payment_provider.py | 11 +++++++-- addons/payment_ogone/const.py | 10 ++++++++ .../payment_ogone/models/payment_provider.py | 7 ++++++ addons/payment_paypal/const.py | 6 +++++ .../payment_paypal/models/payment_provider.py | 11 +++++++-- addons/payment_payulatam/const.py | 11 +++++++++ .../models/payment_provider.py | 13 +++++++++-- addons/payment_payumoney/const.py | 12 ++++++++++ .../models/payment_provider.py | 11 +++++++++ addons/payment_razorpay/const.py | 13 +++++++++++ .../models/payment_provider.py | 11 +++++++-- addons/payment_sips/const.py | 11 +++++++++ .../payment_sips/models/payment_provider.py | 13 +++++++++-- addons/payment_stripe/const.py | 4 +++- 31 files changed, 316 insertions(+), 17 deletions(-) create mode 100644 addons/payment_alipay/const.py create mode 100644 addons/payment_payumoney/const.py diff --git a/addons/payment_adyen/const.py b/addons/payment_adyen/const.py index 20335485ccc..1ee8287ba23 100644 --- a/addons/payment_adyen/const.py +++ b/addons/payment_adyen/const.py @@ -23,6 +23,17 @@ CURRENCY_DECIMALS = { 'ISK': 2, } +# The codes of the payment methods to activate when Adyen is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to Adyen codes. PAYMENT_METHODS_MAPPING = { 'ach_direct_debit': 'ach', diff --git a/addons/payment_adyen/models/payment_provider.py b/addons/payment_adyen/models/payment_provider.py index 53665ab9280..9f4f1da25f7 100644 --- a/addons/payment_adyen/models/payment_provider.py +++ b/addons/payment_adyen/models/payment_provider.py @@ -183,3 +183,10 @@ class PaymentProvider(models.Model): 'value': converted_amount, 'currency': currency_code, } + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'adyen': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_alipay/const.py b/addons/payment_alipay/const.py new file mode 100644 index 00000000000..e1b8286eced --- /dev/null +++ b/addons/payment_alipay/const.py @@ -0,0 +1,10 @@ +# The codes of the payment methods to activate when Alipay is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] diff --git a/addons/payment_alipay/models/payment_provider.py b/addons/payment_alipay/models/payment_provider.py index 0ff5cb2b539..31dbf87c128 100644 --- a/addons/payment_alipay/models/payment_provider.py +++ b/addons/payment_alipay/models/payment_provider.py @@ -5,6 +5,8 @@ from hashlib import md5 from odoo import api, fields, models +from odoo.addons.payment_alipay import const + _logger = logging.getLogger(__name__) @@ -60,3 +62,10 @@ class PaymentProvider(models.Model): return 'https://mapi.alipay.com/gateway.do' else: # test environment return 'https://openapi.alipaydev.com/gateway.do' + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'alipay': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_aps/const.py b/addons/payment_aps/const.py index f6fb3b3be96..164801b2407 100644 --- a/addons/payment_aps/const.py +++ b/addons/payment_aps/const.py @@ -6,3 +6,14 @@ PAYMENT_STATUS_MAPPING = { 'pending': ('19',), 'done': ('14',), } + +# The codes of the payment methods to activate when APS is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] diff --git a/addons/payment_aps/models/payment_provider.py b/addons/payment_aps/models/payment_provider.py index 3b4726c3d0d..1e28355613e 100644 --- a/addons/payment_aps/models/payment_provider.py +++ b/addons/payment_aps/models/payment_provider.py @@ -5,6 +5,8 @@ import logging from odoo import fields, models +from odoo.addons.payment_aps import const + _logger = logging.getLogger(__name__) @@ -58,3 +60,10 @@ class PaymentProvider(models.Model): key = self.aps_sha_response if incoming else self.aps_sha_request signing_string = ''.join([key, sign_data, key]) return hashlib.sha256(signing_string.encode()).hexdigest() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'aps': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_asiapay/const.py b/addons/payment_asiapay/const.py index 7275c17fcbc..2cbe9fbcc1b 100644 --- a/addons/payment_asiapay/const.py +++ b/addons/payment_asiapay/const.py @@ -57,6 +57,17 @@ LANGUAGE_CODES_MAPPING = { 'vi_VN': 'S', } +# The codes of the payment methods to activate when Asiapay is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to AsiaPay codes. PAYMENT_METHODS_MAPPING = { 'alipay_hk': 'ALIPAYHKONL', diff --git a/addons/payment_asiapay/models/payment_provider.py b/addons/payment_asiapay/models/payment_provider.py index 518408916e2..50f8c1f5dbe 100644 --- a/addons/payment_asiapay/models/payment_provider.py +++ b/addons/payment_asiapay/models/payment_provider.py @@ -88,3 +88,10 @@ class PaymentProvider(models.Model): shasign = hashnew(self.asiapay_secure_hash_function) shasign.update(signing_string.encode()) return shasign.hexdigest() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'asiapay': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_authorize/const.py b/addons/payment_authorize/const.py index 3f6edbe69b0..db75138c87d 100644 --- a/addons/payment_authorize/const.py +++ b/addons/payment_authorize/const.py @@ -1,5 +1,17 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +# The codes of the payment methods to activate when Authorize is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'ach_direct_debit', + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to Authorize codes. PAYMENT_METHODS_MAPPING = { 'amex': 'americanexpress', diff --git a/addons/payment_authorize/models/payment_provider.py b/addons/payment_authorize/models/payment_provider.py index 8d824701f44..63ffc1c4b94 100644 --- a/addons/payment_authorize/models/payment_provider.py +++ b/addons/payment_authorize/models/payment_provider.py @@ -8,6 +8,7 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError from odoo.fields import Command +from odoo.addons.payment_authorize import const from odoo.addons.payment_authorize.models.authorize_request import AuthorizeAPI _logger = logging.getLogger(__name__) @@ -121,3 +122,10 @@ class PaymentProvider(models.Model): 'client_key': self.authorize_client_key, } return json.dumps(inline_form_values) + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'authorize': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_buckaroo/const.py b/addons/payment_buckaroo/const.py index 6ae92f18bea..7957bd0ac62 100644 --- a/addons/payment_buckaroo/const.py +++ b/addons/payment_buckaroo/const.py @@ -1,5 +1,17 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +# The codes of the payment methods to activate when Buckaroo is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + 'ideal', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to Buckaroo codes. PAYMENT_METHODS_MAPPING = { 'alipay': 'Alipay', diff --git a/addons/payment_buckaroo/models/payment_provider.py b/addons/payment_buckaroo/models/payment_provider.py index 05744e1b1ad..611ca6da32c 100644 --- a/addons/payment_buckaroo/models/payment_provider.py +++ b/addons/payment_buckaroo/models/payment_provider.py @@ -6,7 +6,7 @@ from werkzeug import urls from odoo import fields, models -from odoo.addons.payment_buckaroo.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_buckaroo import const class PaymentProvider(models.Model): @@ -25,7 +25,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'buckaroo': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -74,3 +74,12 @@ class PaymentProvider(models.Model): sign_string += self.buckaroo_secret_key # Calculate the SHA-1 hash over the signing string return sha1(sign_string.encode('utf-8')).hexdigest() + + # === BUSINESS METHODS ===# + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'buckaroo': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_flutterwave/const.py b/addons/payment_flutterwave/const.py index 5ed91f3b6c5..fb1bb02e8b9 100644 --- a/addons/payment_flutterwave/const.py +++ b/addons/payment_flutterwave/const.py @@ -37,6 +37,18 @@ PAYMENT_STATUS_MAPPING = { 'error': ['failed'], } +# The codes of the payment methods to activate when Flutterwave is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + 'mpesa', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + PAYMENT_METHODS_MAPPING = { 'bank_transfer': 'banktransfer', } diff --git a/addons/payment_flutterwave/models/payment_provider.py b/addons/payment_flutterwave/models/payment_provider.py index 5735dbdc8b0..705a78e8269 100644 --- a/addons/payment_flutterwave/models/payment_provider.py +++ b/addons/payment_flutterwave/models/payment_provider.py @@ -9,7 +9,7 @@ from werkzeug.urls import url_join from odoo import _, api, fields, models from odoo.exceptions import ValidationError -from odoo.addons.payment_flutterwave.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_flutterwave import const _logger = logging.getLogger(__name__) @@ -63,7 +63,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'flutterwave': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -104,3 +104,10 @@ class PaymentProvider(models.Model): "Flutterwave: " + _("Could not establish the connection to the API.") ) return response.json() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'flutterwave': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_mercado_pago/const.py b/addons/payment_mercado_pago/const.py index a6970267e2a..b67e36befcf 100644 --- a/addons/payment_mercado_pago/const.py +++ b/addons/payment_mercado_pago/const.py @@ -27,6 +27,29 @@ SUPPORTED_CURRENCIES = [ 'VES', # Sovereign Bolivar ] +# The codes of the payment methods to activate when Mercado Pago is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'argencard', + 'ceconsud', + 'cordobesa', + 'codensa', + 'lider', + 'magna', + 'naranja', + 'nativa', + 'oca', + 'presto', + 'tarjeta_mercadopago', + 'shopping', + 'elo', + 'hipercard', +] + # Mapping of payment method codes to Mercado Pago codes. PAYMENT_METHODS_MAPPING = { 'card': 'debit_card,credit_card,prepaid_card', diff --git a/addons/payment_mercado_pago/models/payment_provider.py b/addons/payment_mercado_pago/models/payment_provider.py index a63267ed42b..d3697e3fb57 100644 --- a/addons/payment_mercado_pago/models/payment_provider.py +++ b/addons/payment_mercado_pago/models/payment_provider.py @@ -9,7 +9,7 @@ from werkzeug import urls from odoo import _, fields, models from odoo.exceptions import ValidationError -from odoo.addons.payment_mercado_pago.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_mercado_pago import const _logger = logging.getLogger(__name__) @@ -34,7 +34,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'mercado_pago': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -78,3 +78,10 @@ class PaymentProvider(models.Model): "Mercado Pago: " + _("Could not establish the connection to the API.") ) return response.json() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'mercado_pago': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_mollie/const.py b/addons/payment_mollie/const.py index e17cbe1d852..a6dd9c506be 100644 --- a/addons/payment_mollie/const.py +++ b/addons/payment_mollie/const.py @@ -47,6 +47,18 @@ SUPPORTED_CURRENCIES = [ 'ZAR' ] +# The codes of the payment methods to activate when Mollie is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + 'ideal', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to Mollie codes. PAYMENT_METHODS_MAPPING = { 'apple_pay': 'applepay', diff --git a/addons/payment_mollie/models/payment_provider.py b/addons/payment_mollie/models/payment_provider.py index e93ea3e984a..5a8e4a97322 100755 --- a/addons/payment_mollie/models/payment_provider.py +++ b/addons/payment_mollie/models/payment_provider.py @@ -9,7 +9,7 @@ from werkzeug import urls from odoo import _, fields, models, service from odoo.exceptions import ValidationError -from odoo.addons.payment_mollie.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_mollie import const _logger = logging.getLogger(__name__) @@ -33,7 +33,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'mollie': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -82,3 +82,10 @@ class PaymentProvider(models.Model): "Mollie: " + _("Could not establish the connection to the API.") ) return response.json() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'mollie': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_ogone/const.py b/addons/payment_ogone/const.py index 82e4e942ee3..989f297f3f4 100644 --- a/addons/payment_ogone/const.py +++ b/addons/payment_ogone/const.py @@ -77,6 +77,16 @@ PAYMENT_STATUS_MAPPING = { 'declined': (2,), } +# The codes of the payment methods to activate when Ogone is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] # Mapping of payment method codes to Ogone codes. PAYMENT_METHODS_MAPPING = { diff --git a/addons/payment_ogone/models/payment_provider.py b/addons/payment_ogone/models/payment_provider.py index 5825cb1ea6c..71c2017415b 100644 --- a/addons/payment_ogone/models/payment_provider.py +++ b/addons/payment_ogone/models/payment_provider.py @@ -132,3 +132,10 @@ class PaymentProvider(models.Model): _logger.exception("invalid API request at %s with data %s", url, payload) raise ValidationError("Ogone: " + _("The communication with the API failed.")) return response.content + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'ogone': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_paypal/const.py b/addons/payment_paypal/const.py index 1f02c1d0791..d5fb8387313 100644 --- a/addons/payment_paypal/const.py +++ b/addons/payment_paypal/const.py @@ -31,6 +31,12 @@ SUPPORTED_CURRENCIES = ( 'USD', ) +# The codes of the payment methods to activate when Paypal is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'paypal', +] + # Mapping of transaction states to PayPal payment statuses # See https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNandPDTVariables/ PAYMENT_STATUS_MAPPING = { diff --git a/addons/payment_paypal/models/payment_provider.py b/addons/payment_paypal/models/payment_provider.py index c325412478a..ee883b6747f 100644 --- a/addons/payment_paypal/models/payment_provider.py +++ b/addons/payment_paypal/models/payment_provider.py @@ -4,7 +4,7 @@ import logging from odoo import _, fields, models -from odoo.addons.payment_paypal.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_paypal import const _logger = logging.getLogger(__name__) @@ -31,7 +31,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'paypal': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -49,3 +49,10 @@ class PaymentProvider(models.Model): return 'https://www.paypal.com/cgi-bin/webscr' else: return 'https://www.sandbox.paypal.com/cgi-bin/webscr' + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'paypal': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_payulatam/const.py b/addons/payment_payulatam/const.py index 7987c02053e..91c4c373d31 100644 --- a/addons/payment_payulatam/const.py +++ b/addons/payment_payulatam/const.py @@ -13,6 +13,17 @@ SUPPORTED_CURRENCIES = [ 'USD' ] +# The codes of the payment methods to activate when PayULatam is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of payment method codes to PayU Latam codes. PAYMENT_METHODS_MAPPING = { 'bank_reference': 'BANK_REFERENCED', diff --git a/addons/payment_payulatam/models/payment_provider.py b/addons/payment_payulatam/models/payment_provider.py index f5efa00f8d2..de9b1d246e3 100644 --- a/addons/payment_payulatam/models/payment_provider.py +++ b/addons/payment_payulatam/models/payment_provider.py @@ -5,7 +5,7 @@ from hashlib import md5 from odoo import fields, models from odoo.tools.float_utils import float_repr, float_split -from odoo.addons.payment_payulatam.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_payulatam import const class PaymentProvider(models.Model): _inherit = 'payment.provider' @@ -29,7 +29,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'payulatam': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -77,3 +77,12 @@ class PaymentProvider(models.Model): values['paymentMethods'], ]) return md5(data_string.encode('utf-8')).hexdigest() + + #=== BUSINESS METHODS ===# + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'payulatam': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_payumoney/const.py b/addons/payment_payumoney/const.py new file mode 100644 index 00000000000..c0e146cb4e0 --- /dev/null +++ b/addons/payment_payumoney/const.py @@ -0,0 +1,12 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +# The codes of the payment methods to activate when PayU Money is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] diff --git a/addons/payment_payumoney/models/payment_provider.py b/addons/payment_payumoney/models/payment_provider.py index 7e1ea50e761..9ad4898ef4d 100644 --- a/addons/payment_payumoney/models/payment_provider.py +++ b/addons/payment_payumoney/models/payment_provider.py @@ -4,6 +4,8 @@ import hashlib from odoo import fields, models +from odoo.addons.payment_payulatam.const import DEFAULT_PAYMENT_METHODS_CODES + class PaymentProvider(models.Model): _inherit = 'payment.provider' @@ -45,3 +47,12 @@ class PaymentProvider(models.Model): keys = 'key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt' sign = '|'.join(f'{sign_values.get(k) or ""}' for k in keys.split('|')) return hashlib.sha512(sign.encode('utf-8')).hexdigest() + + #=== BUSINESS METHODS ===# + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'payumoney': + return default_codes + return DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_razorpay/const.py b/addons/payment_razorpay/const.py index 5a43c4a4645..da56e66d92e 100644 --- a/addons/payment_razorpay/const.py +++ b/addons/payment_razorpay/const.py @@ -98,6 +98,19 @@ SUPPORTED_CURRENCIES = [ 'ZAR', ] +# The codes of the payment methods to activate when Razorpay is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + 'netbanking', + 'upi', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] + # Mapping of transaction states to Razorpay's payment statuses. # See https://razorpay.com/docs/payments/payments#payment-life-cycle. PAYMENT_STATUS_MAPPING = { diff --git a/addons/payment_razorpay/models/payment_provider.py b/addons/payment_razorpay/models/payment_provider.py index b804c0f0122..2283ebb4fa5 100644 --- a/addons/payment_razorpay/models/payment_provider.py +++ b/addons/payment_razorpay/models/payment_provider.py @@ -11,7 +11,7 @@ from werkzeug.urls import url_join from odoo import _, fields, models from odoo.exceptions import ValidationError -from odoo.addons.payment_razorpay.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_razorpay import const _logger = logging.getLogger(__name__) @@ -56,7 +56,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'razorpay': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES + lambda c: c.name in const.SUPPORTED_CURRENCIES ) return supported_currencies @@ -119,3 +119,10 @@ class PaymentProvider(models.Model): else: # Notification data. secret = self.razorpay_webhook_secret return hmac.new(secret.encode(), msg=data, digestmod=hashlib.sha256).hexdigest() + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'razorpay': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_sips/const.py b/addons/payment_sips/const.py index 7dccc23e2bb..05c5ba030e2 100644 --- a/addons/payment_sips/const.py +++ b/addons/payment_sips/const.py @@ -64,3 +64,14 @@ RESPONSE_CODES_MAPPING = { '94', '97', '99' ), } + +# The codes of the payment methods to activate when Sips is activated. +DEFAULT_PAYMENT_METHODS_CODES = [ + # Primary payment methods. + 'card', + # Brand payment methods. + 'visa', + 'mastercard', + 'amex', + 'discover', +] diff --git a/addons/payment_sips/models/payment_provider.py b/addons/payment_sips/models/payment_provider.py index a68437c7bf0..baa86fcbea3 100644 --- a/addons/payment_sips/models/payment_provider.py +++ b/addons/payment_sips/models/payment_provider.py @@ -5,7 +5,7 @@ from hashlib import sha256 from odoo import fields, models -from odoo.addons.payment_sips.const import SUPPORTED_CURRENCIES +from odoo.addons.payment_sips import const class PaymentProvider(models.Model): @@ -34,7 +34,7 @@ class PaymentProvider(models.Model): supported_currencies = super()._get_supported_currencies() if self.code == 'sips': supported_currencies = supported_currencies.filtered( - lambda c: c.name in SUPPORTED_CURRENCIES.keys() + lambda c: c.name in const.SUPPORTED_CURRENCIES.keys() ) return supported_currencies @@ -52,3 +52,12 @@ class PaymentProvider(models.Model): key = self.sips_secret shasign = sha256((data + key).encode('utf-8')) return shasign.hexdigest() + + # === BUSINESS METHODS ===# + + def _get_default_payment_method_codes(self): + """ Override of `payment` to return the default payment method codes. """ + default_codes = super()._get_default_payment_method_codes() + if self.code != 'sips': + return default_codes + return const.DEFAULT_PAYMENT_METHODS_CODES diff --git a/addons/payment_stripe/const.py b/addons/payment_stripe/const.py index c593e2090ce..2b10477e23f 100644 --- a/addons/payment_stripe/const.py +++ b/addons/payment_stripe/const.py @@ -9,9 +9,11 @@ PROXY_URL = 'https://stripe.api.odoo.com/api/stripe/' DEFAULT_PAYMENT_METHODS_CODES = [ # Primary payment methods. 'card', - 'paypal', 'bancontact', + 'eps', + 'giropay', 'ideal', + 'p24', # Brand payment methods. 'visa', 'mastercard',