0002-ogone-add-algo-parameter-51305.patch
eopayment/ogone.py | ||
---|---|---|
461 | 461 |
'default': 'fr_FR', |
462 | 462 |
'choices': (('fr_FR', 'français'),), |
463 | 463 |
}, |
464 |
{ |
|
465 |
'name': 'encoding', |
|
466 |
'caption': _('Characters encoding'), |
|
467 |
'default': 'utf-8', |
|
468 |
'choices': [ |
|
469 |
('iso-8859-1', 'Latin1 (ISO-8859-1)'), |
|
470 |
('utf-8', 'Unicode (UTF-8)'), |
|
471 |
], |
|
472 |
}, |
|
464 | 473 |
{ |
465 | 474 |
'name': 'hash_algorithm', |
466 | 475 |
'caption': 'Algorithme de hachage', |
... | ... | |
485 | 494 |
] |
486 | 495 |
} |
487 | 496 | |
497 |
def __init__(self, options, logger=None): |
|
498 |
# retro-compatibility with old default of latin1 |
|
499 |
options.setdefault('encoding', 'iso-8859-1') |
|
500 |
super(Payment, self).__init__(options, logger=logger) |
|
501 | ||
488 | 502 |
def sha_sign(self, algo, key, params, keep, encoding='iso-8859-1'): |
489 | 503 |
'''Ogone signature algorithm of query string''' |
490 | 504 |
values = params.items() |
... | ... | |
565 | 579 | |
566 | 580 |
def response(self, query_string, **kwargs): |
567 | 581 |
if six.PY3: |
568 |
params = urlparse.parse_qs(query_string, True, encoding='iso-8859-1')
|
|
582 |
params = urlparse.parse_qs(query_string, True, encoding=self.encoding)
|
|
569 | 583 |
else: |
570 | 584 |
params = urlparse.parse_qs(query_string, True) |
571 | 585 |
params = dict((key.upper(), params[key][0]) for key in params) |
572 | 586 |
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']): |
573 | 587 |
raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR') |
574 | 588 | |
575 |
# uniformize iso-8859-1 encoded values
|
|
589 |
# py2: decode binary strings in query-string
|
|
576 | 590 |
for key in params: |
577 |
params[key] = force_text(params[key], 'iso-8859-1')
|
|
591 |
params[key] = force_text(params[key], self.encoding)
|
|
578 | 592 |
reference = params['ORDERID'] |
579 | 593 |
transaction_id = params['PAYID'] |
580 | 594 |
status = params['STATUS'] |
tests/test_ogone.py | ||
---|---|---|
27 | 27 |
PSPID = u'2352566ö' |
28 | 28 | |
29 | 29 | |
30 |
@pytest.fixture |
|
30 |
@pytest.fixture(params=[None, 'iso-8859-1', 'utf-8'])
|
|
31 | 31 |
def params(request): |
32 | 32 |
params = { |
33 | 33 |
'environment': ogone.ENVIRONMENT_TEST, |
... | ... | |
36 | 36 |
'sha_out': u'sécret', |
37 | 37 |
'automatic_return_url': u'http://example.com/autömatic_réturn_url' |
38 | 38 |
} |
39 |
encoding = request.param |
|
40 |
if encoding: |
|
41 |
params['encoding'] = encoding |
|
39 | 42 |
return params |
40 | 43 | |
41 | 44 | |
... | ... | |
77 | 80 |
data = {'orderid': u'myorder', 'status': u'9', 'payid': u'3011229363', |
78 | 81 |
'cn': u'Usér', 'ncerror': u'0', |
79 | 82 |
'trxdate': u'10/24/16', 'acceptance': u'test123', |
80 |
'currency': u'eur', 'amount': u'7.5', |
|
81 |
'shasign': u'CA4B3C2767B5EFAB33B9122A5D4CF6F27747303D'} |
|
83 |
'currency': u'eur', 'amount': u'7.5'} |
|
84 |
data['shasign'] = ogone_backend.backend.sha_sign_out( |
|
85 |
data, encoding=params.get('encoding', 'iso-8859-1')) |
|
82 | 86 |
# uniformize to utf-8 first |
83 | 87 |
for k in data: |
84 |
data[k] = eopayment.common.force_byte(data[k]) |
|
88 |
data[k] = eopayment.common.force_byte(data[k], encoding=params.get('encoding', 'iso-8859-1'))
|
|
85 | 89 |
response = ogone_backend.response(urllib.urlencode(data)) |
86 | 90 |
assert response.signed |
87 | 91 |
assert response.order_id == order_id |
... | ... | |
134 | 138 |
} |
135 | 139 |
# uniformize to expected encoding |
136 | 140 |
for k in data: |
137 |
data[k] = eopayment.common.force_byte(data[k]) |
|
141 |
data[k] = eopayment.common.force_byte(data[k], encoding=params.get('encoding', 'iso-8859-1'))
|
|
138 | 142 |
response = ogone_backend.response(urllib.urlencode(data)) |
139 | 143 |
assert response.signed |
140 | 144 |
assert response.result == eopayment.WAITING |
141 |
- |