From a1c863594c6f5718335a5001949ba2021fc7cd5f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 10 Oct 2020 13:40:11 +0200 Subject: [PATCH] tipi/payfip_ws: replace www.tipi.budget.gouv.fr by www.payfip.gouv.fr (#46688) --- eopayment/payfip_ws.py | 51 ++++++++++++----------------------------- eopayment/tipi.py | 12 ++-------- tests/test_payfip_ws.py | 9 ++++---- tests/test_tipi.py | 4 ++-- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/eopayment/payfip_ws.py b/eopayment/payfip_ws.py index 843ba5b..581aa1f 100644 --- a/eopayment/payfip_ws.py +++ b/eopayment/payfip_ws.py @@ -18,7 +18,6 @@ from __future__ import print_function, unicode_literals import copy import datetime -from decimal import Decimal, ROUND_DOWN import functools import os import random @@ -36,11 +35,14 @@ from .systempayv2 import isonow from .common import (PaymentCommon, PaymentResponse, URL, PAID, DENIED, CANCELLED, ERROR, ResponseError, PaymentException) -WSDL_URL = 'https://www.tipi.budget.gouv.fr/tpa/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService?wsdl' # noqa: E501 - -SERVICE_URL = 'https://www.tipi.budget.gouv.fr/tpa/services/securite' # noqa: E501 - -PAYMENT_URL = 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web' +# The URL of the WSDL published in the document is still wrong, it references XSD files which are not resolvable :/ +# we must use this other URL where the XSD files are resolvable. To not depend +# too much on those files, we provide copy in eopayment and we patch them to +# fix the service binding URL and the path of XSD files. +# The PayFiP development team is full of morons. +WSDL_URL = 'https://www.payfip.gouv.fr/tpa/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService?wsdl' +SERVICE_URL = 'https://www.payfip.gouv.fr/tpa/services/securite' +PAYMENT_URL = 'https://www.payfip.gouv.fr/tpa/paiementws.web' def clear_namespace(element): @@ -68,8 +70,11 @@ class PayFiPError(PaymentException): class PayFiP(object): '''Encapsulate SOAP web-services of PayFiP''' - - def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None): + def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None, use_local_wsdl=True): + # use cached WSDL + if (not wsdl_url or (wsdl_url == WSDL_URL)) and use_local_wsdl: + base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl') + wsdl_url = 'file://%s' % base_path self.client = zeep.Client(wsdl_url or WSDL_URL, **(zeep_client_kwargs or {})) # distribued WSDL is wrong :/ self.client.service._binding_options['address'] = service_url or SERVICE_URL @@ -141,27 +146,6 @@ class Payment(PaymentCommon): 'validation': lambda s: str.isdigit(s) and len(s) == 6, 'required': True, }, - { - 'name': 'service_url', - 'default': SERVICE_URL, - 'caption': _(u'PayFIP WS service URL'), - 'help_text': _(u'do not modify if you do not know'), - 'validation': lambda x: x.startswith('http'), - }, - { - 'name': 'wsdl_url', - 'default': WSDL_URL, - 'caption': _(u'PayFIP WS WSDL URL'), - 'help_text': _(u'do not modify if you do not know'), - 'validation': lambda x: x.startswith('http'), - }, - { - 'name': 'payment_url', - 'default': PAYMENT_URL, - 'caption': _(u'PayFiP payment URL'), - 'help_text': _(u'do not modify if you do not know'), - 'validation': lambda x: x.startswith('http'), - }, { 'name': 'saisie', 'caption': _('Payment type'), @@ -187,12 +171,7 @@ class Payment(PaymentCommon): def __init__(self, *args, **kwargs): super(Payment, self).__init__(*args, **kwargs) - wsdl_url = self.wsdl_url - # use cached WSDL - if wsdl_url == WSDL_URL: - base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl') - wsdl_url = 'file://%s' % base_path - self.payfip = PayFiP(wsdl_url=wsdl_url, service_url=self.service_url) + self.payfip = PayFiP() def _generate_refdet(self): return '%s%010d' % (isonow(), random.randint(1, 1000000000)) @@ -227,7 +206,7 @@ class Payment(PaymentCommon): url_notification=urlnotif, url_redirect=urlredirect) - return str(idop), URL, self.payment_url + '?idop=%s' % idop + return str(idop), URL, PAYMENT_URL + '?idop=%s' % idop def response(self, query_string, **kwargs): fields = parse_qs(query_string, True) diff --git a/eopayment/tipi.py b/eopayment/tipi.py index d76afe4..7b7d4b3 100644 --- a/eopayment/tipi.py +++ b/eopayment/tipi.py @@ -29,7 +29,7 @@ from .systempayv2 import isonow __all__ = ['Payment'] -TIPI_URL = 'https://www.tipi.budget.gouv.fr/tpa/paiement.web' +PAYFIP_URL = 'https://www.payfip.gouv.fr/tpa/paiement.web' LOGGER = logging.getLogger(__name__) @@ -49,14 +49,6 @@ class Payment(PaymentCommon): 'validation': lambda s: str.isdigit(s) and (0 < int(s) < 1000000), 'required': True, }, - { - 'name': 'service_url', - 'default': TIPI_URL, - 'caption': _(u'TIPI service URL'), - 'help_text': _(u'do not modify if you do not know'), - 'validation': lambda x: x.startswith('http'), - 'required': True, - }, { 'name': 'normal_return_url', 'caption': _('Normal return URL (unused by TIPI)'), @@ -156,7 +148,7 @@ class Payment(PaymentCommon): params['objet'] = objet if automatic_return_url: params['urlcl'] = automatic_return_url - url = '%s?%s' % (self.service_url, urlencode(params)) + url = '%s?%s' % (PAYFIP_URL, urlencode(params)) return transaction_id, URL, url def response(self, query_string, **kwargs): diff --git a/tests/test_payfip_ws.py b/tests/test_payfip_ws.py index d6909de..106b22b 100644 --- a/tests/test_payfip_ws.py +++ b/tests/test_payfip_ws.py @@ -70,8 +70,7 @@ def payfip(request): raise RequestException('huhu') with httmock.HTTMock(raise_on_request): - payfip = PayFiP(wsdl_url='file://eopayment/resource/PaiementSecuriseService.wsdl', - zeep_client_kwargs={'plugins': [history]}) + payfip = PayFiP(zeep_client_kwargs={'plugins': [history]}) try: if 'update_data' not in request.keywords: with httmock.HTTMock(PayFiPHTTMock(request).mock): @@ -191,7 +190,7 @@ def test_payment_ok(request): assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' assert kind == eopayment.URL - assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' + assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' response = payment.response('idop=%s' % payment_id) assert response.result == eopayment.PAID @@ -217,7 +216,7 @@ def test_payment_denied(request): assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' assert kind == eopayment.URL - assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' + assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' response = payment.response('idop=%s' % payment_id) assert response.result == eopayment.DENIED @@ -242,7 +241,7 @@ def test_payment_cancelled(request): assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103' assert kind == eopayment.URL - assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' + assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' response = payment.response('idop=%s' % payment_id) assert response.result == eopayment.CANCELLED diff --git a/tests/test_tipi.py b/tests/test_tipi.py index 3f525fa..f0b9e5a 100644 --- a/tests/test_tipi.py +++ b/tests/test_tipi.py @@ -80,7 +80,7 @@ def test_tipi_orderid_refdef_compatible(): email='info@entrouvert.com', orderid='F121212') assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) - expected_url = urlparse(eopayment.tipi.TIPI_URL) + expected_url = urlparse(eopayment.tipi.PAYFIP_URL) parsed_url = urlparse(url) assert parsed_url[:3] == expected_url[:3] parsed_qs = parse_qs(parsed_url.query) @@ -101,7 +101,7 @@ def test_tipi_orderid_not_refdef_compatible(): objet='coucou', orderid='F12-12-12') assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None - expected_url = urlparse(eopayment.tipi.TIPI_URL) + expected_url = urlparse(eopayment.tipi.PAYFIP_URL) parsed_url = urlparse(url) assert parsed_url[:3] == expected_url[:3] parsed_qs = parse_qs(parsed_url.query) -- 2.28.0