summaryrefslogtreecommitdiffstats
path: root/eopayment/systempayv2.py
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-26 07:56:16 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-07-26 14:25:28 (GMT)
commit887832bc5fb442ef887e8690c5353bf833854c32 (patch)
tree96cb8ad46db0321712792d78fbfb17b5f8296716 /eopayment/systempayv2.py
parent31b85ae9fdece1c2c5fd7a862bae0e037e85eb87 (diff)
downloadeopayment-887832bc5fb442ef887e8690c5353bf833854c32.zip
eopayment-887832bc5fb442ef887e8690c5353bf833854c32.tar.gz
eopayment-887832bc5fb442ef887e8690c5353bf833854c32.tar.bz2
add python3 compatibility (#23720)
Diffstat (limited to 'eopayment/systempayv2.py')
-rw-r--r--eopayment/systempayv2.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py
index ccf38d0..d2de01c 100644
--- a/eopayment/systempayv2.py
+++ b/eopayment/systempayv2.py
@@ -4,13 +4,13 @@ import datetime as dt
import hashlib
import logging
import string
-import urlparse
+from six.moves.urllib import parse as urlparse
import warnings
from gettext import gettext as _
-from common import (PaymentCommon, PaymentResponse, PAID, ERROR, FORM, Form,
- ResponseError, force_text, force_byte)
-from cb import CB_RESPONSE_CODES
+from .common import (PaymentCommon, PaymentResponse, PAID, ERROR, FORM, Form,
+ ResponseError, force_text, force_byte)
+from .cb import CB_RESPONSE_CODES
__all__ = ['Payment']
@@ -117,20 +117,20 @@ PARAMETERS = [
'ONEY_SANDBOX, PAYPAL, PAYPAL_SB, PAYSAFECARD, '
'VISA')),
# must be SINGLE or MULTI with parameters
- Parameter('vads_payment_config', '', 07, default='SINGLE',
+ Parameter('vads_payment_config', '', 7, default='SINGLE',
choices=('SINGLE', 'MULTI'), needed=True),
Parameter('vads_return_mode', None, 48, default='GET',
choices=('', 'NONE', 'POST', 'GET')),
Parameter('signature', 'an', None, length=40),
- Parameter('vads_site_id', 'n', 02, length=8, needed=True,
+ Parameter('vads_site_id', 'n', 2, length=8, needed=True,
description=_(u'Identifiant de la boutique')),
Parameter('vads_theme_config', 'ans', 32, max_length=255),
- Parameter(VADS_TRANS_DATE, 'n', 04, length=14, needed=True,
+ Parameter(VADS_TRANS_DATE, 'n', 4, length=14, needed=True,
default=isonow),
- Parameter('vads_trans_id', 'n', 03, length=6, needed=True),
+ Parameter('vads_trans_id', 'n', 3, length=6, needed=True),
Parameter('vads_validation_mode', 'n', 5, max_length=1, choices=('', 0, 1),
default=''),
- Parameter('vads_version', 'an', 01, default='V2', needed=True,
+ Parameter('vads_version', 'an', 1, default='V2', needed=True,
choices=('V2',)),
Parameter('vads_url_success', 'ans', 24, max_length=127),
Parameter('vads_url_referral', 'ans', 26, max_length=127),
@@ -173,7 +173,7 @@ EXTRA_RESULT_MAP = {
def add_vads(kwargs):
new_vargs = {}
- for k, v in kwargs.iteritems():
+ for k, v in kwargs.items():
if k.startswith('vads_'):
new_vargs[k] = v
else:
@@ -276,8 +276,8 @@ class Payment(PaymentCommon):
info2, info3, next_url, kwargs)
# amount unit is cents
amount = '%.0f' % (100 * amount)
- kwargs.update(add_vads({'amount': unicode(amount)}))
- if amount < 0:
+ kwargs.update(add_vads({'amount': force_text(amount)}))
+ if int(amount) < 0:
raise ValueError('amount must be an integer >= 0')
normal_return_url = self.normal_return_url
if next_url:
@@ -285,30 +285,30 @@ class Payment(PaymentCommon):
"set normal_return_url in options", DeprecationWarning)
normal_return_url = next_url
if normal_return_url:
- kwargs[VADS_URL_RETURN] = unicode(normal_return_url)
+ kwargs[VADS_URL_RETURN] = force_text(normal_return_url)
if name is not None:
- kwargs['vads_cust_name'] = unicode(name)
+ kwargs['vads_cust_name'] = force_text(name)
if first_name is not None:
- kwargs[VADS_CUST_FIRST_NAME] = unicode(first_name)
+ kwargs[VADS_CUST_FIRST_NAME] = force_text(first_name)
if last_name is not None:
- kwargs[VADS_CUST_LAST_NAME] = unicode(last_name)
+ kwargs[VADS_CUST_LAST_NAME] = force_text(last_name)
if address is not None:
- kwargs['vads_cust_address'] = unicode(address)
+ kwargs['vads_cust_address'] = force_text(address)
if email is not None:
- kwargs['vads_cust_email'] = unicode(email)
+ kwargs['vads_cust_email'] = force_text(email)
if phone is not None:
- kwargs['vads_cust_phone'] = unicode(phone)
+ kwargs['vads_cust_phone'] = force_text(phone)
if info1 is not None:
- kwargs['vads_order_info'] = unicode(info1)
+ kwargs['vads_order_info'] = force_text(info1)
if info2 is not None:
- kwargs['vads_order_info2'] = unicode(info2)
+ kwargs['vads_order_info2'] = force_text(info2)
if info3 is not None:
- kwargs['vads_order_info3'] = unicode(info3)
+ kwargs['vads_order_info3'] = force_text(info3)
if orderid is not None:
# check orderid format first
name = 'vads_order_id'
- orderid = unicode(orderid)
+ orderid = force_text(orderid)
ptype = 'an-'
p = Parameter(name, ptype, 13, max_length=32)
if not p.check_value(orderid):
@@ -318,14 +318,14 @@ class Payment(PaymentCommon):
transaction_id = self.transaction_id(6, string.digits, 'systempay',
self.options[VADS_SITE_ID])
- kwargs[VADS_TRANS_ID] = unicode(transaction_id)
+ kwargs[VADS_TRANS_ID] = force_text(transaction_id)
fields = kwargs
for parameter in PARAMETERS:
name = parameter.name
# import default parameters from configuration
if name not in fields \
and name in self.options:
- fields[name] = unicode(self.options[name])
+ fields[name] = force_text(self.options[name])
# import default parameters from module
if name not in fields and parameter.default is not None:
if callable(parameter.default):
@@ -333,7 +333,7 @@ class Payment(PaymentCommon):
else:
fields[name] = parameter.default
check_vads(fields)
- fields[SIGNATURE] = unicode(self.signature(fields))
+ fields[SIGNATURE] = force_text(self.signature(fields))
self.logger.debug('%s request contains fields: %s', __name__, fields)
transaction_id = '%s_%s' % (fields[VADS_TRANS_DATE], transaction_id)
self.logger.debug('%s transaction id: %s', __name__, transaction_id)
@@ -346,14 +346,14 @@ class Payment(PaymentCommon):
'name': force_text(field_name),
'value': force_text(field_value),
}
- for field_name, field_value in fields.iteritems()])
+ for field_name, field_value in fields.items()])
return transaction_id, FORM, form
def response(self, query_string, **kwargs):
fields = urlparse.parse_qs(query_string, True)
if not set(fields) >= set([SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT]):
raise ResponseError()
- for key, value in fields.iteritems():
+ for key, value in fields.items():
fields[key] = value[0]
copy = fields.copy()
bank_status = []
@@ -417,8 +417,8 @@ class Payment(PaymentCommon):
self.logger.debug('ordered keys %s' % ordered_keys)
ordered_fields = [force_byte(fields[key]) for key in ordered_keys]
secret = getattr(self, 'secret_%s' % fields['vads_ctx_mode'].lower())
- signed_data = '+'.join(ordered_fields)
- signed_data = '%s+%s' % (signed_data, force_byte(secret))
+ signed_data = b'+'.join(ordered_fields)
+ signed_data = b'%s+%s' % (signed_data, force_byte(secret))
self.logger.debug(u'generating signature on «%s»', signed_data)
sign = hashlib.sha1(signed_data).hexdigest()
self.logger.debug(u'signature «%s»', sign)