From 18ff6b861f2889f81873b0201aa95cea9b1bd2b9 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 13:31:10 +0200 Subject: [PATCH 01/11] fix: DATA query passed as array in the response --- eopayment/sips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 3dcf7d9..0ef8f3b 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -142,7 +142,7 @@ class Payment(PaymentCommon): def response(self, query_string): form = urlparse.parse_qs(query_string) - params = {'message': form[DATA]} + params = {'message': form[DATA][0]} result = self.execute('response', params) d = dict(zip(RESPONSE_PARAMS, result)) # The reference identifier for the payment is the authorisation_id From e86119927c030f86cddf8da55c6b96412ae77849 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 13:36:03 +0200 Subject: [PATCH 02/11] fix: PaymentResponse arguments does not match signature --- eopayment/sips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 0ef8f3b..15410ec 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -152,7 +152,7 @@ class Payment(PaymentCommon): response_code_msg = CB_BANK_RESPONSE_CODES.get(d.get(RESPONSE_CODE)) response = PaymentResponse( result=response_result, - signed_result=response_result, + signed=response_result, bank_data=d, order_id=d.get(ORDER_ID), transaction_id=d.get(AUTHORISATION_ID), From a4346253358c7088b1a20950245440aeb5aadbd3 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 13:40:48 +0200 Subject: [PATCH 03/11] sips.py pep8 compliance --- eopayment/sips.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 15410ec..5ee4281 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -7,7 +7,6 @@ import logging import os import os.path import uuid -import logging from common import PaymentCommon, HTML, PaymentResponse from cb import CB_RESPONSE_CODES @@ -29,26 +28,28 @@ contained in the middleware distribution file. ''' -__all__ = [ 'Payment' ] +__all__ = ['Payment'] -BINPATH = 'binpath' +BINPATH = 'binpath' PATHFILE = 'pathfile' AUTHORISATION_ID = 'authorisation_id' REQUEST_VALID_PARAMS = ['merchant_id', 'merchant_country', 'amount', 'currency_code', 'pathfile', 'normal_return_url', 'cancel_return_url', 'automatic_response_url', 'language', 'payment_means', 'header_flag', 'capture_day', 'capture_mode', 'bgcolor', 'block_align', 'block_order', - 'textcolor', 'receipt_complement', 'caddie', 'customer_id', 'customer_email', - 'customer_ip_address', 'data', 'return_context', 'target', 'order_id'] + 'textcolor', 'receipt_complement', 'caddie', 'customer_id', + 'customer_email', 'customer_ip_address', 'data', 'return_context', + 'target', 'order_id'] -RESPONSE_PARAMS = [ 'code', 'error', 'merchant_id', 'merchant_country', +RESPONSE_PARAMS = ['code', 'error', 'merchant_id', 'merchant_country', 'amount', 'transaction_id', 'payment_means', 'transmission_date', 'payment_time', 'payment_date', 'response_code', 'payment_certificate', AUTHORISATION_ID, 'currency_code', 'card_number', 'cvv_flag', 'cvv_response_code', 'bank_response_code', 'complementary_code', 'complementary_info', 'return_context', 'caddie', 'receipt_complement', - 'merchant_language', 'language', 'customer_id', 'order_id', 'customer_email', - 'customer_ip_address', 'capture_day', 'capture_mode', 'data', ] + 'merchant_language', 'language', 'customer_id', 'order_id', + 'customer_email', 'customer_ip_address', 'capture_day', 'capture_mode', + 'data', ] DATA = 'DATA' PARAMS = 'params' @@ -58,9 +59,9 @@ ORDER_ID = 'order_id' MERCHANT_ID = 'merchant_id' RESPONSE_CODE = 'response_code' -DEFAULT_PARAMS = { 'merchant_id': '014213245611111', - 'merchant_country': 'fr', - 'currency_code': '978' } +DEFAULT_PARAMS = {'merchant_id': '014213245611111', + 'merchant_country': 'fr', + 'currency_code': '978'} LOGGER = logging.getLogger(__name__) @@ -80,27 +81,26 @@ FINAREF_BANK_RESPONSE_CODE = { '05': 'Compte / Porteur avec statut bloqué ou invalide', '11': 'Compte / porteur inconnu', '16': 'Provision insuffisante', -'20': 'Commerçant invalide - Code monnaie incorrect - Opération commerciale inconnue - Opération commerciale invalide', +'20': 'Commerçant invalide - Code monnaie incorrect - ' + \ + 'Opération commerciale inconnue - Opération commerciale invalide', '80': 'Transaction approuvée avec dépassement', '81': 'Transaction approuvée avec augmentation capital', '82': 'Transaction approuvée NPAI', '83': 'Compte / porteur invalide', } + class Payment(PaymentCommon): description = { 'caption': 'SIPS', 'parameters': [{ 'name': 'merchand_id', }, - { 'name': 'merchant_country', }, - { 'name': 'currency_code', } + {'name': 'merchant_country', }, + {'name': 'currency_code', } ], } - - - def __init__(self, options, logger=LOGGER): self.options = options self.logger = logger @@ -110,7 +110,7 @@ class Payment(PaymentCommon): if PATHFILE in self.options: params[PATHFILE] = self.options[PATHFILE] executable = os.path.join(self.options[BINPATH], executable) - args = [executable] + [ "%s=%s" % p for p in params.iteritems() ] + args = [executable] + ["%s=%s" % p for p in params.iteritems()] self.logger.debug('executing %s' % args) result, _ = subprocess.Popen(args, executable=executable, stdout=subprocess.PIPE, shell=True).communicate() @@ -128,8 +128,8 @@ class Payment(PaymentCommon): transaction_id = self.transaction_id(6, string.digits, 'sips', params[MERCHANT_ID]) params[TRANSACTION_ID] = transaction_id - params[ORDER_ID] = str(uuid.uuid4()).replace('-','') - params['amount'] = str(Decimal(amount)*100) + params[ORDER_ID] = str(uuid.uuid4()).replace('-', '') + params['amount'] = str(Decimal(amount) * 100) if email: params['customer_email'] = email if next_url: From 00dff5f3295dfbc2684704a634974957f4777247 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 13:43:35 +0200 Subject: [PATCH 04/11] common.py pep8 compliance --- eopayment/common.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eopayment/common.py b/eopayment/common.py index 443275b..272ec82 100644 --- a/eopayment/common.py +++ b/eopayment/common.py @@ -4,8 +4,8 @@ import random import logging from datetime import date -__all__ = [ 'PaymentCommon', 'URL', 'HTML', 'RANDOM', 'RECEIVED', 'ACCEPTED', -'PAID', 'ERROR' ] +__all__ = ['PaymentCommon', 'URL', 'HTML', 'RANDOM', 'RECEIVED', 'ACCEPTED', + 'PAID', 'ERROR'] LOGGER = logging.getLogger(__name__) @@ -19,6 +19,7 @@ ACCEPTED = 2 PAID = 3 ERROR = 99 + class PaymentResponse(object): '''Holds a generic view on the result of payment transaction response. @@ -82,9 +83,11 @@ class PaymentCommon(object): while True: parts = [RANDOM.choice(choices) for x in range(length)] id = ''.join(parts) - name = '%s_%s_%s' % (str(date.today()), '-'.join(prefixes), str(id)) + name = '%s_%s_%s' % (str(date.today()), + '-'.join(prefixes), str(id)) try: - fd=os.open(os.path.join(self.PATH, name), os.O_CREAT|os.O_EXCL) + fd = os.open(os.path.join(self.PATH, name), + os.O_CREAT | os.O_EXCL) except: raise else: From 03c078e8c7a7507777801faf34e443806332c1de Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 13:45:46 +0200 Subject: [PATCH 05/11] __init__.py pep8 compliance --- eopayment/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/eopayment/__init__.py b/eopayment/__init__.py index 455dc9b..2282cee 100644 --- a/eopayment/__init__.py +++ b/eopayment/__init__.py @@ -5,8 +5,8 @@ import os.path from common import URL, HTML -__all__ = [ 'Payment', 'URL', 'HTML', '__version__', 'SIPS', 'SYSTEMPAY', - 'SPPLUS', 'DUMMY', 'get_backend' ] +__all__ = ['Payment', 'URL', 'HTML', '__version__', 'SIPS', 'SYSTEMPAY', + 'SPPLUS', 'DUMMY', 'get_backend'] __version__ = "0.0.12" @@ -17,11 +17,13 @@ SYSTEMPAY = 'systempayv2' SPPLUS = 'spplus' DUMMY = 'dummy' + def get_backend(kind): '''Resolve a backend name into a module object''' module = __import__(kind, globals(), locals(), []) return module.Payment + class Payment(object): ''' Interface to credit card online payment servers of French banks. The @@ -84,7 +86,7 @@ class Payment(object): - the first gives a string value to later match the payment with the invoice, - kind gives the type of the third value, payment.URL or - payment.HTML, + payment.HTML, - the third is the URL or the HTML form to contact the payment server, which must be sent to the customer browser. @@ -120,7 +122,7 @@ class Payment(object): query_string -- the URL encoded form-data from a GET or a POST It returns a quadruplet of values: - + (result, transaction_id, bank_data, return_content) - result is a boolean stating whether the transaction worked, use it @@ -141,7 +143,7 @@ if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) spplus_options = { 'cle': '58 6d fc 9c 34 91 9b 86 3f fd 64 \ -63 c9 13 4a 26 ba 29 74 1e c7 e9 80 79', +63 c9 13 4a 26 ba 29 74 1e c7 e9 80 79', 'siret': '00000000000001-01', } p = Payment(kind=SPPLUS, options=spplus_options) @@ -149,7 +151,7 @@ if __name__ == '__main__': next_url='https://my-site.com') systempay_options = { 'secrets': { - 'TEST': '1234567890123456', + 'TEST': '1234567890123456', 'PRODUCTION': 'yyy' }, 'site_id': '00001234', @@ -160,7 +162,7 @@ if __name__ == '__main__': print p.request('10.00', email='bob@example.com', next_url='https://my-site.com') - sips_options = { 'filepath': '/', 'binpath': os.path.dirname(__file__) } + sips_options = {'filepath': '/', 'binpath': os.path.dirname(__file__)} p = Payment(kind=SIPS, options=sips_options) print p.request('10.00', email='bob@example.com', next_url='https://my-site.com') From 1f45f18a3fcf227a86a84df60e9bd4ef8f4e4d01 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 14:14:52 +0200 Subject: [PATCH 06/11] fix: request returns 5 elements instead of 3 --- eopayment/sips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 5ee4281..296289b 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -114,7 +114,7 @@ class Payment(PaymentCommon): self.logger.debug('executing %s' % args) result, _ = subprocess.Popen(args, executable=executable, stdout=subprocess.PIPE, shell=True).communicate() - result = result.split('!') + result = result.strip('!').split('!') self.logger.debug('got response %s' % result) return result From 6f8f2521621e2f39a4f68f62e29129bf017d0a0a Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 14:33:02 +0200 Subject: [PATCH 07/11] Be less greedy while removing leading and trailing '!' --- eopayment/sips.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 296289b..3907019 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -114,7 +114,11 @@ class Payment(PaymentCommon): self.logger.debug('executing %s' % args) result, _ = subprocess.Popen(args, executable=executable, stdout=subprocess.PIPE, shell=True).communicate() - result = result.strip('!').split('!') + if result[0] == '!': + result = result[1:] + if result[-1] == '!': + result = result[:-1] + result = result.split('!') self.logger.debug('got response %s' % result) return result From 21706146c0dc373306d1bc38dedceaf0971d134e Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 14:38:52 +0200 Subject: [PATCH 08/11] Amount not passed as integer in params --- eopayment/sips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index 3907019..d3b477f 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -133,7 +133,7 @@ class Payment(PaymentCommon): params[MERCHANT_ID]) params[TRANSACTION_ID] = transaction_id params[ORDER_ID] = str(uuid.uuid4()).replace('-', '') - params['amount'] = str(Decimal(amount) * 100) + params['amount'] = str(int(Decimal(amount) * 100)) if email: params['customer_email'] = email if next_url: From d23266b1ac3c39de865d48725489bce628f19384 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 13 Jun 2012 15:13:47 +0200 Subject: [PATCH 09/11] fixed calls to request script --- eopayment/sips.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index d3b477f..f4dbddb 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -104,15 +104,15 @@ class Payment(PaymentCommon): def __init__(self, options, logger=LOGGER): self.options = options self.logger = logger - logger.debug('initializing sips payment class with %s' % options) + self.logger.debug('initializing sips payment class with %s' % options) def execute(self, executable, params): if PATHFILE in self.options: params[PATHFILE] = self.options[PATHFILE] - executable = os.path.join(self.options[BINPATH], executable) + executable = os.path.join(self.options.pop(BINPATH), executable) args = [executable] + ["%s=%s" % p for p in params.iteritems()] self.logger.debug('executing %s' % args) - result, _ = subprocess.Popen(args, executable=executable, + result,_ = subprocess.Popen(' '.join(args), stdout=subprocess.PIPE, shell=True).communicate() if result[0] == '!': result = result[1:] @@ -138,6 +138,7 @@ class Payment(PaymentCommon): params['customer_email'] = email if next_url: params['normal_return_url'] = next_url + params.pop('binpath') code, error, form = self.execute('request', params) if int(code) == 0: return params[ORDER_ID], HTML, form From ea0ad0e19eee51843acc9d780deb954571492eec Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 4 Jul 2012 18:10:54 +0200 Subject: [PATCH 10/11] catch invalid response and show detailled error message --- eopayment/sips.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eopayment/sips.py b/eopayment/sips.py index f4dbddb..2dbbe87 100644 --- a/eopayment/sips.py +++ b/eopayment/sips.py @@ -114,10 +114,14 @@ class Payment(PaymentCommon): self.logger.debug('executing %s' % args) result,_ = subprocess.Popen(' '.join(args), stdout=subprocess.PIPE, shell=True).communicate() - if result[0] == '!': - result = result[1:] - if result[-1] == '!': - result = result[:-1] + try: + if result[0] == '!': + result = result[1:] + if result[-1] == '!': + result = result[:-1] + except IndexError: + raise ValueError("Invalid response", result) + return False result = result.split('!') self.logger.debug('got response %s' % result) return result From d3e3d43bec8dd5bad8180e41c8130a8cab578843 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Tue, 10 Jul 2012 18:04:22 +0200 Subject: [PATCH 11/11] pep8 on systempay --- eopayment/systempayv2.py | 114 ++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py index 22eab59..5131835 100644 --- a/eopayment/systempayv2.py +++ b/eopayment/systempayv2.py @@ -29,12 +29,14 @@ VADS_TRANS_ID = 'vads_trans_id' SIGNATURE = 'signature' VADS_TRANS_ID = 'vads_trans_id' + def isonow(): return dt.datetime.now() \ .isoformat('T') \ - .replace('-','') \ - .replace('T','') \ - .replace(':','')[:14] + .replace('-', '') \ + .replace('T', '') \ + .replace(':', '')[:14] + class Parameter: def __init__(self, name, ptype, code, max_length=None, length=None, @@ -60,17 +62,17 @@ class Parameter: return False if value == '': return True - value = str(value).replace('.','') + value = str(value).replace('.', '') if self.ptype == 'n': return value.isdigit() elif self.ptype == 'an': return value.isalnum() elif self.ptype == 'an-': - return value.replace('-','').isalnum() + return value.replace('-', '').isalnum() elif self.ptype == 'an;': - return value.replace(';','').isalnum() + return value.replace(';', '').isalnum() elif self.ptype == 'an@': - return value.replace('@','').isalnum() + return value.replace('@', '').isalnum() # elif self.ptype == 'ans': return True @@ -78,12 +80,14 @@ class Parameter: PARAMETERS = [ # amount as euro cents Parameter('vads_action_mode', None, 47, needed=True, - default='INTERACTIVE', choices=('SILENT','INTERACTIVE')), + default='INTERACTIVE', choices=('SILENT', 'INTERACTIVE')), Parameter('vads_amount', 'n', 9, max_length=12, needed=True), Parameter('vads_capture_delay', 'n', 6, max_length=3, default=''), - Parameter('vads_contrib', 'ans', 31, max_length=255, default='eopayment'), + Parameter('vads_contrib', 'ans', 31, max_length=255, + default='eopayment'), # defaut currency = EURO, norme ISO4217 - Parameter('vads_currency', 'n', 10, length=3, default=978, needed=True), + Parameter('vads_currency', 'n', 10, length=3, default=978, + needed=True), Parameter('vads_cust_address', 'an', 19, max_length=255), # code ISO 3166 Parameter('vads_cust_country', 'a', 22, length=2, default='FR'), @@ -115,9 +119,9 @@ PARAMETERS = [ 'PAYPAL_SB, PAYSAFECARD, VISA')), # must be SINGLE or MULTI with parameters Parameter('vads_payment_config', '', 07, default='SINGLE', - choices=('SINGLE','MULTI'), needed=True), + choices=('SINGLE', 'MULTI'), needed=True), Parameter('vads_return_mode', None, 48, default='GET', - choices=('','NONE','POST','GET')), + choices=('', 'NONE', 'POST', 'GET')), Parameter('signature', 'an', None, length=40), Parameter('vads_site_id', 'n', 02, length=8, needed=True, description=_(u'Identifiant de la boutique')), @@ -125,8 +129,8 @@ PARAMETERS = [ Parameter(VADS_TRANS_DATE, 'n', 04, length=14, needed=True, default=isonow), Parameter('vads_trans_id', 'n', 03, length=6, needed=True), - Parameter('vads_validation_mode', 'n', 5, max_length=1, choices=('', 0, 1), - default=''), + Parameter('vads_validation_mode', 'n', 5, max_length=1, + choices=('', 0, 1), default=''), Parameter('vads_version', 'an', 01, default='V2', needed=True, choices=('V2',)), Parameter('vads_url_success', 'ans', 24, max_length=127), @@ -138,7 +142,8 @@ PARAMETERS = [ Parameter('vads_user_info', 'ans', 61, max_length=255), Parameter('vads_contracts', 'ans', 62, max_length=255), ] -PARAMETER_MAP = dict(((parameter.name, parameter) for parameter in PARAMETERS )) +PARAMETER_MAP = dict(((parameter.name, + parameter) for parameter in PARAMETERS)) AUTH_RESULT_MAP = CB_RESPONSE_CODES @@ -164,15 +169,17 @@ liste blanche du commerçant", d'un des contrôles locaux", } + def add_vads(kwargs): - new_vargs={} + new_vargs = {} for k, v in kwargs.iteritems(): if k.startswith('vads_'): new_vargs[k] = v else: - new_vargs['vads_'+k] = v + new_vargs['vads_' + k] = v return new_vargs + def check_vads(kwargs, exclude=[]): for parameter in PARAMETERS: name = parameter.name @@ -183,13 +190,14 @@ def check_vads(kwargs, exclude=[]): name, kwargs[name], parameter.ptype)) + class Payment(PaymentCommon): - ''' + ''' Produce request for and verify response from the SystemPay payment gateway. - >>> gw =Payment(dict(secret_test='xxx', secret_production='yyyy' site_id=123, - ctx_mode='PRODUCTION') + >>> gw =Payment(dict(secret_test='xxx', secret_production='yyyy', + site_id=123, ctx_mode='PRODUCTION')) >>> print gw.request(100) ('20120525093304_188620', 'https://paiement.systempay.fr/vads-payment/?vads_url_return=http%3A%2F%2Furl.de.retour%2Fretour.php&vads_cust_country=FR&vads_site_id=&vads_payment_config=SINGLE&vads_trans_id=188620&vads_action_mode=INTERACTIVE&vads_contrib=eopayment&vads_page_action=PAYMENT&vads_trans_date=20120525093304&vads_ctx_mode=TEST&vads_validation_mode=&vads_version=V2&vads_payment_cards=&signature=5d412498ab523627ec5730a09118f75afa602af5&vads_language=fr&vads_capture_delay=&vads_currency=978&vads_amount=100&vads_return_mode=NONE', @@ -206,41 +214,37 @@ class Payment(PaymentCommon): ''' description = { - 'caption': 'SystemPay, système de paiment du groupe BPCE', - 'parameters': [ - { 'name': 'service_url', - 'default': SERVICE_URL, - 'caption': _(u'URL du service de paiment'), - 'help_text': _(u'ne pas modifier si vous ne savez pas'), - 'validation': lambda x: x.startswith('http'), - 'required': True, - }, - { 'name': 'secret_test', - 'caption': _(u'Secret pour la configuration de TEST'), - 'validation': str.isdigit, - 'required': True, - }, - { 'name': 'secret_production', - 'caption': _(u'Secret pour la configuration de PRODUCTION'), - 'validation': str.isdigit, - }, - ] + 'caption': 'SystemPay, système de paiment du groupe BPCE', + 'parameters': [ + {'name': 'service_url', + 'default': SERVICE_URL, + 'caption': _(u'URL du service de paiment'), + 'help_text': _(u'ne pas modifier si vous ne savez pas'), + 'validation': lambda x: x.startswith('http'), + 'required': True, }, + {'name': 'secret_test', + 'caption': _(u'Secret pour la configuration de TEST'), + 'validation': str.isdigit, + 'required': True, }, + {'name': 'secret_production', + 'caption': _(u'Secret pour la configuration de PRODUCTION'), + 'validation': str.isdigit, }, + ] } - for name in ('vads_ctx_mode', VADS_SITE_ID, 'vads_order_info', 'vads_order_info2', - 'vads_order_info3', 'vads_payment_cards', 'vads_payment_config'): + for name in ('vads_ctx_mode', VADS_SITE_ID, 'vads_order_info', + 'vads_order_info2', 'vads_order_info3', + 'vads_payment_cards', 'vads_payment_config'): parameter = PARAMETER_MAP[name] - x = { 'name': name, - 'caption': parameter.description or name, - 'validation': parameter.check_value, - 'default': parameter.default, - 'required': parameter.needed, - 'help_text': parameter.help_text, - 'max_length': parameter.max_length - } + x = {'name': name, + 'caption': parameter.description or name, + 'validation': parameter.check_value, + 'default': parameter.default, + 'required': parameter.needed, + 'help_text': parameter.help_text, + 'max_length': parameter.max_length} description['parameters'].append(x) - def __init__(self, options, logger=LOGGER): self.service_url = options.pop('service_url', SERVICE_URL) self.secret_test = options.pop('secret_test') @@ -313,7 +317,7 @@ class Payment(PaymentCommon): if v.isdigit(): for parameter in PARAMETERS: if int(v) == parameter.code: - s ='erreur dans le champ %s' % parameter.name + s = 'erreur dans le champ %s' % parameter.name copy[VADS_EXTRA_RESULT] = s bank_status.append(copy[VADS_EXTRA_RESULT]) elif v in ('05', '00'): @@ -349,10 +353,10 @@ class Payment(PaymentCommon): return response def signature(self, fields): - self.logger.debug('got fields %s to sign' % fields ) - ordered_keys = sorted([ key for key in fields.keys() if key.startswith('vads_') ]) + self.logger.debug('got fields %s to sign' % fields) + ordered_keys = sorted([key for key in fields.keys() if key.startswith('vads_')]) self.logger.debug('ordered keys %s' % ordered_keys) - ordered_fields = [ str(fields[key]) for key in ordered_keys] + ordered_fields = [str(fields[key]) for key in ordered_keys] secret = getattr(self, 'secret_%s' % fields['vads_ctx_mode'].lower()) signed_data = '+'.join(ordered_fields) signed_data = '%s+%s' % (signed_data, secret) @@ -364,7 +368,7 @@ class Payment(PaymentCommon): if __name__ == '__main__': p = Payment(dict( secret_test='', - site_id='', + site_id='', ctx_mode='TEST')) print p.request(100, vads_url_return='http://url.de.retour/retour.php') qs = 'vads_amount=100&vads_auth_mode=FULL&vads_auth_number=767712&vads_auth_result=00&vads_capture_delay=0&vads_card_brand=CB&vads_card_number=497010XXXXXX0000&vads_payment_certificate=9da32cc109882089e1b3fb80888ebbef072f70b7&vads_ctx_mode=TEST&vads_currency=978&vads_effective_amount=100&vads_site_id=&vads_trans_date=20120529132547&vads_trans_id=620594&vads_validation_mode=0&vads_version=V2&vads_warranty_result=NO&vads_payment_src=&vads_order_id=---&vads_cust_country=FR&vads_contrib=eopayment&vads_contract_used=2334233&vads_expiry_month=6&vads_expiry_year=2013&vads_pays_ip=FR&vads_identifier=&vads_subscription=&vads_threeds_enrolled=&vads_threeds_cavv=&vads_threeds_eci=&vads_threeds_xid=&vads_threeds_cavvAlgorithm=&vads_threeds_status=&vads_threeds_sign_valid=&vads_threeds_error_code=&vads_threeds_exit_status=&vads_result=00&vads_extra_result=&vads_card_country=FR&vads_language=fr&vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&signature=9c4f2bf905bb06b008b07090905adf36638d8ece&'