[IMP] payment_ogone: add possibility to use sha256
SHA1 is going to be deprecated by ogone. This change try to keep current behaviour while adding the possibility to use SHA256 and SHA512 via a Selection field available in the developer mode. opw-2766648 X-original-commit: b0df4af See also: - https://github.com/odoo/upgrade/pull/3490 - https://github.com/odoo/documentation/pull/1902 closes odoo/odoo#88628 Related: odoo/documentation#1902 Related: odoo/upgrade#3490 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import logging
|
||||
from hashlib import sha1
|
||||
from hashlib import new as hashnew
|
||||
|
||||
import requests
|
||||
|
||||
@@ -30,6 +30,10 @@ class PaymentAcquirer(models.Model):
|
||||
string="SHA Key IN", required_if_provider='ogone', groups='base.group_system')
|
||||
ogone_shakey_out = fields.Char(
|
||||
string="SHA Key OUT", required_if_provider='ogone', groups='base.group_system')
|
||||
ogone_hash_function = fields.Selection(
|
||||
[('sha1', 'SHA1'), ('sha256', 'SHA256'), ('sha512', 'SHA512')], default='sha512',
|
||||
string="Hash function", required_if_provider='ogone',
|
||||
)
|
||||
|
||||
#=== COMPUTE METHODS ===#
|
||||
|
||||
@@ -99,7 +103,9 @@ class PaymentAcquirer(models.Model):
|
||||
formatted_items = [(k.upper(), v) for k, v in values.items()]
|
||||
sorted_items = sorted(formatted_items)
|
||||
signing_string = ''.join(f'{k}={v}{key}' for k, v in sorted_items if _filter_key(k) and v)
|
||||
return sha1(signing_string.encode()).hexdigest()
|
||||
shasign = hashnew(self.ogone_hash_function)
|
||||
shasign.update(signing_string.encode())
|
||||
return shasign.hexdigest()
|
||||
|
||||
def _ogone_make_request(self, payload=None, method='POST'):
|
||||
""" Make a request to one of Ogone APIs.
|
||||
|
||||
@@ -15,6 +15,7 @@ class OgoneCommon(PaymentCommon):
|
||||
'ogone_password': 'dummy',
|
||||
'ogone_shakey_in': 'dummy',
|
||||
'ogone_shakey_out': 'dummy',
|
||||
'ogone_hash_function': 'sha1',
|
||||
})
|
||||
|
||||
cls.acquirer = cls.ogone
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<field name="ogone_password" attrs="{'required':[('provider', '=', 'ogone'), ('state', '!=', 'disabled')]}" password="True"/>
|
||||
<field name="ogone_shakey_in" attrs="{'required':[('provider', '=', 'ogone'), ('state', '!=', 'disabled')]}" password="True"/>
|
||||
<field name="ogone_shakey_out" attrs="{'required':[('provider', '=', 'ogone'), ('state', '!=', 'disabled')]}" password="True"/>
|
||||
<field name="ogone_hash_function" attrs="{'required':[('provider', '=', 'ogone'), ('state', '!=', 'disabled')]}" groups="base.group_no_one"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user