From 5a0b76cf23ff25ba29a2cada438c10914dae74bf Mon Sep 17 00:00:00 2001 From: vidisha-goel Date: Tue, 17 May 2016 16:52:26 +0530 Subject: [PATCH 01/10] version specific kit is uploaded --- pythonKit 3.X/Checksum.py | 118 ++++++++++++++++++++++ pythonKit 3.X/Checksum.py~ | 118 ++++++++++++++++++++++ {pythonKit => pythonKit 3.X}/response.cgi | 0 {pythonKit => pythonKit 3.X}/test.cgi | 0 {pythonKit => pythonKit2.X}/Checksum.py | 0 pythonKit2.X/response.cgi | 34 +++++++ pythonKit2.X/test.cgi | 44 ++++++++ readme.md | 2 +- readme.md~ | 12 +++ 9 files changed, 327 insertions(+), 1 deletion(-) create mode 100755 pythonKit 3.X/Checksum.py create mode 100755 pythonKit 3.X/Checksum.py~ rename {pythonKit => pythonKit 3.X}/response.cgi (100%) rename {pythonKit => pythonKit 3.X}/test.cgi (100%) rename {pythonKit => pythonKit2.X}/Checksum.py (100%) create mode 100755 pythonKit2.X/response.cgi create mode 100755 pythonKit2.X/test.cgi create mode 100644 readme.md~ diff --git a/pythonKit 3.X/Checksum.py b/pythonKit 3.X/Checksum.py new file mode 100755 index 0000000..b7872ac --- /dev/null +++ b/pythonKit 3.X/Checksum.py @@ -0,0 +1,118 @@ +import base64 +import string +import random +import hashlib + +from Crypto.Cipher import AES + + +IV = "@@@@&&&&####$$$$" +BLOCK_SIZE = 16 + + +def generate_checksum(param_dict, merchant_key, salt=None): + params_string = __get_param_string__(param_dict) + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + + +def generate_checksum_by_str(param_str, merchant_key, salt=None): + params_string = param_str + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + + +def verify_checksum(param_dict, merchant_key, checksum): + # Remove checksum + if 'CHECKSUMHASH' in param_dict: + param_dict.pop('CHECKSUMHASH') + + # Get salt + paytm_hash = __decode__(checksum, IV, merchant_key) + salt = paytm_hash[-4:] + calculated_checksum = generate_checksum(param_dict, merchant_key, salt=salt) + return calculated_checksum == checksum + +def verify_checksum_by_str(param_str, merchant_key, checksum): + # Remove checksum + #if 'CHECKSUMHASH' in param_dict: + #param_dict.pop('CHECKSUMHASH') + + # Get salt + paytm_hash = __decode__(checksum, IV, merchant_key) + salt = paytm_hash[-4:] + calculated_checksum = generate_checksum_by_str(param_str, merchant_key, salt=salt) + return calculated_checksum == checksum + + + +def __id_generator__(size=6, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase): + return ''.join(random.choice(chars) for _ in range(size)) + + +def __get_param_string__(params): + params_string = [] + for key in sorted(params.iterkeys()): + value = params[key] + params_string.append('' if value == 'null' else str(value)) + return '|'.join(params_string) + + +__pad__ = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE) +__unpad__ = lambda s: s[0:-ord(s[-1])] + + +def __encode__(to_encode, iv, key): + # Pad + to_encode = __pad__(to_encode) + # Encrypt + c = AES.new(key, AES.MODE_CBC, iv) + to_encode = c.encrypt(to_encode) + # Encode + to_encode = base64.b64encode(to_encode) + return to_encode + + +def __decode__(to_decode, iv, key): + # Decode + to_decode = base64.b64decode(to_decode) + # Decrypt + c = AES.new(key, AES.MODE_CBC, iv) + to_decode = c.decrypt(to_decode) + if type(to_decode) == bytes: + # convert bytes array to str. + to_decode = to_decode.decode() + # remove pad + return __unpad__(to_decode) + + +if __name__ == "__main__": + params = { + "MID": "mid", + "ORDER_ID": "order_id", + "CUST_ID": "cust_id", + "TXN_AMOUNT": "1", + "CHANNEL_ID": "WEB", + "INDUSTRY_TYPE_ID": "Retail", + "WEBSITE": "xxxxxxxxxxx" + } + + print verify_checksum( + params, 'xxxxxxxxxxxxxxxx', + "CD5ndX8VVjlzjWbbYoAtKQIlvtXPypQYOg0Fi2AUYKXZA5XSHiRF0FDj7vQu66S8MHx9NaDZ/uYm3WBOWHf+sDQAmTyxqUipA7i1nILlxrk=") + + # print generate_checksum(params, "xxxxxxxxxxxxxxxx") diff --git a/pythonKit 3.X/Checksum.py~ b/pythonKit 3.X/Checksum.py~ new file mode 100755 index 0000000..b7872ac --- /dev/null +++ b/pythonKit 3.X/Checksum.py~ @@ -0,0 +1,118 @@ +import base64 +import string +import random +import hashlib + +from Crypto.Cipher import AES + + +IV = "@@@@&&&&####$$$$" +BLOCK_SIZE = 16 + + +def generate_checksum(param_dict, merchant_key, salt=None): + params_string = __get_param_string__(param_dict) + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + + +def generate_checksum_by_str(param_str, merchant_key, salt=None): + params_string = param_str + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + + +def verify_checksum(param_dict, merchant_key, checksum): + # Remove checksum + if 'CHECKSUMHASH' in param_dict: + param_dict.pop('CHECKSUMHASH') + + # Get salt + paytm_hash = __decode__(checksum, IV, merchant_key) + salt = paytm_hash[-4:] + calculated_checksum = generate_checksum(param_dict, merchant_key, salt=salt) + return calculated_checksum == checksum + +def verify_checksum_by_str(param_str, merchant_key, checksum): + # Remove checksum + #if 'CHECKSUMHASH' in param_dict: + #param_dict.pop('CHECKSUMHASH') + + # Get salt + paytm_hash = __decode__(checksum, IV, merchant_key) + salt = paytm_hash[-4:] + calculated_checksum = generate_checksum_by_str(param_str, merchant_key, salt=salt) + return calculated_checksum == checksum + + + +def __id_generator__(size=6, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase): + return ''.join(random.choice(chars) for _ in range(size)) + + +def __get_param_string__(params): + params_string = [] + for key in sorted(params.iterkeys()): + value = params[key] + params_string.append('' if value == 'null' else str(value)) + return '|'.join(params_string) + + +__pad__ = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE) +__unpad__ = lambda s: s[0:-ord(s[-1])] + + +def __encode__(to_encode, iv, key): + # Pad + to_encode = __pad__(to_encode) + # Encrypt + c = AES.new(key, AES.MODE_CBC, iv) + to_encode = c.encrypt(to_encode) + # Encode + to_encode = base64.b64encode(to_encode) + return to_encode + + +def __decode__(to_decode, iv, key): + # Decode + to_decode = base64.b64decode(to_decode) + # Decrypt + c = AES.new(key, AES.MODE_CBC, iv) + to_decode = c.decrypt(to_decode) + if type(to_decode) == bytes: + # convert bytes array to str. + to_decode = to_decode.decode() + # remove pad + return __unpad__(to_decode) + + +if __name__ == "__main__": + params = { + "MID": "mid", + "ORDER_ID": "order_id", + "CUST_ID": "cust_id", + "TXN_AMOUNT": "1", + "CHANNEL_ID": "WEB", + "INDUSTRY_TYPE_ID": "Retail", + "WEBSITE": "xxxxxxxxxxx" + } + + print verify_checksum( + params, 'xxxxxxxxxxxxxxxx', + "CD5ndX8VVjlzjWbbYoAtKQIlvtXPypQYOg0Fi2AUYKXZA5XSHiRF0FDj7vQu66S8MHx9NaDZ/uYm3WBOWHf+sDQAmTyxqUipA7i1nILlxrk=") + + # print generate_checksum(params, "xxxxxxxxxxxxxxxx") diff --git a/pythonKit/response.cgi b/pythonKit 3.X/response.cgi similarity index 100% rename from pythonKit/response.cgi rename to pythonKit 3.X/response.cgi diff --git a/pythonKit/test.cgi b/pythonKit 3.X/test.cgi similarity index 100% rename from pythonKit/test.cgi rename to pythonKit 3.X/test.cgi diff --git a/pythonKit/Checksum.py b/pythonKit2.X/Checksum.py similarity index 100% rename from pythonKit/Checksum.py rename to pythonKit2.X/Checksum.py diff --git a/pythonKit2.X/response.cgi b/pythonKit2.X/response.cgi new file mode 100755 index 0000000..a2bd862 --- /dev/null +++ b/pythonKit2.X/response.cgi @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import Checksum +import requests +import base64 +import json +import requests + +print "Content-type: text/html\n" +MERCHANT_KEY = 'kbzk1DSbJiV_O3p5'; +import cgi + +form = cgi.FieldStorage() +respons_dict = {} + +for i in form.keys(): + respons_dict[i]=form[i].value + if i=='CHECKSUMHASH': + checksum = form[i].value + +if 'GATEWAYNAME' in respons_dict: + if respons_dict['GATEWAYNAME'] == 'WALLET': + respons_dict['BANKNAME'] = 'null'; + +verify = Checksum.verify_checksum(respons_dict, MERCHANT_KEY, checksum) +print verify + +if verify: + if respons_dict['RESPCODE'] == '01': + print "order successful"; + else: + print "order unsuccessful because"+respons_dict['RESPMSG']; +else: + print "order unsuccessful because"+respons_dict['RESPMSG']; diff --git a/pythonKit2.X/test.cgi b/pythonKit2.X/test.cgi new file mode 100755 index 0000000..eff83e0 --- /dev/null +++ b/pythonKit2.X/test.cgi @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import Checksum +import requests +import base64 +import json +print "Content-type: text/html\n" + + +MERCHANT_KEY = 'kbzk1DSbJiV_O3p5'; +data_dict = { + 'MID':'WorldP64425807474247', + 'ORDER_ID':'dddgfgfeeed', + 'TXN_AMOUNT':'1', + 'CUST_ID':'acfff@paytm.com', + 'INDUSTRY_TYPE_ID':'Retail', + 'WEBSITE':'worldpressplg', + 'CHANNEL_ID':'WEB', + #'CALLBACK_URL':'http://localhost/pythonKit/response.cgi', + } + + +param_dict = data_dict +param_dict['CHECKSUMHASH'] =Checksum.generate_checksum(data_dict, MERCHANT_KEY) + + + +#for key in param_dict: + # print key.strip()+param_dict[key].strip() + +print '

