33from uuid import uuid4
44import requests
55import json
6+ import hashlib
67
78import sslcommerz_python ._constants as const
89
@@ -120,4 +121,39 @@ def validate_transaction(self, validation_id):
120121 else :
121122 response_data ['status' ] = 'FAILED'
122123 response_data ['data' ] = 'Validation failed due to status code ' + str (validation_response .status_code )
123- return response_data
124+ return response_data
125+
126+
127+ def validate_ipn_hash (self , ipn_data ):
128+ if self .key_check (ipn_data , 'verify_key' ) and self .key_check (ipn_data , 'verify_sign' ):
129+ check_params : Dict [str , str ] = {}
130+ verify_key = ipn_data ['verify_key' ].split (',' )
131+
132+ for key in verify_key :
133+ check_params [key ] = ipn_data [key ]
134+
135+ store_pass = self .sslc_store_pass .encode ()
136+ store_pass_hash = hashlib .md5 (store_pass ).hexdigest ()
137+ check_params ['store_passwd' ] = store_pass_hash
138+ check_params = self .sort_keys (check_params )
139+
140+ sign_string = ''
141+ for key in check_params :
142+ sign_string += key [0 ] + '=' + str (key [1 ]) + '&'
143+
144+ sign_string = sign_string .strip ('&' )
145+ sign_string_hash = hashlib .md5 (sign_string .encode ()).hexdigest ()
146+
147+ if sign_string_hash == ipn_data ['verify_sign' ]:
148+ return True
149+ return False
150+
151+ @staticmethod
152+ def key_check (data_dict , check_key ):
153+ if check_key in data_dict .keys ():
154+ return True
155+ return False
156+
157+ @staticmethod
158+ def sort_keys (data_dict ):
159+ return [(key , data_dict [k ]) for key in sorted (data_dict .keys ())]
0 commit comments