summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2018-10-23 18:30:34 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2018-10-25 14:27:13 (GMT)
commit0e6a724231e501287f8c3593e2691f7e22f06c01 (patch)
treedc7a0324e3a426f28824cef4ec42a94838b0847f
parentd2b5f91e63422dd6f67abda448cdc45f4187b095 (diff)
downloadeopayment-0e6a724231e501287f8c3593e2691f7e22f06c01.zip
eopayment-0e6a724231e501287f8c3593e2691f7e22f06c01.tar.gz
eopayment-0e6a724231e501287f8c3593e2691f7e22f06c01.tar.bz2
paybox: decode correctly responses of validation and cancellation operations (#27543)
-rw-r--r--eopayment/paybox.py3
-rw-r--r--tests/test_paybox.py6
2 files changed, 5 insertions, 4 deletions
diff --git a/eopayment/paybox.py b/eopayment/paybox.py
index ec4d479..b9f79be 100644
--- a/eopayment/paybox.py
+++ b/eopayment/paybox.py
@@ -364,8 +364,9 @@ class Payment(PaymentCommon):
response.raise_for_status()
logger.debug('received %r', response.content)
data = dict(urlparse.parse_qsl(response.content, True, True))
+ data['COMMENTAIRE'] = data.get('COMMENTAIRE', '').decode('iso-8859-1')
if data.get('CODEREPONSE') != PAYBOX_DIRECT_SUCCESS_RESPONSE_CODE:
- raise ResponseError(data.get('COMMENTAIRE'))
+ raise ResponseError(data['COMMENTAIRE'].encode('utf-8'))
return data
def validate(self, amount, bank_data, **kwargs):
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index 6f09be1..ccb0848 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -146,13 +146,13 @@ class PayboxTests(TestCase):
'numero_appel': ['30310733'],
'reference': ['830657461681']
}
- backend_raw_response = """NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR="""
+ backend_raw_response = """NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000&COMMENTAIRE=Demande trait\xe9e avec succ\xe8s&REFABONNE=&PORTEUR="""
backend_expected_response = {"CODEREPONSE": "00000",
"RANG": "32",
"AUTORISATION": "XXXXXX",
"NUMTRANS": "0013989865",
"PORTEUR": "",
- "COMMENTAIRE": "Demande traitée avec succès",
+ "COMMENTAIRE": u"Demande traitée avec succès",
"SITE": "1999888",
"NUMAPPEL": "0030378572",
"REFABONNE": "",
@@ -192,7 +192,7 @@ class PayboxTests(TestCase):
self.assertEqual(requests_post.call_args[0][0], 'https://ppps.paybox.com/PPPS.php')
with mock.patch('eopayment.paybox.requests.post') as requests_post:
- error_response = """CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouvée"""
+ error_response = """CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouv\xe9e"""
response = mock.Mock(status_code=200, content=error_response)
requests_post.return_value = response
self.assertRaisesRegexp(eopayment.ResponseError, 'Transaction non trouvée', getattr(backend, operation_name),