0001-paybox-decode-correctly-responses-of-validation-and-.patch
eopayment/paybox.py | ||
---|---|---|
363 | 363 |
response = requests.post(url, params) |
364 | 364 |
response.raise_for_status() |
365 | 365 |
logger.debug('received %r', response.content) |
366 |
data = dict(urlparse.parse_qsl(response.content, True, True)) |
|
366 |
# decode response first as paybox encodes it in iso-8859-1 |
|
367 |
decoded_response = response.content.decode('iso-8859-1') |
|
368 |
data = dict(urlparse.parse_qsl(decoded_response, True, True)) |
|
367 | 369 |
if data.get('CODEREPONSE') != PAYBOX_DIRECT_SUCCESS_RESPONSE_CODE: |
368 |
raise ResponseError(data.get('COMMENTAIRE')) |
|
370 |
raise ResponseError(data.get('COMMENTAIRE').encode('utf-8'))
|
|
369 | 371 |
return data |
370 | 372 | |
371 | 373 |
def validate(self, amount, bank_data, **kwargs): |
tests/test_paybox.py | ||
---|---|---|
146 | 146 |
'numero_appel': ['30310733'], |
147 | 147 |
'reference': ['830657461681'] |
148 | 148 |
} |
149 |
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="""
|
|
149 |
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="""
|
|
150 | 150 |
backend_expected_response = {"CODEREPONSE": "00000", |
151 | 151 |
"RANG": "32", |
152 | 152 |
"AUTORISATION": "XXXXXX", |
153 | 153 |
"NUMTRANS": "0013989865", |
154 | 154 |
"PORTEUR": "", |
155 |
"COMMENTAIRE": "Demande traitée avec succès", |
|
155 |
"COMMENTAIRE": u"Demande traitée avec succès",
|
|
156 | 156 |
"SITE": "1999888", |
157 | 157 |
"NUMAPPEL": "0030378572", |
158 | 158 |
"REFABONNE": "", |
... | ... | |
192 | 192 |
self.assertEqual(requests_post.call_args[0][0], 'https://ppps.paybox.com/PPPS.php') |
193 | 193 | |
194 | 194 |
with mock.patch('eopayment.paybox.requests.post') as requests_post: |
195 |
error_response = """CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouvée"""
|
|
195 |
error_response = """CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouv\xe9e"""
|
|
196 | 196 |
response = mock.Mock(status_code=200, content=error_response) |
197 | 197 |
requests_post.return_value = response |
198 | 198 |
self.assertRaisesRegexp(eopayment.ResponseError, 'Transaction non trouvée', getattr(backend, operation_name), |
199 |
- |