ogone: add algo parameter (#51305)
This commit is contained in:
parent
42644a5a71
commit
a546bbaf5b
|
@ -461,6 +461,15 @@ class Payment(PaymentCommon):
|
|||
'default': 'fr_FR',
|
||||
'choices': (('fr_FR', 'français'),),
|
||||
},
|
||||
{
|
||||
'name': 'encoding',
|
||||
'caption': _('Characters encoding'),
|
||||
'default': 'utf-8',
|
||||
'choices': [
|
||||
('iso-8859-1', 'Latin1 (ISO-8859-1)'),
|
||||
('utf-8', 'Unicode (UTF-8)'),
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'hash_algorithm',
|
||||
'caption': 'Algorithme de hachage',
|
||||
|
@ -485,6 +494,11 @@ class Payment(PaymentCommon):
|
|||
]
|
||||
}
|
||||
|
||||
def __init__(self, options, logger=None):
|
||||
# retro-compatibility with old default of latin1
|
||||
options.setdefault('encoding', 'iso-8859-1')
|
||||
super(Payment, self).__init__(options, logger=logger)
|
||||
|
||||
def sha_sign(self, algo, key, params, keep, encoding='iso-8859-1'):
|
||||
'''Ogone signature algorithm of query string'''
|
||||
values = params.items()
|
||||
|
@ -565,16 +579,16 @@ class Payment(PaymentCommon):
|
|||
|
||||
def response(self, query_string, **kwargs):
|
||||
if six.PY3:
|
||||
params = urlparse.parse_qs(query_string, True, encoding='iso-8859-1')
|
||||
params = urlparse.parse_qs(query_string, True, encoding=self.encoding)
|
||||
else:
|
||||
params = urlparse.parse_qs(query_string, True)
|
||||
params = dict((key.upper(), params[key][0]) for key in params)
|
||||
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']):
|
||||
raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR')
|
||||
|
||||
# uniformize iso-8859-1 encoded values
|
||||
# py2: decode binary strings in query-string
|
||||
for key in params:
|
||||
params[key] = force_text(params[key], 'iso-8859-1')
|
||||
params[key] = force_text(params[key], self.encoding)
|
||||
reference = params['ORDERID']
|
||||
transaction_id = params['PAYID']
|
||||
status = params['STATUS']
|
||||
|
|
|
@ -27,7 +27,7 @@ from eopayment import ResponseError
|
|||
PSPID = u'2352566ö'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture(params=[None, 'iso-8859-1', 'utf-8'])
|
||||
def params(request):
|
||||
params = {
|
||||
'environment': ogone.ENVIRONMENT_TEST,
|
||||
|
@ -36,6 +36,9 @@ def params(request):
|
|||
'sha_out': u'sécret',
|
||||
'automatic_return_url': u'http://example.com/autömatic_réturn_url'
|
||||
}
|
||||
encoding = request.param
|
||||
if encoding:
|
||||
params['encoding'] = encoding
|
||||
return params
|
||||
|
||||
|
||||
|
@ -77,11 +80,12 @@ def test_response(params):
|
|||
data = {'orderid': u'myorder', 'status': u'9', 'payid': u'3011229363',
|
||||
'cn': u'Usér', 'ncerror': u'0',
|
||||
'trxdate': u'10/24/16', 'acceptance': u'test123',
|
||||
'currency': u'eur', 'amount': u'7.5',
|
||||
'shasign': u'CA4B3C2767B5EFAB33B9122A5D4CF6F27747303D'}
|
||||
'currency': u'eur', 'amount': u'7.5'}
|
||||
data['shasign'] = ogone_backend.backend.sha_sign_out(
|
||||
data, encoding=params.get('encoding', 'iso-8859-1'))
|
||||
# uniformize to utf-8 first
|
||||
for k in data:
|
||||
data[k] = eopayment.common.force_byte(data[k])
|
||||
data[k] = eopayment.common.force_byte(data[k], encoding=params.get('encoding', 'iso-8859-1'))
|
||||
response = ogone_backend.response(urllib.urlencode(data))
|
||||
assert response.signed
|
||||
assert response.order_id == order_id
|
||||
|
@ -134,7 +138,7 @@ def test_bank_transfer_response(params):
|
|||
}
|
||||
# uniformize to expected encoding
|
||||
for k in data:
|
||||
data[k] = eopayment.common.force_byte(data[k])
|
||||
data[k] = eopayment.common.force_byte(data[k], encoding=params.get('encoding', 'iso-8859-1'))
|
||||
response = ogone_backend.response(urllib.urlencode(data))
|
||||
assert response.signed
|
||||
assert response.result == eopayment.WAITING
|
||||
|
|
Loading…
Reference in New Issue