summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2020-04-04 11:04:58 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2020-04-10 09:39:38 (GMT)
commitbaa769d498a50d653a12e736df8d77335eba2521 (patch)
tree44d972c667e3a7c52cf0a8a85d727bd58e3cf464
parenta3307e0a47aa912df61bd21f71f7409903497f68 (diff)
downloadeopayment-baa769d498a50d653a12e736df8d77335eba2521.zip
eopayment-baa769d498a50d653a12e736df8d77335eba2521.tar.gz
eopayment-baa769d498a50d653a12e736df8d77335eba2521.tar.bz2
sips2: use transaction_date (#41320)
-rw-r--r--eopayment/sips2.py21
-rw-r--r--tests/test_sips2.py9
2 files changed, 28 insertions, 2 deletions
diff --git a/eopayment/sips2.py b/eopayment/sips2.py
index 7b8de2d..80dfd2b 100644
--- a/eopayment/sips2.py
+++ b/eopayment/sips2.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+import datetime
from decimal import Decimal
from gettext import gettext as _
import collections
@@ -14,6 +15,8 @@ from six.moves.urllib import parse as urlparse
import requests
+import pytz
+
from .common import (PaymentCommon, FORM, Form, PaymentResponse, PAID, ERROR,
CANCELED, ResponseError, force_text)
@@ -137,6 +140,12 @@ class Payment(PaymentCommon):
'name': 'payment_means',
'caption': _('Payment Means'),
'required': False
+ },
+ {
+ 'name': 'timezone',
+ 'caption': _('SIPS server Timezone'),
+ 'default': 'Europe/Paris',
+ 'required': False,
}
],
}
@@ -243,6 +252,15 @@ class Payment(PaymentCommon):
result = self.response_code_to_result.get(response_code, ERROR)
merchant_id = data.get('merchantId')
test = merchant_id == self.TEST_MERCHANT_ID
+ transaction_date = None
+ if 'transactionDateTime' in data:
+ try:
+ transaction_date = datetime.datetime.strptime(data['transactionDateTime'], '%Y-%m-%d %H:%M:%S')
+ except (ValueError, TypeError):
+ pass
+ else:
+ sips_tz = pytz.timezone(self.timezone)
+ transaction_date = sips_tz.localize(transaction_date)
return PaymentResponse(
result=result,
signed=signed,
@@ -250,7 +268,8 @@ class Payment(PaymentCommon):
order_id=transaction_id,
transaction_id=data.get('authorisationId'),
bank_status=self.RESPONSE_CODES.get(response_code, u'unknown code - ' + response_code),
- test=test)
+ test=test,
+ transaction_date=transaction_date)
def get_seal_for_json_ws_data(self, data):
data_to_send = []
diff --git a/tests/test_sips2.py b/tests/test_sips2.py
index 563c75b..fe8c4d5 100644
--- a/tests/test_sips2.py
+++ b/tests/test_sips2.py
@@ -37,7 +37,14 @@ def test_options():
def test_parse_response():
qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode='''
backend = eopayment.Payment('sips2', {})
- assert backend.response(qs)
+ response = backend.response(qs)
+ assert response.signed
+ assert response.transaction_date is None
+
+ qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT%7CtransactionDateTime%3D2020-01-01%2001:01:01&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode='''
+ response = backend.response(qs)
+ assert not response.signed
+ assert response.transaction_date.isoformat() == '2020-01-01T01:01:01+01:00'
with pytest.raises(eopayment.ResponseError, match='missing Data, Seal or InterfaceVersion'):
backend.response('foo=bar')