add response.test flag
on tipi, spplus and systempayv2 only.
This commit is contained in:
parent
1ed33d046c
commit
db67c3887d
|
@ -28,6 +28,7 @@ class PaymentResponse(object):
|
|||
result -- holds the declarative result of the transaction, does not use
|
||||
it to validate the payment in your backoffice, it's just for informing
|
||||
the user that all is well.
|
||||
test -- indicates if the transaction was a test
|
||||
signed -- holds whether the message was signed
|
||||
bank_data -- a dictionnary containing some data depending on the bank,
|
||||
you have to log it for audit purpose.
|
||||
|
@ -44,7 +45,7 @@ class PaymentResponse(object):
|
|||
|
||||
def __init__(self, result=None, signed=None, bank_data=dict(),
|
||||
return_content=None, bank_status='', transaction_id='',
|
||||
order_id=''):
|
||||
order_id='', test=False):
|
||||
self.result = result
|
||||
self.signed = signed
|
||||
self.bank_data = bank_data
|
||||
|
@ -52,6 +53,7 @@ class PaymentResponse(object):
|
|||
self.bank_status = bank_status
|
||||
self.transaction_id = transaction_id
|
||||
self.order_id = order_id
|
||||
self.test = test
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s %s>' % (self.__class__.__name__, self.__dict__)
|
||||
|
|
|
@ -115,7 +115,8 @@ class Payment(PaymentCommon):
|
|||
return_content=content,
|
||||
order_id=transaction_id,
|
||||
transaction_id=transaction_id,
|
||||
bank_status=form.get('reason'))
|
||||
bank_status=form.get('reason'),
|
||||
test=True)
|
||||
return response
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -48,6 +48,7 @@ SPPLUS_RESPONSE_CODES = {
|
|||
VALID_STATE = ('1', '4', '10')
|
||||
ACCEPTED_STATE = ('1', '4')
|
||||
PAID_STATE = ('10',)
|
||||
TEST_STATE = ('99',)
|
||||
|
||||
|
||||
def decrypt_ntkey(ntkey):
|
||||
|
@ -179,12 +180,17 @@ next_url=%s' % (montant, email, next_url))
|
|||
bank_status.append('invalid signature')
|
||||
except ValueError:
|
||||
bank_status.append('invalid signature')
|
||||
|
||||
test = False
|
||||
if etat in PAID_STATE:
|
||||
result = PAID
|
||||
elif etat in ACCEPTED_STATE:
|
||||
result = ACCEPTED
|
||||
elif etat in VALID_STATE:
|
||||
result = RECEIVED
|
||||
elif etat in TEST_STATE:
|
||||
result = RECEIVED # what else ?
|
||||
test = True
|
||||
else:
|
||||
result = ERROR
|
||||
|
||||
|
@ -195,7 +201,8 @@ next_url=%s' % (montant, email, next_url))
|
|||
order_id=reference,
|
||||
transaction_id=form[self.BANK_ID],
|
||||
bank_status=' - '.join(bank_status),
|
||||
return_content=SPCHECKOK)
|
||||
return_content=SPCHECKOK,
|
||||
test=test)
|
||||
return response
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ VADS_SITE_ID = 'vads_site_id'
|
|||
VADS_TRANS_ID = 'vads_trans_id'
|
||||
SIGNATURE = 'signature'
|
||||
VADS_TRANS_ID = 'vads_trans_id'
|
||||
VADS_CTX_MODE = 'vads_ctx_mode'
|
||||
|
||||
|
||||
def isonow():
|
||||
|
@ -353,6 +354,7 @@ class Payment(PaymentCommon):
|
|||
result = PAID
|
||||
else:
|
||||
result = ERROR
|
||||
test = fields[VADS_CTX_MODE] == 'TEST'
|
||||
transaction_id = '%s_%s' % (copy[VADS_TRANS_DATE], copy[VADS_TRANS_ID])
|
||||
# the VADS_AUTH_NUMBER is the number to match payment in bank logs
|
||||
copy[self.BANK_ID] = copy.get(VADS_AUTH_NUMBER, '')
|
||||
|
@ -362,7 +364,8 @@ class Payment(PaymentCommon):
|
|||
bank_data=copy,
|
||||
order_id=transaction_id,
|
||||
transaction_id=copy.get(VADS_AUTH_NUMBER),
|
||||
bank_status=' - '.join(bank_status))
|
||||
bank_status=' - '.join(bank_status),
|
||||
test=test)
|
||||
return response
|
||||
|
||||
def signature(self, fields):
|
||||
|
|
|
@ -147,12 +147,16 @@ class Payment(PaymentCommon):
|
|||
else:
|
||||
bank_status = 'wrong return: %r' % result
|
||||
result = ERROR
|
||||
|
||||
test = fields.get('saisie') == 'T'
|
||||
|
||||
return PaymentResponse(
|
||||
result=result,
|
||||
bank_status=bank_status,
|
||||
signed=True,
|
||||
bank_data=fields,
|
||||
transaction_id=transaction_id)
|
||||
transaction_id=transaction_id,
|
||||
test=test)
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = Payment({'numcli': '12345'})
|
||||
|
|
Loading…
Reference in New Issue