0005-paybox-use-transaction_date-41320.patch
eopayment/paybox.py | ||
---|---|---|
7 | 7 |
import hashlib |
8 | 8 |
import hmac |
9 | 9 |
import requests |
10 | ||
11 |
import pytz |
|
12 | ||
10 | 13 |
from decimal import Decimal, ROUND_DOWN |
11 | 14 |
from Crypto.Signature import PKCS1_v1_5 |
12 | 15 |
from Crypto.PublicKey import RSA |
... | ... | |
273 | 276 |
if orderid: |
274 | 277 |
d['PBX_CMD'] = orderid + ORDERID_TRANSACTION_SEPARATOR + d['PBX_CMD'] |
275 | 278 |
d['PBX_PORTEUR'] = force_text(email) |
276 |
d['PBX_RETOUR'] = 'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;numero_transaction:S;signature:K' |
|
279 |
d['PBX_RETOUR'] = ( |
|
280 |
'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;' |
|
281 |
'numero_transaction:S;' |
|
282 |
'date_transaction:W;heure_transaction:Q;' |
|
283 |
'signature:K' |
|
284 |
) |
|
277 | 285 |
d['PBX_HASH'] = 'SHA512' |
278 | 286 |
d['PBX_TIME'] = kwargs.get('time') or (force_text(datetime.datetime.utcnow().isoformat('T')).split('.')[0]+'+00:00') |
279 | 287 |
d['PBX_ARCHIVAGE'] = transaction_id |
... | ... | |
325 | 333 |
data = [] |
326 | 334 |
if callback: |
327 | 335 |
for key in ('montant', 'reference', 'code_autorisation', |
328 |
'erreur', 'numero_appel', 'numero_transaction'): |
|
336 |
'erreur', 'numero_appel', 'numero_transaction', |
|
337 |
'date_transaction', 'heure_transaction'): |
|
329 | 338 |
data.append('%s=%s' % (key, urllib.quote(d[key][0]))) |
330 | 339 |
else: |
331 | 340 |
for key, value in urlparse.parse_qsl(query_string, True, True): |
... | ... | |
348 | 357 |
# decode order id from returned reference |
349 | 358 |
if ORDERID_TRANSACTION_SEPARATOR in orderid: |
350 | 359 |
orderid, transaction_id = orderid.split(ORDERID_TRANSACTION_SEPARATOR, 1) |
360 |
transaction_date = None |
|
361 |
if 'date_transaction' in d and 'heure_transaction' in d: |
|
362 |
try: |
|
363 |
full_date_string = '%sT%s' % (d['date_transaction'][0], d['heure_transaction'][0]) |
|
364 |
transaction_date = datetime.datetime.strptime(full_date_string, '%Y%m%dT%H:%M:%S') |
|
365 |
except ValueError: |
|
366 |
pass |
|
367 |
else: |
|
368 |
# We suppose it's the default timezone for Paybox |
|
369 |
paris_tz = pytz.timezone('Europe/Paris') |
|
370 |
transaction_date = paris_tz.localize(transaction_date) |
|
351 | 371 |
return PaymentResponse( |
352 | 372 |
order_id=orderid, |
353 | 373 |
signed=signed, |
354 | 374 |
bank_data=d, |
355 | 375 |
result=result, |
356 |
bank_status=bank_status) |
|
376 |
bank_status=bank_status, |
|
377 |
transaction_date=transaction_date) |
|
357 | 378 | |
358 | 379 |
def perform(self, amount, bank_data, operation): |
359 | 380 |
logger = logging.getLogger(__name__) |
tests/test_paybox.py | ||
---|---|---|
61 | 61 |
'PBX_RANG': '01', |
62 | 62 |
'PBX_SITE': '12345678', |
63 | 63 |
'PBX_IDENTIFIANT': '12345678', |
64 |
'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;numero_transaction:S;signature:K', |
|
64 |
'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;numero_transaction:S;date_transaction:W;heure_transaction:Q;signature:K',
|
|
65 | 65 |
'PBX_TIME': time, |
66 | 66 |
'PBX_PORTEUR': email, |
67 | 67 |
'PBX_CMD': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction, |
68 | 68 |
'PBX_TOTAL': amount.replace('.', ''), |
69 | 69 |
'PBX_DEVISE': '978', |
70 | 70 |
'PBX_HASH': 'SHA512', |
71 |
'PBX_HMAC': '6C70F35F9C6F6C9AB16D1E766EF981D241CB527C2E547205622DFFAF5B1B6C0F47E1DE2D3A1CE579F97AD19F87C3AE63E89B22F4B6D1E118685F5DD977891668',
|
|
71 |
'PBX_HMAC': 'CE29AB421D9FF5E22B52A0F0D31BB881E6D3040B7A0B390AC3F335292A75D2389253A3ED6B3E430A90D30088F6AC29F792B484A2ECFC36A1B73771796A5FD15C',
|
|
72 | 72 |
'PBX_ARCHIVAGE': '1234', |
73 | 73 |
'PBX_REPONDRE_A': 'http://example.com/callback', |
74 | 74 |
'PBX_AUTOSEULE': 'N' |
... | ... | |
83 | 83 |
self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value'])) |
84 | 84 |
name = node.attrib['name'] |
85 | 85 |
form_params[name] = node.attrib['value'] |
86 |
self.assertEqual(form_params, expected_form_values)
|
|
86 |
assert form_params == expected_form_values
|
|
87 | 87 | |
88 | 88 |
def test_request_with_capture_day(self): |
89 | 89 |
params = BACKEND_PARAMS.copy() |
... | ... | |
159 | 159 |
order_id = '20160216' |
160 | 160 |
transaction = '1234' |
161 | 161 |
reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction |
162 |
data = {'montant': '4242', 'reference': reference, |
|
163 |
'code_autorisation': 'A', 'erreur': '00000'} |
|
162 |
data = { |
|
163 |
'montant': '4242', |
|
164 |
'reference': reference, |
|
165 |
'code_autorisation': 'A', |
|
166 |
'erreur': '00000', |
|
167 |
'date_transaction': '20200101', |
|
168 |
'heure_transaction': '01:01:01'} |
|
164 | 169 |
response = backend.response(urllib.urlencode(data)) |
165 | 170 |
self.assertEqual(response.order_id, order_id) |
171 |
assert not response.signed |
|
172 |
assert response.transaction_date.isoformat() == '2020-01-01T01:01:01+01:00' |
|
166 | 173 | |
167 | 174 |
with self.assertRaisesRegexp(eopayment.ResponseError, 'missing erreur or reference'): |
168 | 175 |
backend.response('foo=bar') |
169 |
- |