Project

General

Profile

0001-implement-payzen-backend-by-inheriing-systempayv2-fi.patch

Serghei Mihai, 18 November 2015 06:57 PM

Download (4.29 KB)

View differences:

Subject: [PATCH] implement payzen backend by inheriing systempayv2 (fixes
 #8854)

 eopayment/__init__.py    |  3 ++-
 eopayment/payzen.py      | 10 ++++++++++
 eopayment/systempayv2.py | 16 ++++++++--------
 3 files changed, 20 insertions(+), 9 deletions(-)
 create mode 100644 eopayment/payzen.py
eopayment/__init__.py
15 15
DUMMY = 'dummy'
16 16
OGONE = 'ogone'
17 17
PAYBOX = 'paybox'
18
PAYZEN = 'payzen'
18 19

  
19 20

  
20 21
def get_backend(kind):
......
22 23
    module = __import__(kind, globals(), locals(), [])
23 24
    return module.Payment
24 25

  
25
__BACKENDS = [ DUMMY, SIPS, SYSTEMPAY, SPPLUS, OGONE, PAYBOX ]
26
__BACKENDS = [ DUMMY, SIPS, SYSTEMPAY, SPPLUS, OGONE, PAYBOX, PAYZEN ]
26 27

  
27 28
def get_backends():
28 29
    '''Return a dictionnary mapping existing eopayment backends name to their
eopayment/payzen.py
1
from . import systempayv2
2

  
3
__all__ = ['Payment']
4

  
5
class Payment(systempayv2.Payment):
6
    service_url = 'https://secure.payzen.eu/vads-payment/'
7

  
8
    description = systempayv2.Payment.description.copy()
9
    description['caption'] = 'PayZen'
10
    description['parameters'][0]['name'] = service_url
eopayment/systempayv2.py
12 12

  
13 13
__all__ = ['Payment']
14 14

  
15
SERVICE_URL = "https://paiement.systempay.fr/vads-payment/"
16
LOGGER = logging.getLogger(__name__)
17 15
VADS_TRANS_DATE = 'vads_trans_date'
18 16
VADS_AUTH_NUMBER = 'vads_auth_number'
19 17
VADS_AUTH_RESULT = 'vads_auth_result'
......
211 209
            'vads_return_mode': 'NONE'})
212 210

  
213 211
    '''
212
    service_url = "https://paiement.systempay.fr/vads-payment/"
213

  
214 214
    description = {
215 215
        'caption': 'SystemPay, système de paiment du groupe BPCE',
216 216
        'parameters': [
217 217
            {'name': 'service_url',
218
                'default': SERVICE_URL,
218
                'default': service_url,
219 219
                'caption': _(u'URL du service de paiment'),
220 220
                'help_text': _(u'ne pas modifier si vous ne savez pas'),
221 221
                'validation': lambda x: x.startswith('http'),
......
243 243
             'max_length': parameter.max_length}
244 244
        description['parameters'].append(x)
245 245

  
246
    def __init__(self, options, logger=LOGGER):
247
        self.service_url = options.pop('service_url', SERVICE_URL)
246
    def __init__(self, options, logger=None):
247
        self.service_url = options.pop('service_url', self.service_url)
248 248
        self.secret_test = options.pop('secret_test')
249 249
        self.secret_production = options.pop('secret_production', None)
250 250
        options = add_vads(options)
251 251
        self.options = options
252
        self.logger = logger
252
        self.logger = logger or logging.getLogger(__name__)
253 253

  
254 254
    def request(self, amount, name=None, address=None, email=None, phone=None,
255 255
                info1=None, info2=None, info3=None, next_url=None, **kwargs):
......
304 304
        transaction_id = '%s_%s' % (fields[VADS_TRANS_DATE], transaction_id)
305 305
        self.logger.debug('%s transaction id: %s', __name__, transaction_id)
306 306
        form = Form(
307
                url=SERVICE_URL,
307
                url=self.service_url,
308 308
                method='POST',
309 309
                fields=[{'type': 'hidden',
310 310
                        'name': name,
......
379 379
        secret = getattr(self, 'secret_%s' % fields['vads_ctx_mode'].lower())
380 380
        signed_data = '+'.join(ordered_fields)
381 381
        signed_data = '%s+%s' % (signed_data, secret)
382
        self.logger.debug('generating signature on «%s»' % signed_data)
382
        self.logger.debug(u'generating signature on «%s»' % signed_data)
383 383
        sign = hashlib.sha1(signed_data).hexdigest()
384 384
        self.logger.debug('signature «%s»' % sign)
385 385
        return sign
386
-