summaryrefslogtreecommitdiff
path: root/addons/payment_authorize/models/payment.py
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-22 11:17:40 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-22 11:43:54 +0000
commit324d3fc93a00a919d4a561f713ec2c5dd0d6b51c (patch)
tree3487e89e219b6d3357635c7ed620447dadfab443 /addons/payment_authorize/models/payment.py
parentf58fa65c2bb1f6ec65b3b9ed7227975ce2799e83 (diff)
parent06f8f0469915f6686d9f5f6f1ab5feff18722ffd (diff)
[MERGE] Forward port of saas-11.3 to 12.0 up to 06f8f046991
closes odoo/odoo#35064 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'addons/payment_authorize/models/payment.py')
-rw-r--r--addons/payment_authorize/models/payment.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py
index 6361a211f16..b1d9a2e6a1e 100644
--- a/addons/payment_authorize/models/payment.py
+++ b/addons/payment_authorize/models/payment.py
@@ -25,6 +25,7 @@ class PaymentAcquirerAuthorize(models.Model):
provider = fields.Selection(selection_add=[('authorize', 'Authorize.Net')])
authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize', groups='base.group_user')
authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize', groups='base.group_user')
+ authorize_signature_key = fields.Char(string='API Signature Key', groups='base.group_user', compute="_compute_auth_signature_key", inverse="_inverse_auth_signature_key")
def _get_feature_support(self):
"""Get advanced feature support by provider.
@@ -42,6 +43,16 @@ class PaymentAcquirerAuthorize(models.Model):
res['tokenize'].append('authorize')
return res
+ def _compute_auth_signature_key(self):
+ ICP = self.env['ir.config_parameter'].sudo()
+ for acquirer in self.filtered(lambda a: a.provider == 'authorize'):
+ acquirer.authorize_signature_key = ICP.get_param('payment_authorize.signature_key_%s' % acquirer.id)
+
+ def _inverse_auth_signature_key(self):
+ ICP = self.env['ir.config_parameter'].sudo()
+ for acquirer in self.filtered(lambda a: a.provider == 'authorize'):
+ ICP.set_param('payment_authorize.signature_key_%s' % acquirer.id, acquirer.authorize_signature_key)
+
def _get_authorize_urls(self, environment):
""" Authorize URLs """
if environment == 'prod':
@@ -57,13 +68,22 @@ class PaymentAcquirerAuthorize(models.Model):
values['x_amount'],
values['x_currency_code']]).encode('utf-8')
- # [BACKWARD COMPATIBILITY] Check that the merchant did update his transaction
- # key to signature key (end of MD5 support from Authorize.net)
+ # [BACKWARD COMPATIBILITY, 2nd edition]
# The signature key is now '128-character hexadecimal format', while the
# transaction key was only 16-character.
- if len(values['x_trans_key']) == 128:
- key = bytes.fromhex(values['x_trans_key'])
- return hmac.new(key, data, hashlib.sha512).hexdigest().upper()
+ # One of 2 things should have happened:
+ # 1/ the Transaction Key has been replaced with the Signature Key value (patch from March 2019)
+ # => Use that to sign, but server-to-server won't work since it uses transaction key
+ # as its credentials
+ # 2/ the Signature key is a new field (patch from July 2019)
+ # => Use that field for the signature
+
+ # FORWARD-PORT NOTE: forward part to saas-12.4 but no further
+ if len(values['x_trans_key']) == 128 and not self.authorize_signature_key:
+ self.authorize_signature_key = values['x_trans_key'] # store in the correct field
+ return hmac.new(bytes.fromhex(values['x_trans_key']), data, hashlib.sha512).hexdigest().upper()
+ elif self.authorize_signature_key:
+ return hmac.new(bytes.fromhex(self.authorize_signature_key), data, hashlib.sha512).hexdigest().upper()
else:
return hmac.new(values['x_trans_key'].encode('utf-8'), data, hashlib.md5).hexdigest()