paybox: use transaction_date (#41320)
This commit is contained in:
parent
27bea9fce9
commit
69aa304c43
|
@ -7,6 +7,9 @@ import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
from decimal import Decimal, ROUND_DOWN
|
from decimal import Decimal, ROUND_DOWN
|
||||||
from Crypto.Signature import PKCS1_v1_5
|
from Crypto.Signature import PKCS1_v1_5
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
@ -254,6 +257,12 @@ class Payment(PaymentCommon):
|
||||||
'type': bool,
|
'type': bool,
|
||||||
'default': False,
|
'default': False,
|
||||||
'scope': 'transaction'
|
'scope': 'transaction'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'timezone',
|
||||||
|
'caption': _('Default Timezone'),
|
||||||
|
'default': 'Europe/Paris',
|
||||||
|
'required': False,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -273,7 +282,12 @@ class Payment(PaymentCommon):
|
||||||
if orderid:
|
if orderid:
|
||||||
d['PBX_CMD'] = orderid + ORDERID_TRANSACTION_SEPARATOR + d['PBX_CMD']
|
d['PBX_CMD'] = orderid + ORDERID_TRANSACTION_SEPARATOR + d['PBX_CMD']
|
||||||
d['PBX_PORTEUR'] = force_text(email)
|
d['PBX_PORTEUR'] = force_text(email)
|
||||||
d['PBX_RETOUR'] = 'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;numero_transaction:S;signature:K'
|
d['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'
|
||||||
|
)
|
||||||
d['PBX_HASH'] = 'SHA512'
|
d['PBX_HASH'] = 'SHA512'
|
||||||
d['PBX_TIME'] = kwargs.get('time') or (force_text(datetime.datetime.utcnow().isoformat('T')).split('.')[0]+'+00:00')
|
d['PBX_TIME'] = kwargs.get('time') or (force_text(datetime.datetime.utcnow().isoformat('T')).split('.')[0]+'+00:00')
|
||||||
d['PBX_ARCHIVAGE'] = transaction_id
|
d['PBX_ARCHIVAGE'] = transaction_id
|
||||||
|
@ -325,7 +339,8 @@ class Payment(PaymentCommon):
|
||||||
data = []
|
data = []
|
||||||
if callback:
|
if callback:
|
||||||
for key in ('montant', 'reference', 'code_autorisation',
|
for key in ('montant', 'reference', 'code_autorisation',
|
||||||
'erreur', 'numero_appel', 'numero_transaction'):
|
'erreur', 'numero_appel', 'numero_transaction',
|
||||||
|
'date_transaction', 'heure_transaction'):
|
||||||
data.append('%s=%s' % (key, urllib.quote(d[key][0])))
|
data.append('%s=%s' % (key, urllib.quote(d[key][0])))
|
||||||
else:
|
else:
|
||||||
for key, value in urlparse.parse_qsl(query_string, True, True):
|
for key, value in urlparse.parse_qsl(query_string, True, True):
|
||||||
|
@ -348,12 +363,25 @@ class Payment(PaymentCommon):
|
||||||
# decode order id from returned reference
|
# decode order id from returned reference
|
||||||
if ORDERID_TRANSACTION_SEPARATOR in orderid:
|
if ORDERID_TRANSACTION_SEPARATOR in orderid:
|
||||||
orderid, transaction_id = orderid.split(ORDERID_TRANSACTION_SEPARATOR, 1)
|
orderid, transaction_id = orderid.split(ORDERID_TRANSACTION_SEPARATOR, 1)
|
||||||
|
transaction_date = None
|
||||||
|
if 'date_transaction' in d and 'heure_transaction' in d:
|
||||||
|
try:
|
||||||
|
full_date_string = '%sT%s' % (d['date_transaction'][0], d['heure_transaction'][0])
|
||||||
|
transaction_date = datetime.datetime.strptime(full_date_string, '%Y%m%dT%H:%M:%S')
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# We suppose Europe/Paris is the default timezone for Paybox
|
||||||
|
# servers.
|
||||||
|
paris_tz = pytz.timezone(self.timezone)
|
||||||
|
transaction_date = paris_tz.localize(transaction_date)
|
||||||
return PaymentResponse(
|
return PaymentResponse(
|
||||||
order_id=orderid,
|
order_id=orderid,
|
||||||
signed=signed,
|
signed=signed,
|
||||||
bank_data=d,
|
bank_data=d,
|
||||||
result=result,
|
result=result,
|
||||||
bank_status=bank_status)
|
bank_status=bank_status,
|
||||||
|
transaction_date=transaction_date)
|
||||||
|
|
||||||
def perform(self, amount, bank_data, operation):
|
def perform(self, amount, bank_data, operation):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
|
@ -61,14 +61,14 @@ class PayboxTests(TestCase):
|
||||||
'PBX_RANG': '01',
|
'PBX_RANG': '01',
|
||||||
'PBX_SITE': '12345678',
|
'PBX_SITE': '12345678',
|
||||||
'PBX_IDENTIFIANT': '12345678',
|
'PBX_IDENTIFIANT': '12345678',
|
||||||
'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;numero_appel:T;numero_transaction:S;signature:K',
|
'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',
|
||||||
'PBX_TIME': time,
|
'PBX_TIME': time,
|
||||||
'PBX_PORTEUR': email,
|
'PBX_PORTEUR': email,
|
||||||
'PBX_CMD': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction,
|
'PBX_CMD': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction,
|
||||||
'PBX_TOTAL': amount.replace('.', ''),
|
'PBX_TOTAL': amount.replace('.', ''),
|
||||||
'PBX_DEVISE': '978',
|
'PBX_DEVISE': '978',
|
||||||
'PBX_HASH': 'SHA512',
|
'PBX_HASH': 'SHA512',
|
||||||
'PBX_HMAC': '6C70F35F9C6F6C9AB16D1E766EF981D241CB527C2E547205622DFFAF5B1B6C0F47E1DE2D3A1CE579F97AD19F87C3AE63E89B22F4B6D1E118685F5DD977891668',
|
'PBX_HMAC': 'CE29AB421D9FF5E22B52A0F0D31BB881E6D3040B7A0B390AC3F335292A75D2389253A3ED6B3E430A90D30088F6AC29F792B484A2ECFC36A1B73771796A5FD15C',
|
||||||
'PBX_ARCHIVAGE': '1234',
|
'PBX_ARCHIVAGE': '1234',
|
||||||
'PBX_REPONDRE_A': 'http://example.com/callback',
|
'PBX_REPONDRE_A': 'http://example.com/callback',
|
||||||
'PBX_AUTOSEULE': 'N'
|
'PBX_AUTOSEULE': 'N'
|
||||||
|
@ -83,7 +83,7 @@ class PayboxTests(TestCase):
|
||||||
self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value']))
|
self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value']))
|
||||||
name = node.attrib['name']
|
name = node.attrib['name']
|
||||||
form_params[name] = node.attrib['value']
|
form_params[name] = node.attrib['value']
|
||||||
self.assertEqual(form_params, expected_form_values)
|
assert form_params == expected_form_values
|
||||||
|
|
||||||
def test_request_with_capture_day(self):
|
def test_request_with_capture_day(self):
|
||||||
params = BACKEND_PARAMS.copy()
|
params = BACKEND_PARAMS.copy()
|
||||||
|
@ -159,10 +159,17 @@ class PayboxTests(TestCase):
|
||||||
order_id = '20160216'
|
order_id = '20160216'
|
||||||
transaction = '1234'
|
transaction = '1234'
|
||||||
reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction
|
reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction
|
||||||
data = {'montant': '4242', 'reference': reference,
|
data = {
|
||||||
'code_autorisation': 'A', 'erreur': '00000'}
|
'montant': '4242',
|
||||||
|
'reference': reference,
|
||||||
|
'code_autorisation': 'A',
|
||||||
|
'erreur': '00000',
|
||||||
|
'date_transaction': '20200101',
|
||||||
|
'heure_transaction': '01:01:01'}
|
||||||
response = backend.response(urllib.urlencode(data))
|
response = backend.response(urllib.urlencode(data))
|
||||||
self.assertEqual(response.order_id, order_id)
|
self.assertEqual(response.order_id, order_id)
|
||||||
|
assert not response.signed
|
||||||
|
assert response.transaction_date.isoformat() == '2020-01-01T01:01:01+01:00'
|
||||||
|
|
||||||
with self.assertRaisesRegexp(eopayment.ResponseError, 'missing erreur or reference'):
|
with self.assertRaisesRegexp(eopayment.ResponseError, 'missing erreur or reference'):
|
||||||
backend.response('foo=bar')
|
backend.response('foo=bar')
|
||||||
|
|
Loading…
Reference in New Issue