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: