systempay: copy vads_effective_creation_date to response.transaction_date (#41320)
This commit is contained in:
parent
5be09fdfe1
commit
70bf7295b6
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytz
|
||||
import datetime as dt
|
||||
import hashlib
|
||||
import logging
|
||||
|
@ -33,6 +34,7 @@ VADS_SITE_ID = 'vads_site_id'
|
|||
VADS_TRANS_ID = 'vads_trans_id'
|
||||
SIGNATURE = 'signature'
|
||||
VADS_CTX_MODE = 'vads_ctx_mode'
|
||||
VADS_EFFECTIVE_CREATION_DATE = 'vads_effective_creation_date'
|
||||
|
||||
|
||||
def isonow():
|
||||
|
@ -40,6 +42,14 @@ def isonow():
|
|||
.replace('T', '').replace(':', '')[:14]
|
||||
|
||||
|
||||
def parse_utc(value):
|
||||
try:
|
||||
naive_dt = dt.datetime.strptime(value, '%Y%m%d%H%M%S')
|
||||
except ValueError:
|
||||
return None
|
||||
return pytz.utc.localize(naive_dt)
|
||||
|
||||
|
||||
class Parameter:
|
||||
def __init__(self, name, ptype, code, max_length=None, length=None,
|
||||
needed=False, default=None, choices=None, description=None,
|
||||
|
@ -417,6 +427,9 @@ class Payment(PaymentCommon):
|
|||
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, '')
|
||||
transaction_date = None
|
||||
if VADS_EFFECTIVE_CREATION_DATE in fields:
|
||||
transaction_date = parse_utc(fields[VADS_EFFECTIVE_CREATION_DATE])
|
||||
response = PaymentResponse(
|
||||
result=result,
|
||||
signed=signature_result,
|
||||
|
@ -424,6 +437,7 @@ class Payment(PaymentCommon):
|
|||
order_id=transaction_id,
|
||||
transaction_id=copy.get(VADS_AUTH_NUMBER),
|
||||
bank_status=' - '.join(bank_status),
|
||||
transaction_date=transaction_date,
|
||||
test=test)
|
||||
return response
|
||||
|
||||
|
|
|
@ -51,9 +51,13 @@ def test_systempayv2():
|
|||
'&vads_ctx_mode=TEST&vads_currency=978&vads_effective_amount=1042' \
|
||||
'&vads_site_id=70168983&vads_trans_date=20161013101355' \
|
||||
'&vads_trans_id=226787&vads_trans_uuid=4b5053b3b1fe4b02a07753e7a' \
|
||||
'&signature=62a4fb6738ebadebf9cc720164bc70e47282d36e'
|
||||
'&vads_effective_creation_date=20200330162530' \
|
||||
'&signature=faca0ef814d55a860996e28f84de9a9b29ddeca2'
|
||||
response = p.response(response_qs)
|
||||
assert response.result == PAID
|
||||
assert response.signed
|
||||
assert response.transaction_date
|
||||
assert response.transaction_date.isoformat() == '2020-03-30T16:25:30+00:00'
|
||||
|
||||
# bad response
|
||||
with pytest.raises(ResponseError, match='missing signature, vads_ctx_mode or vads_auth_result'):
|
||||
|
|
Loading…
Reference in New Issue