0001-tipi-payfip_ws-replace-www.tipi.budget.gouv.fr-by-ww.patch
eopayment/payfip_ws.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
import copy |
20 | 20 |
import datetime |
21 |
from decimal import Decimal, ROUND_DOWN |
|
22 | 21 |
import functools |
23 | 22 |
import os |
24 | 23 |
import random |
... | ... | |
36 | 35 |
from .common import (PaymentCommon, PaymentResponse, URL, PAID, DENIED, |
37 | 36 |
CANCELLED, ERROR, ResponseError, PaymentException) |
38 | 37 | |
39 |
WSDL_URL = 'https://www.tipi.budget.gouv.fr/tpa/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService?wsdl' # noqa: E501 |
|
40 | ||
41 |
SERVICE_URL = 'https://www.tipi.budget.gouv.fr/tpa/services/securite' # noqa: E501 |
|
42 | ||
43 |
PAYMENT_URL = 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web' |
|
38 |
# The URL of the WSDL published in the document is still wrong, it references XSD files which are not resolvable :/ |
|
39 |
# we must use this other URL where the XSD files are resolvable. To not depend |
|
40 |
# too much on those files, we provide copy in eopayment and we patch them to |
|
41 |
# fix the service binding URL and the path of XSD files. |
|
42 |
# The PayFiP development team is full of morons. |
|
43 |
WSDL_URL = 'https://www.payfip.gouv.fr/tpa/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService?wsdl' |
|
44 |
SERVICE_URL = 'https://www.payfip.gouv.fr/tpa/services/securite' |
|
45 |
PAYMENT_URL = 'https://www.payfip.gouv.fr/tpa/paiementws.web' |
|
44 | 46 | |
45 | 47 | |
46 | 48 |
def clear_namespace(element): |
... | ... | |
68 | 70 | |
69 | 71 |
class PayFiP(object): |
70 | 72 |
'''Encapsulate SOAP web-services of PayFiP''' |
71 | ||
72 |
def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None): |
|
73 |
def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None, use_local_wsdl=True): |
|
74 |
# use cached WSDL |
|
75 |
if (not wsdl_url or (wsdl_url == WSDL_URL)) and use_local_wsdl: |
|
76 |
base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl') |
|
77 |
wsdl_url = 'file://%s' % base_path |
|
73 | 78 |
self.client = zeep.Client(wsdl_url or WSDL_URL, **(zeep_client_kwargs or {})) |
74 | 79 |
# distribued WSDL is wrong :/ |
75 | 80 |
self.client.service._binding_options['address'] = service_url or SERVICE_URL |
... | ... | |
141 | 146 |
'validation': lambda s: str.isdigit(s) and len(s) == 6, |
142 | 147 |
'required': True, |
143 | 148 |
}, |
144 |
{ |
|
145 |
'name': 'service_url', |
|
146 |
'default': SERVICE_URL, |
|
147 |
'caption': _(u'PayFIP WS service URL'), |
|
148 |
'help_text': _(u'do not modify if you do not know'), |
|
149 |
'validation': lambda x: x.startswith('http'), |
|
150 |
}, |
|
151 |
{ |
|
152 |
'name': 'wsdl_url', |
|
153 |
'default': WSDL_URL, |
|
154 |
'caption': _(u'PayFIP WS WSDL URL'), |
|
155 |
'help_text': _(u'do not modify if you do not know'), |
|
156 |
'validation': lambda x: x.startswith('http'), |
|
157 |
}, |
|
158 |
{ |
|
159 |
'name': 'payment_url', |
|
160 |
'default': PAYMENT_URL, |
|
161 |
'caption': _(u'PayFiP payment URL'), |
|
162 |
'help_text': _(u'do not modify if you do not know'), |
|
163 |
'validation': lambda x: x.startswith('http'), |
|
164 |
}, |
|
165 | 149 |
{ |
166 | 150 |
'name': 'saisie', |
167 | 151 |
'caption': _('Payment type'), |
... | ... | |
187 | 171 | |
188 | 172 |
def __init__(self, *args, **kwargs): |
189 | 173 |
super(Payment, self).__init__(*args, **kwargs) |
190 |
wsdl_url = self.wsdl_url |
|
191 |
# use cached WSDL |
|
192 |
if wsdl_url == WSDL_URL: |
|
193 |
base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl') |
|
194 |
wsdl_url = 'file://%s' % base_path |
|
195 |
self.payfip = PayFiP(wsdl_url=wsdl_url, service_url=self.service_url) |
|
174 |
self.payfip = PayFiP() |
|
196 | 175 | |
197 | 176 |
def _generate_refdet(self): |
198 | 177 |
return '%s%010d' % (isonow(), random.randint(1, 1000000000)) |
... | ... | |
227 | 206 |
url_notification=urlnotif, |
228 | 207 |
url_redirect=urlredirect) |
229 | 208 | |
230 |
return str(idop), URL, self.payment_url + '?idop=%s' % idop
|
|
209 |
return str(idop), URL, PAYMENT_URL + '?idop=%s' % idop
|
|
231 | 210 | |
232 | 211 |
def response(self, query_string, **kwargs): |
233 | 212 |
fields = parse_qs(query_string, True) |
eopayment/tipi.py | ||
---|---|---|
29 | 29 | |
30 | 30 |
__all__ = ['Payment'] |
31 | 31 | |
32 |
TIPI_URL = 'https://www.tipi.budget.gouv.fr/tpa/paiement.web'
|
|
32 |
PAYFIP_URL = 'https://www.payfip.gouv.fr/tpa/paiement.web'
|
|
33 | 33 |
LOGGER = logging.getLogger(__name__) |
34 | 34 | |
35 | 35 | |
... | ... | |
49 | 49 |
'validation': lambda s: str.isdigit(s) and (0 < int(s) < 1000000), |
50 | 50 |
'required': True, |
51 | 51 |
}, |
52 |
{ |
|
53 |
'name': 'service_url', |
|
54 |
'default': TIPI_URL, |
|
55 |
'caption': _(u'TIPI service URL'), |
|
56 |
'help_text': _(u'do not modify if you do not know'), |
|
57 |
'validation': lambda x: x.startswith('http'), |
|
58 |
'required': True, |
|
59 |
}, |
|
60 | 52 |
{ |
61 | 53 |
'name': 'normal_return_url', |
62 | 54 |
'caption': _('Normal return URL (unused by TIPI)'), |
... | ... | |
156 | 148 |
params['objet'] = objet |
157 | 149 |
if automatic_return_url: |
158 | 150 |
params['urlcl'] = automatic_return_url |
159 |
url = '%s?%s' % (self.service_url, urlencode(params))
|
|
151 |
url = '%s?%s' % (PAYFIP_URL, urlencode(params))
|
|
160 | 152 |
return transaction_id, URL, url |
161 | 153 | |
162 | 154 |
def response(self, query_string, **kwargs): |
tests/test_payfip_ws.py | ||
---|---|---|
70 | 70 |
raise RequestException('huhu') |
71 | 71 | |
72 | 72 |
with httmock.HTTMock(raise_on_request): |
73 |
payfip = PayFiP(wsdl_url='file://eopayment/resource/PaiementSecuriseService.wsdl', |
|
74 |
zeep_client_kwargs={'plugins': [history]}) |
|
73 |
payfip = PayFiP(zeep_client_kwargs={'plugins': [history]}) |
|
75 | 74 |
try: |
76 | 75 |
if 'update_data' not in request.keywords: |
77 | 76 |
with httmock.HTTMock(PayFiPHTTMock(request).mock): |
... | ... | |
191 | 190 | |
192 | 191 |
assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' |
193 | 192 |
assert kind == eopayment.URL |
194 |
assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
193 |
assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
195 | 194 | |
196 | 195 |
response = payment.response('idop=%s' % payment_id) |
197 | 196 |
assert response.result == eopayment.PAID |
... | ... | |
217 | 216 | |
218 | 217 |
assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' |
219 | 218 |
assert kind == eopayment.URL |
220 |
assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
219 |
assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
221 | 220 | |
222 | 221 |
response = payment.response('idop=%s' % payment_id) |
223 | 222 |
assert response.result == eopayment.DENIED |
... | ... | |
242 | 241 | |
243 | 242 |
assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' |
244 | 243 |
assert kind == eopayment.URL |
245 |
assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
244 |
assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
|
|
246 | 245 | |
247 | 246 |
response = payment.response('idop=%s' % payment_id) |
248 | 247 |
assert response.result == eopayment.CANCELLED |
tests/test_tipi.py | ||
---|---|---|
80 | 80 |
email='info@entrouvert.com', |
81 | 81 |
orderid='F121212') |
82 | 82 |
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) |
83 |
expected_url = urlparse(eopayment.tipi.TIPI_URL)
|
|
83 |
expected_url = urlparse(eopayment.tipi.PAYFIP_URL)
|
|
84 | 84 |
parsed_url = urlparse(url) |
85 | 85 |
assert parsed_url[:3] == expected_url[:3] |
86 | 86 |
parsed_qs = parse_qs(parsed_url.query) |
... | ... | |
101 | 101 |
objet='coucou', |
102 | 102 |
orderid='F12-12-12') |
103 | 103 |
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None |
104 |
expected_url = urlparse(eopayment.tipi.TIPI_URL)
|
|
104 |
expected_url = urlparse(eopayment.tipi.PAYFIP_URL)
|
|
105 | 105 |
parsed_url = urlparse(url) |
106 | 106 |
assert parsed_url[:3] == expected_url[:3] |
107 | 107 |
parsed_qs = parse_qs(parsed_url.query) |
108 |
- |