From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/adyen_platforms/util.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 addons/adyen_platforms/util.py (limited to 'addons/adyen_platforms/util.py') diff --git a/addons/adyen_platforms/util.py b/addons/adyen_platforms/util.py new file mode 100644 index 00000000..5352a251 --- /dev/null +++ b/addons/adyen_platforms/util.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import base64 +import hashlib +import hmac +import json +import requests +import time +import werkzeug.urls + +class AdyenProxyAuth(requests.auth.AuthBase): + def __init__(self, adyen_account_id): + super(AdyenProxyAuth, self).__init__() + self.adyen_account_id = adyen_account_id + + def __call__(self, request): + h = hmac.new(self.adyen_account_id.proxy_token.encode('utf-8'), digestmod=hashlib.sha256) + + # Craft the message (timestamp|url path|query params|body content) + msg_timestamp = int(time.time()) + parsed_url = werkzeug.urls.url_parse(request.path_url) + body = request.body + if isinstance(body, bytes): + body = body.decode('utf-8') + body = json.loads(body) + + message = '%s|%s|%s|%s' % ( + msg_timestamp, # timestamp + parsed_url.path, # url path + json.dumps(werkzeug.urls.url_decode(parsed_url.query), sort_keys=True), # url query params sorted by key + json.dumps(body, sort_keys=True)) # request body + + h.update(message.encode('utf-8')) # digest the message + + request.headers.update({ + 'oe-adyen-uuid': self.adyen_account_id.adyen_uuid, + 'oe-signature': base64.b64encode(h.digest()), + 'oe-timestamp': msg_timestamp, + }) + + return request -- cgit v1.2.3