summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-10-29 14:30:38 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-10-29 15:24:44 (GMT)
commit8a6702066d806b578ddc04145ec6910e6474f553 (patch)
tree12100a31945ad70ff6adb3c879704980fded014e
parent3d34d44246a90a73bad076d0d31dda6da9d08e34 (diff)
downloadeopayment-master.zip
eopayment-master.tar.gz
eopayment-master.tar.bz2
paybox: fix validate/cancel operations encoding handling (#37322)HEADv1.38master
-rw-r--r--eopayment/paybox.py6
-rw-r--r--tests/test_paybox.py17
2 files changed, 13 insertions, 10 deletions
diff --git a/eopayment/paybox.py b/eopayment/paybox.py
index a451702..adf20e1 100644
--- a/eopayment/paybox.py
+++ b/eopayment/paybox.py
@@ -372,10 +372,8 @@ class Payment(PaymentCommon):
}
response = requests.post(url, params)
response.raise_for_status()
- logger.debug('received %r', response.content)
- data = dict(urlparse.parse_qsl(response.content, True, True))
- if six.PY2:
- data['COMMENTAIRE'] = data.get('COMMENTAIRE', '').decode('iso-8859-1')
+ logger.debug('received %r', response.text)
+ data = dict(urlparse.parse_qsl(response.text, True, True))
if data.get('CODEREPONSE') != PAYBOX_DIRECT_SUCCESS_RESPONSE_CODE:
if six.PY2:
raise ResponseError(data['COMMENTAIRE'].encode('utf-8'))
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index 1782f4b..a503063 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -177,7 +177,7 @@ 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\xe9e avec succ\xe8s&REFABONNE=&PORTEUR="""
+ backend_raw_response = u"""NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR="""
backend_expected_response = {"CODEREPONSE": "00000",
"RANG": "32",
"AUTORISATION": "XXXXXX",
@@ -190,7 +190,7 @@ class PayboxTests(TestCase):
"NUMQUESTION": "0013989862"}
with mock.patch('eopayment.paybox.requests.post') as requests_post:
- response = mock.Mock(status_code=200, content=backend_raw_response)
+ response = mock.Mock(status_code=200, text=backend_raw_response)
requests_post.return_value = response
backend_response = getattr(backend, operation_name)(Decimal('10'), bank_data)
self.assertEqual(requests_post.call_args[0][0], 'https://preprod-ppps.paybox.com/PPPS.php')
@@ -217,14 +217,14 @@ class PayboxTests(TestCase):
params['platform'] = 'prod'
backend = eopayment.Payment('paybox', params)
with mock.patch('eopayment.paybox.requests.post') as requests_post:
- response = mock.Mock(status_code=200, content=backend_raw_response)
+ response = mock.Mock(status_code=200, text=backend_raw_response)
requests_post.return_value = response
getattr(backend, operation_name)(Decimal('10'), bank_data)
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\xe9e"""
- response = mock.Mock(status_code=200, content=error_response)
+ error_response = u"""CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouvée"""
+ response = mock.Mock(status_code=200, text=error_response)
requests_post.return_value = response
self.assertRaisesRegexp(eopayment.ResponseError, 'Transaction non trouvée', getattr(backend, operation_name),
Decimal('10'), bank_data)
@@ -238,7 +238,12 @@ 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 = u"""NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR="""
+
+ with mock.patch('eopayment.paybox.requests.post') as requests_post:
+ response = mock.Mock(status_code=200, text=backend_raw_response)
+ requests_post.return_value = response
+ backend.validate(Decimal(12), bank_data)
def test_rsa_signature_validation(self):