summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2018-08-22 21:14:53 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2018-08-22 21:14:53 (GMT)
commite8f12c5d1fd7b9cf5bd2526898b2004a3bbee8b0 (patch)
treeb7a35299b288c0c84f0146fa51a0798d84458c3b
parentcdd3295e398be15d4327c4bd5309b2dfd194fd23 (diff)
downloadeopayment-e8f12c5d1fd7b9cf5bd2526898b2004a3bbee8b0.zip
eopayment-e8f12c5d1fd7b9cf5bd2526898b2004a3bbee8b0.tar.gz
eopayment-e8f12c5d1fd7b9cf5bd2526898b2004a3bbee8b0.tar.bz2
add a message in ResponseErrors (#25773)v1.26
-rw-r--r--eopayment/dummy.py2
-rw-r--r--eopayment/ogone.py2
-rw-r--r--eopayment/paybox.py2
-rw-r--r--eopayment/sips.py2
-rw-r--r--eopayment/sips2.py2
-rw-r--r--eopayment/spplus.py2
-rw-r--r--eopayment/systempayv2.py3
-rw-r--r--eopayment/tipi.py4
-rw-r--r--tests/test_dummy.py5
-rw-r--r--tests/test_ogone.py2
-rw-r--r--tests/test_paybox.py3
-rw-r--r--tests/test_sips2.py5
-rw-r--r--tests/test_spplus.py4
-rw-r--r--tests/test_systempayv2.py6
-rw-r--r--tests/test_tipi.py4
15 files changed, 38 insertions, 10 deletions
diff --git a/eopayment/dummy.py b/eopayment/dummy.py
index 330a618..98c63e0 100644
--- a/eopayment/dummy.py
+++ b/eopayment/dummy.py
@@ -120,7 +120,7 @@ class Payment(PaymentCommon):
def response(self, query_string, logger=LOGGER, **kwargs):
form = parse_qs(force_text(query_string))
if not 'transaction_id' in form:
- raise ResponseError()
+ raise ResponseError('missing transaction_id')
transaction_id = form.get('transaction_id',[''])[0]
form[self.BANK_ID] = transaction_id
diff --git a/eopayment/ogone.py b/eopayment/ogone.py
index af0600d..f2788ec 100644
--- a/eopayment/ogone.py
+++ b/eopayment/ogone.py
@@ -540,7 +540,7 @@ class Payment(PaymentCommon):
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()
+ raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR')
# uniformize iso-8859-1 encoded values
for key in params:
diff --git a/eopayment/paybox.py b/eopayment/paybox.py
index 4333173..6e70143 100644
--- a/eopayment/paybox.py
+++ b/eopayment/paybox.py
@@ -264,7 +264,7 @@ class Payment(PaymentCommon):
def response(self, query_string, callback=False, **kwargs):
d = urlparse.parse_qs(query_string, True, False)
if not set(d) >= set(['erreur', 'reference']):
- raise ResponseError()
+ raise ResponseError('missing erreur or reference')
signed = False
if 'signature' in d:
sig = d['signature'][0]
diff --git a/eopayment/sips.py b/eopayment/sips.py
index ced03a8..9c06d83 100644
--- a/eopayment/sips.py
+++ b/eopayment/sips.py
@@ -160,7 +160,7 @@ class Payment(PaymentCommon):
def response(self, query_string, **kwargs):
form = urlparse.parse_qs(query_string)
if not DATA in form:
- raise ResponseError()
+ raise ResponseError('missing %s' % DATA)
params = {'message': form[DATA][0]}
result = self.execute('response', params)
d = dict(zip(RESPONSE_PARAMS, result))
diff --git a/eopayment/sips2.py b/eopayment/sips2.py
index 4def5d7..fe4de5a 100644
--- a/eopayment/sips2.py
+++ b/eopayment/sips2.py
@@ -229,7 +229,7 @@ class Payment(PaymentCommon):
def response(self, query_string, **kwargs):
form = urlparse.parse_qs(query_string)
if not set(form) >= set(['Data', 'Seal', 'InterfaceVersion']):
- raise ResponseError()
+ raise ResponseError('missing Data, Seal or InterfaceVersion')
self.logger.debug('received query string %r', form)
data = self.decode_data(form['Data'][0])
seal = form['Seal'][0]
diff --git a/eopayment/spplus.py b/eopayment/spplus.py
index e8b1ffc..771a672 100644
--- a/eopayment/spplus.py
+++ b/eopayment/spplus.py
@@ -177,7 +177,7 @@ class Payment(PaymentCommon):
def response(self, query_string, logger=LOGGER, **kwargs):
form = urlparse.parse_qs(query_string)
if not set(form) >= set([REFERENCE, ETAT, REFSFP]):
- raise ResponseError()
+ raise ResponseError('missing %s, %s or %s' % (REFERENCE, ETAT, REFSFP))
for key, value in form.items():
form[key] = value[0]
logger.debug('received query_string %s' % query_string)
diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py
index d2de01c..3002010 100644
--- a/eopayment/systempayv2.py
+++ b/eopayment/systempayv2.py
@@ -352,7 +352,8 @@ class Payment(PaymentCommon):
def response(self, query_string, **kwargs):
fields = urlparse.parse_qs(query_string, True)
if not set(fields) >= set([SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT]):
- raise ResponseError()
+ raise ResponseError('missing %s, %s or %s' % (SIGNATURE, VADS_CTX_MODE,
+ VADS_AUTH_RESULT))
for key, value in fields.items():
fields[key] = value[0]
copy = fields.copy()
diff --git a/eopayment/tipi.py b/eopayment/tipi.py
index 4e18c39..ef20199 100644
--- a/eopayment/tipi.py
+++ b/eopayment/tipi.py
@@ -145,12 +145,12 @@ class Payment(PaymentCommon):
def response(self, query_string, **kwargs):
fields = parse_qs(query_string, True)
if not set(fields) >= set(['refdet', 'resultrans']):
- raise ResponseError()
+ raise ResponseError('missing refdet or resultrans')
for key, value in fields.items():
fields[key] = value[0]
refdet = fields.get('refdet')
if refdet is None:
- raise ValueError('refdet is missing')
+ raise ResponseError('refdet is missing')
if 'objet' in fields:
iso_now = fields['objet']
else:
diff --git a/tests/test_dummy.py b/tests/test_dummy.py
index caac610..1725673 100644
--- a/tests/test_dummy.py
+++ b/tests/test_dummy.py
@@ -1,4 +1,5 @@
import eopayment
+import pytest
def test_dummy():
options = {
@@ -17,3 +18,7 @@ def test_dummy():
assert r.signed
assert r.transaction_id == '6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T'
assert r.return_content == 'signature ok'
+
+ data = {'foo': 'bar'}
+ with pytest.raises(eopayment.ResponseError, match='missing transaction_id'):
+ p.response('foo=bar')
diff --git a/tests/test_ogone.py b/tests/test_ogone.py
index b667445..c44596d 100644
--- a/tests/test_ogone.py
+++ b/tests/test_ogone.py
@@ -76,7 +76,7 @@ class OgoneTests(TestCase):
ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
order_id = 'myorder'
data = {'payid': '32100123', 'status': 9, 'ncerror': 0}
- with self.assertRaises(ResponseError):
+ with self.assertRaisesRegexp(ResponseError, 'missing ORDERID, PAYID, STATUS or NCERROR'):
response = ogone_backend.response(urllib.urlencode(data))
def test_bank_transfer_response(self):
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index bedcb69..abea656 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -92,6 +92,9 @@ class PayboxTests(TestCase):
response = backend.response(urllib.urlencode(data))
self.assertEqual(response.order_id, order_id)
+ with self.assertRaisesRegexp(eopayment.ResponseError, 'missing erreur or reference'):
+ backend.response('foo=bar')
+
def test_rsa_signature_validation(self):
pkey = '''-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUgYufHuheMztK1LhQSG6xsOzb
diff --git a/tests/test_sips2.py b/tests/test_sips2.py
index a2250b4..65e63f1 100644
--- a/tests/test_sips2.py
+++ b/tests/test_sips2.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import eopayment
+import pytest
+
def test_build_request():
backend = eopayment.Payment('sips2', {})
@@ -31,3 +33,6 @@ def test_parse_response():
qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode='''
backend = eopayment.Payment('sips2', {})
assert backend.response(qs)
+
+ with pytest.raises(eopayment.ResponseError, match='missing Data, Seal or InterfaceVersion'):
+ backend.response('foo=bar')
diff --git a/tests/test_spplus.py b/tests/test_spplus.py
index a1a2058..ba047e9 100644
--- a/tests/test_spplus.py
+++ b/tests/test_spplus.py
@@ -1,5 +1,6 @@
from unittest import TestCase
import eopayment.spplus as spplus
+from eopayment import ResponseError
class SPPlustTest(TestCase):
ntkey = b'58 6d fc 9c 34 91 9b 86 3f ' \
@@ -14,3 +15,6 @@ class SPPlustTest(TestCase):
for query, result in self.tests:
self.assertEqual(spplus.sign_ntkey_query(self.ntkey, query).lower(), result)
+
+ with self.assertRaisesRegexp(ResponseError, 'missing reference, etat or refsfp'):
+ payment.response('foo=bar')
diff --git a/tests/test_systempayv2.py b/tests/test_systempayv2.py
index c558bbf..bf00b6d 100644
--- a/tests/test_systempayv2.py
+++ b/tests/test_systempayv2.py
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
+import pytest
from six.moves.urllib import parse as urlparse
from eopayment.systempayv2 import Payment, VADS_CUST_FIRST_NAME, \
VADS_CUST_LAST_NAME, PAID
+from eopayment import ResponseError
PARAMS = {
'secret_test': u'1122334455667788',
@@ -43,3 +45,7 @@ def test_systempayv2():
'&signature=62a4fb6738ebadebf9cc720164bc70e47282d36e'
response = p.response(response_qs)
assert response.result == PAID
+
+ # bad response
+ with pytest.raises(ResponseError, match='missing signature, vads_ctx_mode or vads_auth_result'):
+ p.response('foo=bar')
diff --git a/tests/test_tipi.py b/tests/test_tipi.py
index 2f8a665..f33bae5 100644
--- a/tests/test_tipi.py
+++ b/tests/test_tipi.py
@@ -1,6 +1,7 @@
from decimal import Decimal
from six.moves.urllib.parse import urlparse, parse_qs
import eopayment
+import pytest
def test_tipi():
p = eopayment.Payment('tipi', {'numcli': '12345'})
@@ -23,3 +24,6 @@ def test_tipi():
response = p.response('objet=tout+a+fait&montant=12312&saisie=T&mel=info%40entrouvert.com&numcli=12345&exer=9999&refdet=999900000000999999&resultrans=P')
assert response.signed # ...
assert response.result == eopayment.PAID
+
+ with pytest.raises(eopayment.ResponseError, match='missing refdet or resultrans'):
+ p.response('foo=bar')