summaryrefslogtreecommitdiffstats
path: root/eopayment/systempayv2.py
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2013-03-29 17:45:36 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2013-03-29 17:45:36 (GMT)
commita4b47d91f4e713c7caf2001fc62887eb7a33e952 (patch)
tree6eefe019174e2a19b47ad6b443ae227a1f5fe6f1 /eopayment/systempayv2.py
parent5ce6dc0f843a0517a73a7b55bdc0bc56b298c153 (diff)
parentd3e3d43bec8dd5bad8180e41c8130a8cab578843 (diff)
downloadeopayment-a4b47d91f4e713c7caf2001fc62887eb7a33e952.zip
eopayment-a4b47d91f4e713c7caf2001fc62887eb7a33e952.tar.gz
eopayment-a4b47d91f4e713c7caf2001fc62887eb7a33e952.tar.bz2
Merge branch 'master' of git://github.com/strycore/eopayment
Conflicts: eopayment/systempayv2.py
Diffstat (limited to 'eopayment/systempayv2.py')
-rw-r--r--eopayment/systempayv2.py112
1 files changed, 58 insertions, 54 deletions
diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py
index c037d40..e050714 100644
--- a/eopayment/systempayv2.py
+++ b/eopayment/systempayv2.py
@@ -33,12 +33,14 @@ VADS_TRANS_ID = 'vads_trans_id'
SIGNATURE = 'signature'
VADS_TRANS_ID = 'vads_trans_id'
+
def isonow():
return dt.datetime.utcnow() \
.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,
@@ -64,27 +66,29 @@ 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()
return True
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'),
@@ -116,9 +120,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')),
@@ -126,8 +130,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),
@@ -139,7 +143,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
@@ -165,15 +170,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
@@ -184,13 +191,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',
@@ -207,41 +215,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')
@@ -326,7 +330,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'):
@@ -362,10 +366,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)
@@ -377,7 +381,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&'