Skip to content

Commit

Permalink
added: ipn hash validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shahedex committed Apr 21, 2020
1 parent 299cb2d commit f4f80db
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion sslcommerz_python/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from uuid import uuid4
import requests
import json
import hashlib

import sslcommerz_python._constants as const

Expand Down Expand Up @@ -120,4 +121,39 @@ def validate_transaction(self, validation_id):
else:
response_data['status'] = 'FAILED'
response_data['data'] = 'Validation failed due to status code ' + str(validation_response.status_code)
return response_data
return response_data


def validate_ipn_hash(self, ipn_data):
if self.key_check(ipn_data, 'verify_key') and self.key_check(ipn_data, 'verify_sign'):
check_params : Dict[str, str] = {}
verify_key = ipn_data['verify_key'].split(',')

for key in verify_key:
check_params[key] = ipn_data[key]

store_pass = self.sslc_store_pass.encode()
store_pass_hash = hashlib.md5(store_pass).hexdigest()
check_params['store_passwd'] = store_pass_hash
check_params = self.sort_keys(check_params)

sign_string = ''
for key in check_params:
sign_string += key[0] + '=' + str(key[1]) + '&'

sign_string = sign_string.strip('&')
sign_string_hash = hashlib.md5(sign_string.encode()).hexdigest()

if sign_string_hash == ipn_data['verify_sign']:
return True
return False

@staticmethod
def key_check(data_dict, check_key):
if check_key in data_dict.keys():
return True
return False

@staticmethod
def sort_keys(data_dict):
return [(key, data_dict[k]) for key in sorted(data_dict.keys())]

0 comments on commit f4f80db

Please sign in to comment.