0002-systempay-copy-vads_effective_creation_date-to-respo.patch
eopayment/systempayv2.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
import pytz |
|
3 | 4 |
import datetime as dt |
4 | 5 |
import hashlib |
5 | 6 |
import logging |
... | ... | |
33 | 34 |
VADS_TRANS_ID = 'vads_trans_id' |
34 | 35 |
SIGNATURE = 'signature' |
35 | 36 |
VADS_CTX_MODE = 'vads_ctx_mode' |
37 |
VADS_EFFECTIVE_CREATION_DATE = 'vads_effective_creation_date' |
|
36 | 38 | |
37 | 39 | |
38 | 40 |
def isonow(): |
... | ... | |
40 | 42 |
.replace('T', '').replace(':', '')[:14] |
41 | 43 | |
42 | 44 | |
45 |
def parse_utc(value): |
|
46 |
try: |
|
47 |
naive_dt = dt.datetime.strptime(value, '%Y%m%d%H%M%S') |
|
48 |
except ValueError: |
|
49 |
return None |
|
50 |
return pytz.utc.localize(naive_dt) |
|
51 | ||
52 | ||
43 | 53 |
class Parameter: |
44 | 54 |
def __init__(self, name, ptype, code, max_length=None, length=None, |
45 | 55 |
needed=False, default=None, choices=None, description=None, |
... | ... | |
417 | 427 |
transaction_id = '%s_%s' % (copy[VADS_TRANS_DATE], copy[VADS_TRANS_ID]) |
418 | 428 |
# the VADS_AUTH_NUMBER is the number to match payment in bank logs |
419 | 429 |
copy[self.BANK_ID] = copy.get(VADS_AUTH_NUMBER, '') |
430 |
transaction_date = None |
|
431 |
if VADS_EFFECTIVE_CREATION_DATE in fields: |
|
432 |
transaction_date = parse_utc(fields[VADS_EFFECTIVE_CREATION_DATE]) |
|
420 | 433 |
response = PaymentResponse( |
421 | 434 |
result=result, |
422 | 435 |
signed=signature_result, |
... | ... | |
424 | 437 |
order_id=transaction_id, |
425 | 438 |
transaction_id=copy.get(VADS_AUTH_NUMBER), |
426 | 439 |
bank_status=' - '.join(bank_status), |
440 |
transaction_date=transaction_date, |
|
427 | 441 |
test=test) |
428 | 442 |
return response |
429 | 443 |
tests/test_systempayv2.py | ||
---|---|---|
51 | 51 |
'&vads_ctx_mode=TEST&vads_currency=978&vads_effective_amount=1042' \ |
52 | 52 |
'&vads_site_id=70168983&vads_trans_date=20161013101355' \ |
53 | 53 |
'&vads_trans_id=226787&vads_trans_uuid=4b5053b3b1fe4b02a07753e7a' \ |
54 |
'&signature=62a4fb6738ebadebf9cc720164bc70e47282d36e' |
|
54 |
'&vads_effective_creation_date=20200330162530' \ |
|
55 |
'&signature=faca0ef814d55a860996e28f84de9a9b29ddeca2' |
|
55 | 56 |
response = p.response(response_qs) |
56 | 57 |
assert response.result == PAID |
58 |
assert response.signed |
|
59 |
assert response.transaction_date |
|
60 |
assert response.transaction_date.isoformat() == '2020-03-30T16:25:30+00:00' |
|
57 | 61 | |
58 | 62 |
# bad response |
59 | 63 |
with pytest.raises(ResponseError, match='missing signature, vads_ctx_mode or vads_auth_result'): |
60 |
- |