Projet

Général

Profil

0002-tipi-payfip_ws-remove-URL-backend-parameters-46688.patch

Benjamin Dauvergne, 04 juin 2021 13:01

Télécharger (5,49 ko)

Voir les différences:

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(-)
eopayment/payfip_ws.py
38 38
                     CANCELLED, ERROR, ResponseError, PaymentException,
39 39
                     WAITING, EXPIRED, force_text, _)
40 40

  
41
# The URL of the WSDL published in the documentation is still wrong, it
42
# references XSD files which are not resolvable :/ we must use this other URL
43
# where the XSD files are resolvable. To not depend too much on those files, we
44
# provide copy in eopayment and we patch them to fix the service binding URL
45
# and the path of XSD files.  The PayFiP development team is full of morons.
41 46
WSDL_URL = 'https://www.payfip.gouv.fr/tpa/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService?wsdl'  # noqa: E501
42

  
43 47
SERVICE_URL = 'https://www.payfip.gouv.fr/tpa/services/securite'  # noqa: E501
44

  
45 48
PAYMENT_URL = 'https://www.payfip.gouv.fr/tpa/paiementws.web'
46 49

  
47 50
REFDET_RE = re.compile(r'^[A-Za-z0-9]{1,30}$')
......
86 89
class PayFiP(object):
87 90
    '''Encapsulate SOAP web-services of PayFiP'''
88 91

  
89
    def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None):
92
    def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None, use_local_wsdl=True):
93
        # use cached WSDL
94
        if (not wsdl_url or (wsdl_url == WSDL_URL)) and use_local_wsdl:
95
            base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl')
96
            wsdl_url = 'file://%s' % base_path
90 97
        self.wsdl_url = wsdl_url
91 98
        self.service_url = service_url
92 99
        self.zeep_client_kwargs = zeep_client_kwargs
......
169 176
                'validation': lambda s: str.isdigit(s) and len(s) == 6,
170 177
                'required': True,
171 178
            },
172
            {
173
                'name': 'service_url',
174
                'default': SERVICE_URL,
175
                'caption': _(u'PayFIP WS service URL'),
176
                'help_text': _(u'do not modify if you do not know'),
177
                'validation': lambda x: x.startswith('http'),
178
            },
179
            {
180
                'name': 'wsdl_url',
181
                'default': WSDL_URL,
182
                'caption': _(u'PayFIP WS WSDL URL'),
183
                'help_text': _(u'do not modify if you do not know'),
184
                'validation': lambda x: x.startswith('http'),
185
            },
186
            {
187
                'name': 'payment_url',
188
                'default': PAYMENT_URL,
189
                'caption': _(u'PayFiP payment URL'),
190
                'help_text': _(u'do not modify if you do not know'),
191
                'validation': lambda x: x.startswith('http'),
192
            },
193 179
            {
194 180
                'name': 'saisie',
195 181
                'caption': _('Payment type'),
......
217 203

  
218 204
    def __init__(self, *args, **kwargs):
219 205
        super(Payment, self).__init__(*args, **kwargs)
220
        wsdl_url = self.wsdl_url
221
        # use cached WSDL
222
        if wsdl_url == WSDL_URL:
223
            base_path = os.path.join(os.path.dirname(__file__), 'resource', 'PaiementSecuriseService.wsdl')
224
            wsdl_url = 'file://%s' % base_path
225
        self.payfip = PayFiP(wsdl_url=wsdl_url, service_url=self.service_url)
206
        self.payfip = PayFiP()
226 207

  
227 208
    def _generate_refdet(self):
228 209
        return '%s%010d' % (isonow(), random.randint(1, 1000000000))
......
280 261
                                    url_notification=urlnotif,
281 262
                                    url_redirect=urlredirect)
282 263

  
283
        return str(idop), URL, self.payment_url + '?idop=%s' % idop
264
        return str(idop), URL, PAYMENT_URL + '?idop=%s' % idop
284 265

  
285 266
    def payment_status(self, transaction_id, transaction_date=None, **kwargs):
286 267
        # idop are valid for 15 minutes after their generation
eopayment/tipi.py
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)'),
......
157 149
            params['objet'] = objet
158 150
        if automatic_return_url:
159 151
            params['urlcl'] = automatic_return_url
160
        url = '%s?%s' % (self.service_url, urlencode(params))
152
        url = '%s?%s' % (TIPI_URL, urlencode(params))
161 153
        return transaction_id, URL, url
162 154

  
163 155
    def response(self, query_string, **kwargs):
164
-