[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 <anko@odoo.com>
This commit is contained in:
Anita (anko)
2023-11-06 18:11:32 +00:00
parent f7a4da5602
commit 06523ff675
31 changed files with 316 additions and 17 deletions
+11
View File
@@ -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',
@@ -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
+10
View File
@@ -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',
]
@@ -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
+11
View File
@@ -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',
]
@@ -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
+11
View File
@@ -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',
@@ -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
+12
View File
@@ -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',
@@ -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
+12
View File
@@ -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',
@@ -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
+12
View File
@@ -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',
}
@@ -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
+23
View File
@@ -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',
@@ -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
+12
View File
@@ -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',
@@ -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
+10
View File
@@ -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 = {
@@ -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
+6
View File
@@ -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 = {
@@ -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
+11
View File
@@ -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',
@@ -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
+12
View File
@@ -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',
]
@@ -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
+13
View File
@@ -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 = {
@@ -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
+11
View File
@@ -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',
]
+11 -2
View File
@@ -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
+3 -1
View File
@@ -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',