From c652009e76c4aa7d39d3ea6280b3a5f33f4f8a77 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 5 May 2011 15:50:42 +0200 Subject: [PATCH] Add parameter to the dummy payment protocol to pass a human description of the requesting service --- eopayment/dummy.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/eopayment/dummy.py b/eopayment/dummy.py index 90361c2..8065724 100644 --- a/eopayment/dummy.py +++ b/eopayment/dummy.py @@ -13,12 +13,24 @@ SERVICE_URL = 'http://dummy-payment.demo.entrouvert.com/' ALPHANUM = string.letters + string.digits class Payment(PaymentCommon): + ''' + Dummy implementation of the payment interface. + + It is used with a dummy implementation of a bank payment service that + you can find on: + + http://dummy-payment.demo.entrouvert.com/ + ''' description = { 'caption': 'Dummy payment backend', 'parameters': { 'direct_notification_url': { 'caption': 'direct notification url', }, + 'origin': { + 'caption': 'name of the requesting service, ' + 'to present in the user interface' + }, 'siret': { 'caption': 'dummy siret parameter', }, @@ -26,17 +38,28 @@ 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'] def request(self, montant, email=None, next_url=None): transaction_id = self.transaction_id(30, ALPHANUM, 'dummy', self.siret) query = { 'transaction_id': transaction_id, + 'siret': self.siret, 'amount': montant, 'email': email, 'return_url': next_url or '', - 'direct_notification_url': self.direct_notification_url + 'direct_notification_url': self.direct_notification_url, + 'origin': self.origin } url = '%s?%s' % (SERVICE_URL, urllib.urlencode(query)) return transaction_id, URL, url @@ -54,7 +77,8 @@ class Payment(PaymentCommon): if __name__ == '__main__': options = { 'direct_notification_url': 'http://example.com/direct_notification_url', - 'siret': '1234' + 'siret': '1234', + 'origin': 'Mairie de Perpette-les-oies' } p = Payment(options) print p.request(10.00, email='toto@example.com', next_url='http://example.com/retour')