0001-general-check-responses-for-required-attributes-as-1.patch
eopayment/__init__.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
from common import URL, HTML, FORM, RECEIVED, ACCEPTED, PAID, DENIED, CANCELED, CANCELLED, ERROR |
|
3 |
from common import (URL, HTML, FORM, RECEIVED, ACCEPTED, PAID, DENIED, |
|
4 |
CANCELED, CANCELLED, ERROR, ResponseError) |
|
4 | 5 | |
5 | 6 |
__all__ = ['Payment', 'URL', 'HTML', 'FORM', 'SIPS', |
6 | 7 |
'SYSTEMPAY', 'SPPLUS', 'TIPI', 'DUMMY', 'get_backend', 'RECEIVED', 'ACCEPTED', |
eopayment/common.py | ||
---|---|---|
27 | 27 |
ORDERID_TRANSACTION_SEPARATOR = '!' |
28 | 28 | |
29 | 29 | |
30 |
class ResponseError(Exception): |
|
31 |
pass |
|
32 | ||
33 | ||
30 | 34 |
class PaymentResponse(object): |
31 | 35 |
'''Holds a generic view on the result of payment transaction response. |
32 | 36 |
eopayment/dummy.py | ||
---|---|---|
10 | 10 |
except ImportError: |
11 | 11 |
from urlparse import parse_qs |
12 | 12 | |
13 |
from common import PaymentCommon, URL, PaymentResponse, PAID, ERROR |
|
13 |
from common import PaymentCommon, URL, PaymentResponse, PAID, ERROR, ResponseError
|
|
14 | 14 | |
15 | 15 |
__all__ = [ 'Payment' ] |
16 | 16 | |
... | ... | |
122 | 122 | |
123 | 123 |
def response(self, query_string, logger=LOGGER, **kwargs): |
124 | 124 |
form = parse_qs(query_string) |
125 |
if not 'transaction_id' in form: |
|
126 |
raise ResponseError() |
|
125 | 127 |
transaction_id = form.get('transaction_id',[''])[0] |
126 | 128 |
form[self.BANK_ID] = transaction_id |
127 | 129 |
eopayment/ogone.py | ||
---|---|---|
5 | 5 |
from decimal import Decimal, ROUND_HALF_UP |
6 | 6 | |
7 | 7 |
from common import (PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID, |
8 |
ERROR, Form, DENIED, ACCEPTED, ORDERID_TRANSACTION_SEPARATOR) |
|
8 |
ERROR, Form, DENIED, ACCEPTED, ORDERID_TRANSACTION_SEPARATOR, |
|
9 |
ResponseError) |
|
9 | 10 |
def N_(message): return message |
10 | 11 | |
11 | 12 |
ENVIRONMENT_TEST = 'TEST' |
... | ... | |
528 | 529 |
def response(self, query_string, **kwargs): |
529 | 530 |
params = urlparse.parse_qs(query_string, True) |
530 | 531 |
params = dict((key.upper(), params[key][0]) for key in params) |
532 |
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']): |
|
533 |
raise ResponseError() |
|
531 | 534 |
reference = params['ORDERID'] |
532 | 535 |
transaction_id = params['PAYID'] |
533 | 536 |
status = params['STATUS'] |
eopayment/paybox.py | ||
---|---|---|
17 | 17 |
import warnings |
18 | 18 | |
19 | 19 |
from common import (PaymentCommon, PaymentResponse, FORM, PAID, ERROR, Form, |
20 |
ORDERID_TRANSACTION_SEPARATOR) |
|
20 |
ORDERID_TRANSACTION_SEPARATOR, ResponseError)
|
|
21 | 21 | |
22 | 22 |
__all__ = ['sign', 'Payment'] |
23 | 23 | |
... | ... | |
253 | 253 | |
254 | 254 |
def response(self, query_string, callback=False, **kwargs): |
255 | 255 |
d = urlparse.parse_qs(query_string, True, False) |
256 |
if not set(d) >= set(['erreur', 'reference']): |
|
257 |
raise ResponseError() |
|
256 | 258 |
signed = False |
257 | 259 |
if 'signature' in d: |
258 | 260 |
sig = d['signature'][0] |
eopayment/sips.py | ||
---|---|---|
9 | 9 |
import uuid |
10 | 10 |
import warnings |
11 | 11 | |
12 |
from common import PaymentCommon, HTML, PaymentResponse |
|
12 |
from common import PaymentCommon, HTML, PaymentResponse, ResponseError
|
|
13 | 13 |
from cb import CB_RESPONSE_CODES |
14 | 14 | |
15 | 15 |
''' |
... | ... | |
159 | 159 | |
160 | 160 |
def response(self, query_string, **kwargs): |
161 | 161 |
form = urlparse.parse_qs(query_string) |
162 |
if not DATA in form: |
|
163 |
raise ResponseError() |
|
162 | 164 |
params = {'message': form[DATA][0]} |
163 | 165 |
result = self.execute('response', params) |
164 | 166 |
d = dict(zip(RESPONSE_PARAMS, result)) |
eopayment/sips2.py | ||
---|---|---|
8 | 8 |
from gettext import gettext as _ |
9 | 9 |
import warnings |
10 | 10 | |
11 |
from common import PaymentCommon, FORM, Form, PaymentResponse, PAID, ERROR, CANCELED |
|
11 |
from common import (PaymentCommon, FORM, Form, PaymentResponse, PAID, ERROR, |
|
12 |
CANCELED, ResponseError) |
|
12 | 13 | |
13 | 14 |
__all__ = ['Payment'] |
14 | 15 | |
... | ... | |
190 | 191 | |
191 | 192 |
def response(self, query_string, **kwargs): |
192 | 193 |
form = urlparse.parse_qs(query_string) |
194 |
if not set(form) >= set(['Data', 'Seal', 'InterfaceVersion']): |
|
195 |
raise ResponseError() |
|
193 | 196 |
self.logger.debug('received query string %r', form) |
194 |
assert 'Data' in form |
|
195 |
assert 'Seal' in form |
|
196 |
assert 'InterfaceVersion' in form |
|
197 | 197 |
data = self.decode_data(form['Data'][0]) |
198 | 198 |
seal = form['Seal'][0] |
199 | 199 |
self.logger.debug('parsed response %r seal %r', data, seal) |
eopayment/spplus.py | ||
---|---|---|
14 | 14 | |
15 | 15 |
import Crypto.Cipher.DES |
16 | 16 |
from common import (PaymentCommon, URL, PaymentResponse, RECEIVED, ACCEPTED, |
17 |
PAID, ERROR) |
|
17 |
PAID, ERROR, ResponseError)
|
|
18 | 18 | |
19 | 19 |
def N_(message): return message |
20 | 20 | |
... | ... | |
176 | 176 | |
177 | 177 |
def response(self, query_string, logger=LOGGER, **kwargs): |
178 | 178 |
form = urlparse.parse_qs(query_string) |
179 |
if not set(form) >= set([REFERENCE, ETAT, REFSFP]): |
|
180 |
raise ResponseError() |
|
179 | 181 |
for key, value in form.iteritems(): |
180 | 182 |
form[key] = value[0] |
181 | 183 |
logger.debug('received query_string %s' % query_string) |
eopayment/systempayv2.py | ||
---|---|---|
8 | 8 |
import warnings |
9 | 9 |
from gettext import gettext as _ |
10 | 10 | |
11 |
from common import PaymentCommon, PaymentResponse, PAID, ERROR, FORM, Form |
|
11 |
from common import (PaymentCommon, PaymentResponse, PAID, ERROR, FORM, Form, |
|
12 |
ResponseError) |
|
12 | 13 |
from cb import CB_RESPONSE_CODES |
13 | 14 | |
14 | 15 |
__all__ = ['Payment'] |
... | ... | |
338 | 339 | |
339 | 340 |
def response(self, query_string, **kwargs): |
340 | 341 |
fields = urlparse.parse_qs(query_string, True) |
342 |
if not set(fields) >= set([SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT]): |
|
343 |
raise ResponseError() |
|
341 | 344 |
for key, value in fields.iteritems(): |
342 | 345 |
fields[key] = value[0] |
343 | 346 |
copy = fields.copy() |
eopayment/tipi.py | ||
---|---|---|
2 | 2 | |
3 | 3 |
from decimal import Decimal, ROUND_DOWN |
4 | 4 |
from common import (PaymentCommon, PaymentResponse, URL, PAID, DENIED, |
5 |
CANCELLED, ERROR) |
|
5 |
CANCELLED, ERROR, ResponseError)
|
|
6 | 6 |
from urllib import urlencode |
7 | 7 |
from urlparse import parse_qs |
8 | 8 |
from gettext import gettext as _ |
... | ... | |
136 | 136 | |
137 | 137 |
def response(self, query_string, **kwargs): |
138 | 138 |
fields = parse_qs(query_string, True) |
139 |
if not set(fields) >= set(['refdet', 'resultrans']): |
|
140 |
raise ResponseError() |
|
139 | 141 |
for key, value in fields.iteritems(): |
140 | 142 |
fields[key] = value[0] |
141 | 143 |
refdet = fields.get('refdet') |
tests/test_ogone.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
import eopayment |
5 | 5 |
import eopayment.ogone as ogone |
6 |
from eopayment import ResponseError |
|
6 | 7 | |
7 | 8 |
PSPID = '2352566' |
8 | 9 | |
... | ... | |
52 | 53 |
'payid': '32100123', 'status': 9, 'ncerror': 0} |
53 | 54 |
response = ogone_backend.response(urllib.urlencode(data)) |
54 | 55 |
self.assertEqual(response.order_id, order_id) |
56 | ||
57 |
def test_bad_response(self): |
|
58 |
ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) |
|
59 |
order_id = 'myorder' |
|
60 |
data = {'payid': '32100123', 'status': 9, 'ncerror': 0} |
|
61 |
with self.assertRaises(ResponseError): |
|
62 |
response = ogone_backend.response(urllib.urlencode(data)) |
|
55 |
- |