summaryrefslogtreecommitdiff
path: root/addons/adyen_platforms/util.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/adyen_platforms/util.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/adyen_platforms/util.py')
-rw-r--r--addons/adyen_platforms/util.py42
1 files changed, 42 insertions, 0 deletions
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