Merchant Check Out Page


' +print '
' +print '' +print '' +for key in param_dict: + print '' +print '' +print '
' +print '' +print '
' + + diff --git a/readme.md b/readme.md index 5ee5191..df8c64e 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ This sample kit is ready to be deployed and tested. # Instructions - 1. Copy the *pythonKit* folder into the root folder of your server (like /var/www/html) + 1. Copy the *pythonKit* folder(according to ypur python version) into the root folder of your server (like /var/www/html) 2. **Mandatory Step**: For each test transaction, please change the value of the parameter "ORDER_ID" in the test.cgi file. # Usage Description diff --git a/readme.md~ b/readme.md~ new file mode 100644 index 0000000..df8c64e --- /dev/null +++ b/readme.md~ @@ -0,0 +1,12 @@ +# Introduction +This sample kit is ready to be deployed and tested. + +# Instructions + 1. Copy the *pythonKit* folder(according to ypur python version) into the root folder of your server (like /var/www/html) + 2. **Mandatory Step**: For each test transaction, please change the value of the parameter "ORDER_ID" in the test.cgi file. + +# Usage Description +The *pythonKit* folder has the following files: + 1. CheckSum.py – This file has the logic for checksum generation and verification. + 2. test.cgi – This file will initiate the sample test transaction through the Paytm gateway. Paytm parameters need to be added in this file. + 3. response.cgi – This file has the logic for processing PG response after the transaction processing. From 91593a78002923b3fd764722d72067ae346ca85c Mon Sep 17 00:00:00 2001 From: vidisha-goel Date: Tue, 17 May 2016 17:03:39 +0530 Subject: [PATCH 02/10] version specific kit is uploaded --- readme.md~ | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 readme.md~ diff --git a/readme.md~ b/readme.md~ deleted file mode 100644 index df8c64e..0000000 --- a/readme.md~ +++ /dev/null @@ -1,12 +0,0 @@ -# Introduction -This sample kit is ready to be deployed and tested. - -# Instructions - 1. Copy the *pythonKit* folder(according to ypur python version) into the root folder of your server (like /var/www/html) - 2. **Mandatory Step**: For each test transaction, please change the value of the parameter "ORDER_ID" in the test.cgi file. - -# Usage Description -The *pythonKit* folder has the following files: - 1. CheckSum.py – This file has the logic for checksum generation and verification. - 2. test.cgi – This file will initiate the sample test transaction through the Paytm gateway. Paytm parameters need to be added in this file. - 3. response.cgi – This file has the logic for processing PG response after the transaction processing. From 36364799cb3fd2b4a724b3495c0216346aba0ec1 Mon Sep 17 00:00:00 2001 From: vidisha-goel Date: Tue, 17 May 2016 17:07:23 +0530 Subject: [PATCH 03/10] version specific kit is uploaded --- pythonKit 3.X/Checksum.py~ | 118 ------------------------------------- 1 file changed, 118 deletions(-) delete mode 100755 pythonKit 3.X/Checksum.py~ diff --git a/pythonKit 3.X/Checksum.py~ b/pythonKit 3.X/Checksum.py~ deleted file mode 100755 index b7872ac..0000000 --- a/pythonKit 3.X/Checksum.py~ +++ /dev/null @@ -1,118 +0,0 @@ -import base64 -import string -import random -import hashlib - -from Crypto.Cipher import AES - - -IV = "@@@@&&&&####$$$$" -BLOCK_SIZE = 16 - - -def generate_checksum(param_dict, merchant_key, salt=None): - params_string = __get_param_string__(param_dict) - salt = salt if salt else __id_generator__(4) - final_string = '%s|%s' % (params_string, salt) - - hasher = hashlib.sha256(final_string.encode()) - hash_string = hasher.hexdigest() - - hash_string += salt - - return __encode__(hash_string, IV, merchant_key) - - -def generate_checksum_by_str(param_str, merchant_key, salt=None): - params_string = param_str - salt = salt if salt else __id_generator__(4) - final_string = '%s|%s' % (params_string, salt) - - hasher = hashlib.sha256(final_string.encode()) - hash_string = hasher.hexdigest() - - hash_string += salt - - return __encode__(hash_string, IV, merchant_key) - - -def verify_checksum(param_dict, merchant_key, checksum): - # Remove checksum - if 'CHECKSUMHASH' in param_dict: - param_dict.pop('CHECKSUMHASH') - - # Get salt - paytm_hash = __decode__(checksum, IV, merchant_key) - salt = paytm_hash[-4:] - calculated_checksum = generate_checksum(param_dict, merchant_key, salt=salt) - return calculated_checksum == checksum - -def verify_checksum_by_str(param_str, merchant_key, checksum): - # Remove checksum - #if 'CHECKSUMHASH' in param_dict: - #param_dict.pop('CHECKSUMHASH') - - # Get salt - paytm_hash = __decode__(checksum, IV, merchant_key) - salt = paytm_hash[-4:] - calculated_checksum = generate_checksum_by_str(param_str, merchant_key, salt=salt) - return calculated_checksum == checksum - - - -def __id_generator__(size=6, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase): - return ''.join(random.choice(chars) for _ in range(size)) - - -def __get_param_string__(params): - params_string = [] - for key in sorted(params.iterkeys()): - value = params[key] - params_string.append('' if value == 'null' else str(value)) - return '|'.join(params_string) - - -__pad__ = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE) -__unpad__ = lambda s: s[0:-ord(s[-1])] - - -def __encode__(to_encode, iv, key): - # Pad - to_encode = __pad__(to_encode) - # Encrypt - c = AES.new(key, AES.MODE_CBC, iv) - to_encode = c.encrypt(to_encode) - # Encode - to_encode = base64.b64encode(to_encode) - return to_encode - - -def __decode__(to_decode, iv, key): - # Decode - to_decode = base64.b64decode(to_decode) - # Decrypt - c = AES.new(key, AES.MODE_CBC, iv) - to_decode = c.decrypt(to_decode) - if type(to_decode) == bytes: - # convert bytes array to str. - to_decode = to_decode.decode() - # remove pad - return __unpad__(to_decode) - - -if __name__ == "__main__": - params = { - "MID": "mid", - "ORDER_ID": "order_id", - "CUST_ID": "cust_id", - "TXN_AMOUNT": "1", - "CHANNEL_ID": "WEB", - "INDUSTRY_TYPE_ID": "Retail", - "WEBSITE": "xxxxxxxxxxx" - } - - print verify_checksum( - params, 'xxxxxxxxxxxxxxxx', - "CD5ndX8VVjlzjWbbYoAtKQIlvtXPypQYOg0Fi2AUYKXZA5XSHiRF0FDj7vQu66S8MHx9NaDZ/uYm3WBOWHf+sDQAmTyxqUipA7i1nILlxrk=") - - # print generate_checksum(params, "xxxxxxxxxxxxxxxx") From 7688d4479782ba230283774308d06c4f9add0065 Mon Sep 17 00:00:00 2001 From: vidisha-goel Date: Wed, 18 May 2016 18:50:13 +0530 Subject: [PATCH 04/10] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index df8c64e..7e27138 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ This sample kit is ready to be deployed and tested. # Instructions - 1. Copy the *pythonKit* folder(according to ypur python version) into the root folder of your server (like /var/www/html) + 1. Copy the *pythonKit* folder(according to your python version) into the root folder of your server (like /var/www/html) 2. **Mandatory Step**: For each test transaction, please change the value of the parameter "ORDER_ID" in the test.cgi file. # Usage Description From aa16b80ac3bc36b9dfad24b284f966da7f7ebec6 Mon Sep 17 00:00:00 2001 From: vidisha-goel Date: Thu, 13 Oct 2016 11:13:49 +0530 Subject: [PATCH 05/10] Update Readme --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 7e27138..e855161 100644 --- a/readme.md +++ b/readme.md @@ -10,3 +10,7 @@ The *pythonKit* folder has the following files: 1. CheckSum.py – This file has the logic for checksum generation and verification. 2. test.cgi – This file will initiate the sample test transaction through the Paytm gateway. Paytm parameters need to be added in this file. 3. response.cgi – This file has the logic for processing PG response after the transaction processing. + + # For Offline(Wallet Api) Checksum Utility below are the methods: + 1. generate_checksum_by_str : For generating the checksum + 2. verify_checksum_by_str : For verifing the checksum From 7e3b5a07369ee67666245a58343a38232a54770b Mon Sep 17 00:00:00 2001 From: aabhishekgoyal Date: Tue, 23 May 2017 17:48:02 +0530 Subject: [PATCH 06/10] Python Kit Update --- pythonKit 3.X/Checksum.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pythonKit 3.X/Checksum.py b/pythonKit 3.X/Checksum.py index b7872ac..dbeb5ed 100755 --- a/pythonKit 3.X/Checksum.py +++ b/pythonKit 3.X/Checksum.py @@ -22,6 +22,22 @@ def generate_checksum(param_dict, merchant_key, salt=None): return __encode__(hash_string, IV, merchant_key) +def generate_refund_checksum(param_dict, merchant_key, salt=None): + for i in param_dict: + if("|" in param_dict[i]): + param_dict = {} + exit() + params_string = __get_param_string__(param_dict) + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + def generate_checksum_by_str(param_str, merchant_key, salt=None): params_string = param_str From ed39e1cd410f07046e51177ff74d32e592edce01 Mon Sep 17 00:00:00 2001 From: aabhishekgoyal Date: Tue, 23 May 2017 17:49:37 +0530 Subject: [PATCH 07/10] Python Kit Update --- pythonKit2.X/Checksum.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pythonKit2.X/Checksum.py b/pythonKit2.X/Checksum.py index 6282d87..34575bd 100755 --- a/pythonKit2.X/Checksum.py +++ b/pythonKit2.X/Checksum.py @@ -22,6 +22,22 @@ def generate_checksum(param_dict, merchant_key, salt=None): return __encode__(hash_string, IV, merchant_key) +def generate_refund_checksum(param_dict, merchant_key, salt=None): + for i in param_dict: + if("|" in param_dict[i]): + param_dict = {} + exit() + params_string = __get_param_string__(param_dict) + salt = salt if salt else __id_generator__(4) + final_string = '%s|%s' % (params_string, salt) + + hasher = hashlib.sha256(final_string.encode()) + hash_string = hasher.hexdigest() + + hash_string += salt + + return __encode__(hash_string, IV, merchant_key) + def generate_checksum_by_str(param_str, merchant_key, salt=None): params_string = param_str From a4e1bff157e31993e6da5150c98262ab09676e32 Mon Sep 17 00:00:00 2001 From: aabhishekgoyal Date: Tue, 23 May 2017 18:20:10 +0530 Subject: [PATCH 08/10] Python Kit Update --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index e855161..13fcfa7 100644 --- a/readme.md +++ b/readme.md @@ -14,3 +14,9 @@ The *pythonKit* folder has the following files: # For Offline(Wallet Api) Checksum Utility below are the methods: 1. generate_checksum_by_str : For generating the checksum 2. verify_checksum_by_str : For verifing the checksum + +# To generate refund checksum in Python : + 1. Create an array with key value pair of following paytm parameters + (MID, ORDERID, TXNTYPE, REFUNDAMOUNT, TXNID, REFID) + 2. To generate checksum, call the following method. This function returns the checksum as a string. + generate_refund_checksum(param_dict, merchant_key, salt=None) From f727d2d0e473f6496456ac37a683369240020a76 Mon Sep 17 00:00:00 2001 From: Prabhat Mishra <35480210+Prabhat1Mishra@users.noreply.github.com> Date: Tue, 6 Mar 2018 12:34:58 +0530 Subject: [PATCH 09/10] Upgraded to PGP... --- pythonKit2.X/test.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonKit2.X/test.cgi b/pythonKit2.X/test.cgi index eff83e0..d0b22b3 100755 --- a/pythonKit2.X/test.cgi +++ b/pythonKit2.X/test.cgi @@ -29,7 +29,7 @@ param_dict['CHECKSUMHASH'] =Checksum.generate_checksum(data_dict, MERCHANT_KEY) # print key.strip()+param_dict[key].strip() print '

