Payment Gateway Integration in Python
Learn how to integrate Zaakpay Payment Gateway in Python. Please follow our Getting started guide to integrate Payment gateway in your website.
Haven't created your account yet?
Please follow our Getting started guide.
1. Installing The Kit
- Download Zaakpay Payment Gateway Python Kit
2. Initiating Payment
- Request parameters must be provided at your site that will further pass to the processTransaction() ( Transaction.py ) for further payment process.
def processTransaction():
#You can also pass these parameters as function arguments
requestParams = RequestParameters.getProcessTransactionParameters()
requestUrl = Config.ENVIRONMENT + Config.TRANSACTION_API_URL
checksumString = Checksum.getChecksumString(requestParams)
checksum = Checksum.calculateChecksum(Config.ZAAKPAY_SECRET_KEY , checksumString)
#Above are all the request parameters you need to pass to initiate transaction
#You need to post all the parameters with checksum to the request URL
- To check the optional and mandatory parameters please refer to this Documentation.
def getProcessTransactionParameters():
amount = 100
orderId = "ZPLive"+str(round(time.time()))
merchantIdentifier = Config.ZAAKPAY_MERCHANT_IDENTIFIER
currency = "INR"
buyerEmail = "[email protected]"
#Add all the parameters ( Mandatory/Optional ) here
params = {"amount":amount,"merchantIdentifier":merchantIdentifier,"orderId":orderId,"currency":currency,"buyerEmail":buyerEmail}
return params
You can also add/remove the optional parameters from getProcessTransactionParameters() ( RequestParameters.py ) .
- All the request parameters including the checksum further redirect to the Zaakpay using the post request as mentioned in Transaction.py .
Also you can print the checksum string and calculated checksum .
def getChecksumString(params):
checksumString = ""
for param in sorted (params.keys()) :
checksumString = str(checksumString+param)+"="+str(params[param])+"&"
return checksumString
Transaction Failing ?
Make sure you are using Live cards for Live Transactions.
-
Once the transaction got completed you will get the Zaakpay's Callback to the path you had provided on returnUrl.
( By default it will redirect to Zaakpay's test response page )
Unable to get Response ?
Please check the Return URL ( Response file path ) is correct and reachable.
3. Featured API's
-
Check API
This is used to check the status of the transaction.
def checkTransactionStatus(orderId):
#You can also pass these parameters as function arguments
requestParams = RequestParameters.getTransactionStatusParameters(orderId)
requestUrl = Config.ENVIRONMENT + Config.TRANSACTION_STATUS_API_URL
data = requestParams['formRequestData']
checksum = Checksum.calculateChecksum(Config.ZAAKPAY_SECRET_KEY , data)
#Above are all the request parameters you need to pass to check transaction status
#You need to post all the parameters with checksum to the request URL
Such that passing the above parameters to getTransactionStatusParameters(orderId) ( Transaction.py ) you can check the status of the transaction.
def getTransactionStatusParameters(orderId):
merchantIdentifier = Config.ZAAKPAY_MERCHANT_IDENTIFIER
mode = "0"
#You can also pass JSON object here to submit in final form request or you can use the below format string
params = {"orderId":orderId,"merchantIdentifier":merchantIdentifier,"mode":mode,"formRequestData":"{merchantIdentifier:"+merchantIdentifier+",mode:"+mode+",orderDetail:{orderId:"+orderId+"}}"}
return params
Also checksum would be calculated on the json data as checksum string.
-
Refund API
This is used to refund the transaction.
You can either initaite full refund or partial refund against a particular transaction.
def partialRefund(orderId,amount):
#You can also pass these parameters as function arguments
requestParams = RequestParameters.getPartialRefundParameters(orderId,amount)
requestUrl = Config.ENVIRONMENT + Config.UPDATE_API_URL
checksumString = Checksum.getUpdateChecksumString(requestParams)
checksum = Checksum.calculateChecksum(Config.ZAAKPAY_SECRET_KEY , checksumString)
#Above are all the request parameters you need to pass to check transaction status
#You need to post all the parameters with checksum to the request URL
def fullRefund(orderId):
#You can also pass these parameters as function arguments
requestParams = RequestParameters.getFullRefundParameters(orderId)
requestUrl = Config.ENVIRONMENT + Config.UPDATE_API_URL
checksumString = Checksum.getUpdateChecksumString(requestParams)
checksum = Checksum.calculateChecksum(Config.ZAAKPAY_SECRET_KEY , checksumString)
#Above are all the request parameters you need to pass to check transaction status
#You need to post all the parameters with checksum to the request URL
Also the checksum string generated here would be a concatenated string all the parameters seperated by single courses as mentioned below .
def getUpdateChecksumString(params):
checksumString = ""
for param in params.keys() :
checksumString = checksumString+'\''+str(params[param])+'\''
return checksumString
Updated almost 4 years ago