0001-paybox-use-uuid4-to-generate-transaction-id-9946.patch
eopayment/paybox.py | ||
---|---|---|
22 | 22 |
import hashlib |
23 | 23 |
import hmac |
24 | 24 |
import requests |
25 |
import uuid |
|
25 | 26 | |
26 | 27 |
import pytz |
27 | 28 | |
... | ... | |
284 | 285 |
] |
285 | 286 |
} |
286 | 287 | |
288 |
def make_pbx_cmd(self, guid, orderid=None, transaction_id=None): |
|
289 |
if not transaction_id: |
|
290 |
date = datetime.datetime.now(pytz.timezone(self.timezone)).strftime('%Y-%m-%dT%H%M%S') |
|
291 |
transaction_id = '%s_%s' % (date, guid) |
|
292 |
pbx_cmd = transaction_id |
|
293 |
if orderid: |
|
294 |
pbx_cmd += '!' + orderid |
|
295 |
return pbx_cmd |
|
296 | ||
287 | 297 |
def request(self, amount, email, name=None, orderid=None, manual_validation=None, **kwargs): |
288 | 298 |
d = OrderedDict() |
289 | 299 |
d['PBX_SITE'] = force_text(self.site) |
... | ... | |
291 | 301 |
d['PBX_IDENTIFIANT'] = force_text(self.identifiant) |
292 | 302 |
d['PBX_TOTAL'] = self.clean_amount(amount) |
293 | 303 |
d['PBX_DEVISE'] = force_text(self.devise) |
294 |
transaction_id = kwargs.get('transaction_id') or \ |
|
295 |
self.transaction_id(12, string.digits, 'paybox', self.site, |
|
296 |
self.rang, self.identifiant) |
|
297 |
d['PBX_CMD'] = force_text(transaction_id) |
|
298 |
# prepend order id command reference |
|
299 |
if orderid: |
|
300 |
d['PBX_CMD'] = orderid + ORDERID_TRANSACTION_SEPARATOR + d['PBX_CMD'] |
|
304 |
guid = str(uuid.uuid4().hex) |
|
305 |
transaction_id = d['PBX_CMD'] = self.make_pbx_cmd(guid=guid, |
|
306 |
transaction_id=kwargs.get('transaction_id'), |
|
307 |
orderid=orderid) |
|
301 | 308 |
d['PBX_PORTEUR'] = force_text(email) |
302 | 309 |
d['PBX_RETOUR'] = ( |
303 | 310 |
'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;' |
... | ... | |
309 | 316 |
d['PBX_TIME'] = kwargs.get('time') or ( |
310 | 317 |
force_text(datetime.datetime.utcnow().isoformat('T')).split('.')[0] |
311 | 318 |
+ '+00:00') |
312 |
d['PBX_ARCHIVAGE'] = transaction_id
|
|
319 |
d['PBX_ARCHIVAGE'] = orderid or guid
|
|
313 | 320 |
if self.normal_return_url: |
314 | 321 |
d['PBX_EFFECTUE'] = self.normal_return_url |
315 | 322 |
d['PBX_REFUSE'] = self.normal_return_url |
... | ... | |
378 | 385 |
bank_status = PAYBOX_ERROR_CODES.get(prefix + suffix) |
379 | 386 |
if bank_status is not None: |
380 | 387 |
break |
381 |
orderid = d['reference'][0] |
|
382 |
# decode order id from returned reference |
|
383 |
if ORDERID_TRANSACTION_SEPARATOR in orderid: |
|
384 |
orderid, transaction_id = orderid.split(ORDERID_TRANSACTION_SEPARATOR, 1) |
|
388 |
pbx_cmd = d['reference'][0] |
|
385 | 389 |
transaction_date = None |
386 | 390 |
if 'date_transaction' in d and 'heure_transaction' in d: |
387 | 391 |
try: |
... | ... | |
395 | 399 |
paris_tz = pytz.timezone(self.timezone) |
396 | 400 |
transaction_date = paris_tz.localize(transaction_date) |
397 | 401 |
return PaymentResponse( |
398 |
order_id=orderid,
|
|
402 |
order_id=pbx_cmd,
|
|
399 | 403 |
signed=signed, |
400 | 404 |
bank_data=d, |
401 | 405 |
result=result, |
tests/test_paybox.py | ||
---|---|---|
87 | 87 |
Decimal(amount), email=email, orderid=order_id, |
88 | 88 |
transaction_id=transaction, time=time, manual_validation=False) |
89 | 89 |
self.assertEqual(kind, eopayment.FORM) |
90 |
self.assertEqual(transaction_id, '1234')
|
|
90 |
self.assertEqual(transaction_id, '%s!%s' % (transaction, order_id))
|
|
91 | 91 |
root = ET.fromstring(str(what)) |
92 | 92 |
self.assertEqual(root.tag, 'form') |
93 | 93 |
self.assertEqual(root.attrib['method'], 'POST') |
... | ... | |
103 | 103 |
), |
104 | 104 |
'PBX_TIME': time, |
105 | 105 |
'PBX_PORTEUR': email, |
106 |
'PBX_CMD': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction,
|
|
106 |
'PBX_CMD': '%s!%s' % (transaction, order_id),
|
|
107 | 107 |
'PBX_TOTAL': amount.replace('.', ''), |
108 | 108 |
'PBX_DEVISE': '978', |
109 | 109 |
'PBX_HASH': 'SHA512', |
110 | 110 |
'PBX_HMAC': ( |
111 |
'CE29AB421D9FF5E22B52A0F0D31BB881E6D' |
|
112 |
'3040B7A0B390AC3F335292A75D2389253A3' |
|
113 |
'ED6B3E430A90D30088F6AC29F792B484A2E' |
|
114 |
'CFC36A1B73771796A5FD15C' |
|
111 |
'300CFBDFF0454403BE7FEA11B9714C6B134294313E' |
|
112 |
'7A052580F517BFCB117FB6A175C2E0DC81F6137D95' |
|
113 |
'8FCA3CC4F8F1883A479C474C3A7B871CCA2DB8D033D9' |
|
115 | 114 |
), |
116 |
'PBX_ARCHIVAGE': '1234',
|
|
115 |
'PBX_ARCHIVAGE': '20160216',
|
|
117 | 116 |
'PBX_REPONDRE_A': 'http://example.com/callback', |
118 | 117 |
'PBX_AUTOSEULE': 'N' |
119 | 118 |
} |
... | ... | |
203 | 202 |
backend = eopayment.Payment('paybox', BACKEND_PARAMS) |
204 | 203 |
order_id = '20160216' |
205 | 204 |
transaction = '1234' |
206 |
reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction
|
|
205 |
reference = transaction + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + order_id
|
|
207 | 206 |
data = { |
208 | 207 |
'montant': '4242', |
209 | 208 |
'reference': reference, |
... | ... | |
212 | 211 |
'date_transaction': '20200101', |
213 | 212 |
'heure_transaction': '01:01:01'} |
214 | 213 |
response = backend.response(urllib.urlencode(data)) |
215 |
self.assertEqual(response.order_id, order_id)
|
|
214 |
self.assertEqual(response.order_id, reference)
|
|
216 | 215 |
assert not response.signed |
217 | 216 |
assert response.transaction_date.isoformat() == '2020-01-01T01:01:01+01:00' |
218 | 217 | |
219 |
- |