Merchant Check Out Page


' -print '
' +print '' print '' print '' for key in param_dict: From fd08bb96db6bb60f02483e6fa7f6f1712278fe4b Mon Sep 17 00:00:00 2001 From: Rahul Verma Date: Fri, 14 Sep 2018 12:03:10 +0530 Subject: [PATCH 10/10] utility updated for python3 --- pythonKit 3.X/Checksum.py | 19 +++++++++++-------- pythonKit 3.X/response.cgi | 12 ++++++------ pythonKit 3.X/test.cgi | 24 +++++++++--------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/pythonKit 3.X/Checksum.py b/pythonKit 3.X/Checksum.py index dbeb5ed..9d90af2 100755 --- a/pythonKit 3.X/Checksum.py +++ b/pythonKit 3.X/Checksum.py @@ -24,9 +24,9 @@ def generate_checksum(param_dict, merchant_key, salt=None): def generate_refund_checksum(param_dict, merchant_key, salt=None): for i in param_dict: - if("|" in param_dict[i]): - param_dict = {} - exit() + if("|" in param_dict[i]): + param_dict = {} + exit() params_string = __get_param_string__(param_dict) salt = salt if salt else __id_generator__(4) final_string = '%s|%s' % (params_string, salt) @@ -82,7 +82,10 @@ def __id_generator__(size=6, chars=string.ascii_uppercase + string.digits + stri def __get_param_string__(params): params_string = [] - for key in sorted(params.iterkeys()): + for key in sorted(params.keys()): + if("REFUND" in params[key] or "|" in params[key]): + respons_dict = {} + exit() value = params[key] params_string.append('' if value == 'null' else str(value)) return '|'.join(params_string) @@ -100,7 +103,7 @@ def __encode__(to_encode, iv, key): to_encode = c.encrypt(to_encode) # Encode to_encode = base64.b64encode(to_encode) - return to_encode + return to_encode.decode("UTF-8") def __decode__(to_decode, iv, key): @@ -127,8 +130,8 @@ def __decode__(to_decode, iv, key): "WEBSITE": "xxxxxxxxxxx" } - print verify_checksum( + print(verify_checksum( params, 'xxxxxxxxxxxxxxxx', - "CD5ndX8VVjlzjWbbYoAtKQIlvtXPypQYOg0Fi2AUYKXZA5XSHiRF0FDj7vQu66S8MHx9NaDZ/uYm3WBOWHf+sDQAmTyxqUipA7i1nILlxrk=") + "CD5ndX8VVjlzjWbbYoAtKQIlvtXPypQYOg0Fi2AUYKXZA5XSHiRF0FDj7vQu66S8MHx9NaDZ/uYm3WBOWHf+sDQAmTyxqUipA7i1nILlxrk=")) - # print generate_checksum(params, "xxxxxxxxxxxxxxxx") + # print(generate_checksum(params, "xxxxxxxxxxxxxxxx")) diff --git a/pythonKit 3.X/response.cgi b/pythonKit 3.X/response.cgi index a2bd862..a6a3489 100755 --- a/pythonKit 3.X/response.cgi +++ b/pythonKit 3.X/response.cgi @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import Checksum import requests @@ -6,8 +6,8 @@ import base64 import json import requests -print "Content-type: text/html\n" -MERCHANT_KEY = 'kbzk1DSbJiV_O3p5'; +print("Content-type: text/html\n") +MERCHANT_KEY = 'xxxxxxxxxxxxxxxx'; import cgi form = cgi.FieldStorage() @@ -27,8 +27,8 @@ print verify if verify: if respons_dict['RESPCODE'] == '01': - print "order successful"; + print("order successful") else: - print "order unsuccessful because"+respons_dict['RESPMSG']; + print("order unsuccessful because"+respons_dict['RESPMSG']) else: - print "order unsuccessful because"+respons_dict['RESPMSG']; + print("order unsuccessful because"+respons_dict['RESPMSG']) diff --git a/pythonKit 3.X/test.cgi b/pythonKit 3.X/test.cgi index eff83e0..5982630 100755 --- a/pythonKit 3.X/test.cgi +++ b/pythonKit 3.X/test.cgi @@ -4,7 +4,7 @@ import Checksum import requests import base64 import json -print "Content-type: text/html\n" +print("Content-type: text/html\n") MERCHANT_KEY = 'kbzk1DSbJiV_O3p5'; @@ -26,19 +26,13 @@ param_dict['CHECKSUMHASH'] =Checksum.generate_checksum(data_dict, MERCHANT_KEY) #for key in param_dict: - # print key.strip()+param_dict[key].strip() + # print(key.strip()+param_dict[key].strip()) -print '

Merchant Check Out Page


' -print '' -print '
' -print '' +print('

Merchant Check Out Page


') +print('') for key in param_dict: - print '' -print '' -print '
' -print '' -print '
' - - + print('') +print('') +print('')