Commit 15d620ed authored by Łukasz Nowak's avatar Łukasz Nowak

Force UTC usage.

PayZen interface expectes all dates in UTC, but suds library is not configurable.
So force UTC usage while importing and using suds, so no date mangling will happen.
parent fed1799d
...@@ -6,13 +6,41 @@ from Products.ERP5Type.Document import newTempDocument ...@@ -6,13 +6,41 @@ from Products.ERP5Type.Document import newTempDocument
import hashlib import hashlib
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
import datetime import datetime
import os
import time
present = False
tz = None
if 'TZ' in os.environ:
present = True
tz = os.environ['TZ']
os.environ['TZ'] = 'UTC'
time.tzset()
try: try:
import suds import suds
except ImportError: except ImportError:
class PayzenSOAP: class PayzenSOAP:
pass pass
else: else:
def setUTCTimeZone(fn):
def wrapped(*args, **kwargs):
present = False
tz = None
if 'TZ' in os.environ:
present = True
tz = os.environ['TZ']
os.environ['TZ'] = 'UTC'
time.tzset()
try:
return fn(*args, **kwargs)
finally:
if present:
os.environ['TZ'] = tz
else:
del(os.environ['TZ'])
time.tzset()
return wrapped
class PayzenSOAP: class PayzenSOAP:
"""SOAP communication """SOAP communication
...@@ -48,6 +76,7 @@ else: ...@@ -48,6 +76,7 @@ else:
signature = self._getSignature(data, received_sorted_keys) signature = self._getSignature(data, received_sorted_keys)
return signature == data.signature return signature == data.signature
@setUTCTimeZone
def soap_getInfo(self, transmissionDate, transactionId): def soap_getInfo(self, transmissionDate, transactionId):
"""Returns getInfo as dict, booelan, string, string """Returns getInfo as dict, booelan, string, string
...@@ -106,6 +135,7 @@ else: ...@@ -106,6 +135,7 @@ else:
return [data_kw, signature, last_sent, last_received] return [data_kw, signature, last_sent, last_received]
@setUTCTimeZone
def soap_duplicate(self, transmissionDate, transactionId, presentationDate, def soap_duplicate(self, transmissionDate, transactionId, presentationDate,
newTransactionId, amount, devise, orderId='', orderInfo='', orderInfo2='', newTransactionId, amount, devise, orderId='', orderInfo='', orderInfo2='',
orderInfo3='', validationMode=0, comment=''): orderInfo3='', validationMode=0, comment=''):
...@@ -166,6 +196,12 @@ else: ...@@ -166,6 +196,12 @@ else:
signature = False signature = False
return [data_kw, signature, last_sent, last_received] return [data_kw, signature, last_sent, last_received]
finally:
if present:
os.environ['TZ'] = tz
else:
del(os.environ['TZ'])
time.tzset()
class PayzenService(XMLObject, PayzenSOAP): class PayzenService(XMLObject, PayzenSOAP):
meta_type = 'Payzen Service' meta_type = 'Payzen Service'
...@@ -211,6 +247,7 @@ class PayzenService(XMLObject, PayzenSOAP): ...@@ -211,6 +247,7 @@ class PayzenService(XMLObject, PayzenSOAP):
elif isinstance(v, datetime.datetime): elif isinstance(v, datetime.datetime):
# for sure date # for sure date
v = v.strftime('%Y%m%d') v = v.strftime('%Y%m%d')
# import ipdb ; ipdb.set_trace()
else: else:
# anything else cast to string # anything else cast to string
v = str(v) v = str(v)
......
47 48
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment