From 4af6d1d2fb65382704161b96c9023231ed7f5036 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 4 Jun 2021 12:54:24 +0200 Subject: [PATCH 2/2] tipi/payfip_ws: remove URL backend parameters (#46688) --- eopayment/payfip_ws.py | 43 ++++++++++++------------------------------ eopayment/tipi.py | 10 +--------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/eopayment/payfip_ws.py b/eopayment/payfip_ws.py index 984e7dc..1503462 100644 --- a/eopayment/payfip_ws.py +++ b/eopayment/payfip_ws.py @@ -38,10 +38,13 @@ from .common import (PaymentCommon, PaymentResponse, URL, PAID, DENIED, CANCELLED, ERROR, ResponseError, PaymentException, WAITING, EXPIRED, force_text, _) +# The URL of the WSDL published in the documentation 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' # noqa: E501 - SERVICE_URL = 'https://www.payfip.gouv.fr/tpa/services/securite' # noqa: E501 - PAYMENT_URL = 'https://www.payfip.gouv.fr/tpa/paiementws.web' REFDET_RE = re.compile(r'^[A-Za-z0-9]{1,30}$') @@ -86,7 +89,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.wsdl_url = wsdl_url self.service_url = service_url self.zeep_client_kwargs = zeep_client_kwargs @@ -169,27 +176,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'), @@ -217,12 +203,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)) @@ -280,7 +261,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 payment_status(self, transaction_id, transaction_date=None, **kwargs): # idop are valid for 15 minutes after their generation diff --git a/eopayment/tipi.py b/eopayment/tipi.py index c78010c..c734db2 100644 --- a/eopayment/tipi.py +++ b/eopayment/tipi.py @@ -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)'), @@ -157,7 +149,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' % (TIPI_URL, urlencode(params)) return transaction_id, URL, url def response(self, query_string, **kwargs): -- 2.32.0.rc0