From c9174c008f91ef29b50d07f46c02953b216fe012 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 30 Apr 2021 11:20:33 +0200 Subject: [PATCH] payfip_ws: initialize PayFiP SOAP client lazily and encapsulate internal exceptions (#53590) --- eopayment/payfip_ws.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/eopayment/payfip_ws.py b/eopayment/payfip_ws.py index a7754bd..4d2b72b 100644 --- a/eopayment/payfip_ws.py +++ b/eopayment/payfip_ws.py @@ -87,9 +87,20 @@ class PayFiP(object): '''Encapsulate SOAP web-services of PayFiP''' def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None): - 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 + self.wsdl_url = wsdl_url + self.service_url = service_url + self.zeep_client_kwargs = zeep_client_kwargs + + @property + def client(self): + if not hasattr(self, '_client'): + try: + self._client = zeep.Client(self.wsdl_url or WSDL_URL, **(self.zeep_client_kwargs or {})) + # distribued WSDL is wrong :/ + self._client.service._binding_options['address'] = self.service_url or SERVICE_URL + except Exception as e: + raise PayFiPError('Cound not initialize the SOAP client', e) + return self._client def fault_to_exception(self, fault): if fault.message != 'fr.gouv.finances.cp.tpa.webservice.exceptions.FonctionnelleErreur' or fault.detail is None: