Commit eca31be5 authored by Łukasz Nowak's avatar Łukasz Nowak

Simplify and add some comments.

parent 95420164
...@@ -26,6 +26,9 @@ else: ...@@ -26,6 +26,9 @@ else:
SOAP protocol is assumed as untrusted and dangerous, users of those methods SOAP protocol is assumed as untrusted and dangerous, users of those methods
are encouraged to log such messages for future debugging.""" are encouraged to log such messages for future debugging."""
def _check_transcationInfoSignature(self, data): def _check_transcationInfoSignature(self, data):
"""Checks transactionInfo signature
Can raise.
"""
received_sorted_keys = ['errorCode', 'extendedErrorCode', received_sorted_keys = ['errorCode', 'extendedErrorCode',
'transactionStatus', 'shopId', 'paymentMethod', 'contractNumber', 'transactionStatus', 'shopId', 'paymentMethod', 'contractNumber',
'orderId', 'orderInfo', 'orderInfo2', 'orderInfo3', 'transmissionDate', 'orderId', 'orderInfo', 'orderInfo2', 'orderInfo3', 'transmissionDate',
...@@ -44,25 +47,22 @@ else: ...@@ -44,25 +47,22 @@ else:
'refundDevise', 'litige', 'timestamp'] 'refundDevise', 'litige', 'timestamp']
signature = '' signature = ''
for k in received_sorted_keys: for k in received_sorted_keys:
try: v = getattr(data, k, None)
v = getattr(data, k) if v is None:
except AttributeError: # empty or not transmitted: add as empty string
# not transmitted: just add + v = ''
signature += '+' elif k in ['transmissionDate', 'presentationDate', 'cardExpirationDate',
else: 'markDate', 'authDate', 'captureDate'] \
if k in ['transmissionDate', 'presentationDate', 'cardExpirationDate', or isinstance(v, datetime.datetime):
'markDate', 'authDate', 'captureDate']: # dates (or field like dates) shall be converted to YYYYMMDD
# crazyiness again
if isinstance(v, datetime.datetime): if isinstance(v, datetime.datetime):
v = v.strftime('%Y%m%d') v = v.strftime('%Y%m%d')
else: else:
# defensive: maybe date-like field is represented not as datetime?
v = time.strftime('%Y%m%d', time.strptime(str(v), v = time.strftime('%Y%m%d', time.strptime(str(v),
'%Y-%m-%d %H:%M:%S')) '%Y-%m-%d %H:%M:%S'))
if v is not None: # convert to string (there could be ints, longs, etc)
v = str(v) v = str(v)
else:
# empty transmitted: just add +
v = ''
signature += v + '+' signature += v + '+'
signature += self.getServicePassword() signature += self.getServicePassword()
signature = hashlib.sha1(signature).hexdigest() signature = hashlib.sha1(signature).hexdigest()
......
33 34
\ 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