diff --git a/eopayment/common.py b/eopayment/common.py index 5c65d5a..6c8afa9 100644 --- a/eopayment/common.py +++ b/eopayment/common.py @@ -1,11 +1,13 @@ import os.path import os import random +import logging from datetime import date __all__ = [ 'PaymentCommon', 'URL', 'HTML', 'RANDOM' ] +LOGGER = logging.getLogger(__name__) RANDOM = random.SystemRandom() URL = 1 @@ -14,6 +16,14 @@ HTML = 2 class PaymentCommon(object): PATH = '/tmp' + def __init__(self, options): + LOGGER.debug('initializing with options %s' % options) + for key, value in self.description['parameters'].iteritems(): + if 'default' in value: + setattr(self, key, options.get(key, value['default'])) + else: + setattr(self, key, options.get(key)) + def transaction_id(self, length, choices, *prefixes): while True: parts = [RANDOM.choice(choices) for x in range(length)] diff --git a/eopayment/dummy.py b/eopayment/dummy.py index 966835f..3c0b6b4 100644 --- a/eopayment/dummy.py +++ b/eopayment/dummy.py @@ -20,10 +20,25 @@ class Payment(PaymentCommon): you can find on: http://dummy-payment.demo.entrouvert.com/ + + You must pass the following keys inside the options dictionnary: + - dummy_service_url, the URL of the dummy payment service, it defaults + to the one operated by Entr'ouvert. + - direct_notification_url: where to POST to notify the service of a + payment + - origin: a human string to display to the user about the origin of + the request. + - siret: an identifier for the eCommerce site, fake. + - next_url: the return URL for the user (can be overriden on a per + request basis). ''' description = { 'caption': 'Dummy payment backend', 'parameters': { + 'dummy_service_url': { + 'caption': 'URL of the dummy payment service', + 'default': SERVICE_URL, + }, 'direct_notification_url': { 'caption': 'direct notification url', }, @@ -40,20 +55,6 @@ class Payment(PaymentCommon): } } - def __init__(self, options): - ''' - You must pass the following keys inside the options dictionnary: - - direct_notification_url: where to POST to notify the service of a - payment - - siret: an identifier for the eCommerce site - - origin: a human string to display to the user about the origin of - the request. - ''' - self.direct_notification_url = options['direct_notification_url'] - self.siret = options['siret'] - self.origin = options['origin'] - self.next_url = options.get('next_url','') - def request(self, montant, email=None, next_url=None): transaction_id = self.transaction_id(30, ALPHANUM, 'dummy', self.siret) if self.next_url: @@ -87,7 +88,6 @@ if __name__ == '__main__': 'origin': 'Mairie de Perpette-les-oies' } p = Payment(options) - print p.request(10.00, email='toto@example.com', next_url='http://example.com/retour') retour = 'http://example.com/retour?amount=10.0&direct_notification_url=http%3A%2F%2Fexample.com%2Fdirect_notification_url&email=toto%40example.com&transaction_id=6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T&return_url=http%3A%2F%2Fexample.com%2Fretour&nok=1' r = p.response(retour.split('?',1)[1]) assert not r[0] diff --git a/eopayment/spplus.py b/eopayment/spplus.py index f10fc89..5673e60 100644 --- a/eopayment/spplus.py +++ b/eopayment/spplus.py @@ -63,17 +63,18 @@ class Payment(PaymentCommon): 'caption': 'Siret of the entreprise augmented with the ' 'site number, example: 00000000000001-01', 'regexp': re.compile('^ *(\d{14}-\d{2}) *$') - } + }, + 'langue': { + 'caption': 'Language of the customers', + 'default': 'FR', + }, + 'taxe': { + 'caption': 'Taxes', + 'default': '0.00' + }, } } - - def __init__(self, options): - LOGGER.debug('initializing spplus payment with %s' % options) - self.cle = options['cle'] - self.siret = options['siret'] - self.devise = '978' - self.langue = options.get('langue', 'FR') - self.taxe = options.get('taxe', '0.00') + devise = '978' def request(self, montant, email=None, next_url=None): LOGGER.debug('requesting spplus payment with montant %s email=%s and \ diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py index 246ff59..1a5a09c 100644 --- a/eopayment/systempayv2.py +++ b/eopayment/systempayv2.py @@ -25,8 +25,8 @@ def isonow(): .replace(':','')[:14] class Parameter: - def __init__(self, name, ptype, code, max_length=None, length=None, needed=False, - default=None, choices=None): + def __init__(self, name, ptype, code, max_length=None, length=None, + needed=False, default=None, choices=None): self.name = name self.ptype = ptype self.code = code