sips2: adapt for python3
This commit is contained in:
parent
f3611bcc38
commit
f99d6eeb91
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue