Files
odoo_source/addons/payment_sips/models/payment_provider.py
T
Valentin Vallaeys (vava) 90af85c2e4 [IMP] payment(_*): show available currencies for payment providers
Before this commit, the lists of supported currencies by payment
provider were hard-coded in the Python scripts, which made them
unavailable to the users.

With this commit, the implemented initial lists of supported currencies
are displayed on the form view and are editable, because Odoo lists may
not be up-to-date. Empty lists do not trigger any filtering on the
payment providers to access payment methods.

For Authorize.net and Asiapay payment providers, the specific
`(authorize,asiapay)_currency_id` are removed and the generic payment
provider field `available_currency_ids` is restricted to a single-item
list when one of those providers is enabled.

task-2926016

closes odoo/odoo#101018

Related: odoo/enterprise#34158
Related: odoo/documentation#2788
Related: odoo/upgrade#4069
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
2023-01-05 16:51:56 +01:00

55 lines
2.1 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Original Copyright 2015 Eezee-It, modified and maintained by Odoo.
from hashlib import sha256
from odoo import fields, models
from odoo.addons.payment_sips.const import SUPPORTED_CURRENCIES
class PaymentProvider(models.Model):
_inherit = 'payment.provider'
code = fields.Selection(
selection_add=[('sips', "Sips")], ondelete={'sips': 'set default'})
sips_merchant_id = fields.Char(
string="Merchant ID", help="The ID solely used to identify the merchant account with Sips",
required_if_provider='sips')
sips_secret = fields.Char(
string="SIPS Secret Key", size=64, required_if_provider='sips', groups='base.group_system')
sips_key_version = fields.Integer(
string="Secret Key Version", required_if_provider='sips', default=2)
sips_test_url = fields.Char(
string="Test URL", required_if_provider='sips',
default="https://payment-webinit.simu.sips-services.com/paymentInit")
sips_prod_url = fields.Char(
string="Production URL", required_if_provider='sips',
default="https://payment-webinit.sips-services.com/paymentInit")
sips_version = fields.Char(
string="Interface Version", required_if_provider='sips', default="HP_2.31")
def _get_supported_currencies(self):
""" Override of `payment` to return the supported currencies. """
supported_currencies = super()._get_supported_currencies()
if self.code == 'sips':
supported_currencies = supported_currencies.filtered(
lambda c: c.name in SUPPORTED_CURRENCIES.keys()
)
return supported_currencies
def _sips_generate_shasign(self, data):
""" Generate the shasign for incoming or outgoing communications.
Note: self.ensure_one()
:param str data: The data to use to generate the shasign
:return: shasign
:rtype: str
"""
self.ensure_one()
key = self.sips_secret
shasign = sha256((data + key).encode('utf-8'))
return shasign.hexdigest()