From 4d89e60b532ff040dd87b8ca20e2313bea83967a Mon Sep 17 00:00:00 2001 From: Alex Hedlund Date: Fri, 30 Jan 2015 10:39:33 +0200 Subject: [PATCH] Fix python3 incompatibility issues --- checkout/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/checkout/__init__.py b/checkout/__init__.py index e271005..ffe5c41 100644 --- a/checkout/__init__.py +++ b/checkout/__init__.py @@ -14,6 +14,7 @@ import hmac import json import requests +import sys import xml.etree.ElementTree as ET class CheckoutException(Exception): @@ -260,6 +261,8 @@ def _calculate_payment_md5(self, params, merchant_secret): params["ADDRESS"], params["POSTCODE"], params["POSTOFFICE"], merchant_secret] base = '+'.join(fields) + if sys.version_info >= (3, 0, 0): + base = base.encode('utf-8') return hashlib.md5(base).hexdigest().upper() def validate_payment_return(self, mac, version, order_number, order_reference, payment, status, algorithm): @@ -286,4 +289,8 @@ def validate_payment_return(self, mac, version, order_number, order_reference, p """ fields = [version, order_number, order_reference, payment, status, algorithm] base = '&'.join(fields) - return mac == hmac.new(self.merchant_secret, base, hashlib.sha256).hexdigest().upper() + ms = self.merchant_secret + if sys.version_info >= (3, 0, 0): + base = base.encode('utf-8') + ms = ms.encode('utf-8') + return mac == hmac.new(ms, base, hashlib.sha256).hexdigest().upper()