summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-26 18:20:26 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-07-25 08:22:22 (GMT)
commitf99d6eeb91b4541dbdd8c772b5424cd05f4f39aa (patch)
tree78de347d67f83f0365537f1487706338ea3d6314
parentf3611bcc38fc595129d58c3126a857126e39b457 (diff)
downloadeopayment-f99d6eeb91b4541dbdd8c772b5424cd05f4f39aa.zip
eopayment-f99d6eeb91b4541dbdd8c772b5424cd05f4f39aa.tar.gz
eopayment-f99d6eeb91b4541dbdd8c772b5424cd05f4f39aa.tar.bz2
sips2: adapt for python3
-rw-r--r--eopayment/sips2.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/eopayment/sips2.py b/eopayment/sips2.py
index ef709e3..4def5d7 100644
--- a/eopayment/sips2.py
+++ b/eopayment/sips2.py
@@ -12,7 +12,7 @@ import requests
import warnings
from .common import (PaymentCommon, FORM, Form, PaymentResponse, PAID, ERROR,
- CANCELED, ResponseError)
+ CANCELED, ResponseError, force_text)
__all__ = ['Payment']
@@ -139,12 +139,12 @@ class Payment(PaymentCommon):
}
def encode_data(self, data):
- return u'|'.join(u'%s=%s' % (unicode(key), unicode(value))
+ return u'|'.join(u'%s=%s' % (force_text(key), force_text(value))
for key, value in data.items())
def seal_data(self, data):
s = self.encode_data(data)
- s += unicode(self.secret_key)
+ s += force_text(self.secret_key)
s = s.encode('utf-8')
s = hashlib.sha256(s).hexdigest()
return s
@@ -172,13 +172,13 @@ class Payment(PaymentCommon):
info1=None, info2=None, info3=None, next_url=None, **kwargs):
data = self.get_data()
transaction_id = self.transaction_id(10, string.digits, 'sips2', data['merchantId'])
- data['transactionReference'] = unicode(transaction_id)
- data['orderId'] = orderid or unicode(uuid.uuid4()).replace('-', '')
+ data['transactionReference'] = force_text(transaction_id)
+ data['orderId'] = orderid or force_text(uuid.uuid4()).replace('-', '')
if info1:
- data['statementReference'] = unicode(info1)
+ data['statementReference'] = force_text(info1)
else:
data['statementReference'] = data['transactionReference']
- data['amount'] = unicode(int(Decimal(amount) * 100))
+ data['amount'] = force_text(int(Decimal(amount) * 100))
if email:
data['billingContact.email'] = email
if 'captureDay' in kwargs:
@@ -215,7 +215,7 @@ class Payment(PaymentCommon):
def decode_data(self, data):
data = data.split('|')
- data = [map(unicode, p.split('=', 1)) for p in data]
+ data = [map(force_text, p.split('=', 1)) for p in data]
return collections.OrderedDict(data)
def check_seal(self, data, seal):
@@ -254,9 +254,9 @@ class Payment(PaymentCommon):
for key in sorted(data.keys()):
if key in ('keyVersion', 'sealAlgorithm', 'seal'):
continue
- data_to_send.append(unicode(data[key]))
+ data_to_send.append(force_text(data[key]))
data_to_send_str = u''.join(data_to_send).encode('utf-8')
- return hmac.new(unicode(self.secret_key).encode('utf-8'), data_to_send_str, hashlib.sha256).hexdigest()
+ return hmac.new(force_text(self.secret_key).encode('utf-8'), data_to_send_str, hashlib.sha256).hexdigest()
def perform_cash_management_operation(self, endpoint, data):
data['merchantId'] = self.merchant_id
@@ -282,13 +282,13 @@ class Payment(PaymentCommon):
def cancel(self, amount, bank_data, **kwargs):
data = {}
- data['operationAmount'] = unicode(int(Decimal(amount) * 100))
+ data['operationAmount'] = force_text(int(Decimal(amount) * 100))
data['transactionReference'] = bank_data.get('transactionReference')
return self.perform_cash_management_operation('cancel', data)
def validate(self, amount, bank_data, **kwargs):
data = {}
- data['operationAmount'] = unicode(int(Decimal(amount) * 100))
+ data['operationAmount'] = force_text(int(Decimal(amount) * 100))
data['transactionReference'] = bank_data.get('transactionReference')
return self.perform_cash_management_operation('validate', data)