summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2021-02-20 18:44:45 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2021-02-25 09:54:39 (GMT)
commita546bbaf5b1dc354a39f5afa01f1e1ac162d8fcd (patch)
treefb6189ecb93a3eb66aa6e3150c8bb63af04925b7
parent42644a5a713b74c14bf8cc03034e9bec45971408 (diff)
downloadeopayment-a546bbaf5b1dc354a39f5afa01f1e1ac162d8fcd.zip
eopayment-a546bbaf5b1dc354a39f5afa01f1e1ac162d8fcd.tar.gz
eopayment-a546bbaf5b1dc354a39f5afa01f1e1ac162d8fcd.tar.bz2
ogone: add algo parameter (#51305)v1.66
-rw-r--r--eopayment/ogone.py20
-rw-r--r--tests/test_ogone.py14
2 files changed, 26 insertions, 8 deletions
diff --git a/eopayment/ogone.py b/eopayment/ogone.py
index 185e143..4aa7086 100644
--- a/eopayment/ogone.py
+++ b/eopayment/ogone.py
@@ -462,6 +462,15 @@ class Payment(PaymentCommon):
'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',
'default': 'sha1',
@@ -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']
diff --git a/tests/test_ogone.py b/tests/test_ogone.py
index edd4a50..b9c1440 100644
--- a/tests/test_ogone.py
+++ b/tests/test_ogone.py
@@ -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