pip install django-billdesk
MID = '<merchant-id>'
SEC_ID = '<sercet-id>'
BILL_URL = 'https://uat.billdesk.com/pgidsk/PGIMerchantPayment'
CONF_BILL_URL = 'https://uat.billdesk.com/pgidsk/PGIQueryController'
CHECKSUM_KEY = '<checksum-key>'
REVERSE_URL = '<reverse url>'
To know excatly what these variables mean have at look at my gist
Now to use this in your project,you simply need to dofrom django_billdesk import ResponseMessage, GetMessage
msg = GetMessage().message(uniqueID, amount, ExInfo1, ExInfo2, ExInfo3, ExInfo4)
NOTE:
- uniqueID mentioned above should be truely unique for all the transactions requested by you.If not, the transaction will be declined by billdesk.
- The order of arguments being passed should not be changed.
- Atleast 4 (billdesk says 3 but for extra security) ExtraInfo should be passed about the transaction.
For ex - emailId of person making transaction, his phone number, his name, his ID in your company or website.
Suggested format
msg = GetMessage().message(uniqueID, amount, some_id, email, name, mnumber)
Important : some_id shouldn't be confused with uniqueID. uniqueID will be created by you everytime a transaction is requested and is ensured that it is truely unique and never before has any request been made with the same id, whereas some_id is the id which you allocate to a user when he or she registers on your site.
So a same person, when will make multiple transactions, will have same 'some_id' but different uniqueID
values = ResponseMessage.respMsg(<The response msg>)
Note :
- Make sure your function which is called at response url is csrf exempted as you are receiving a POST request from a website outside of your domain.
- You will get a dictionary in the variable 'values' as mentioned above. But before doing anything make sure the variable 'values' is not False.
if values not False:
<do everything in here>
cuz if the value is false, it means there had been a breach as Checksum verification failed.
Now you can update your database based on the response and values in the variable 'values'Structure of 'values':
{'MID': '', 'OrderID': '', 'TaxnNo': '', 'AMNT': '', 'TStat': '', 'DnT': '', 'TMode': ''}
All the variables in the dictionary above will hold values as received in the response message from billdesk
- MID = will hold the merchant ID to which payment was made
- OrderID = will hold the unique order id for the transaction
- TaxnNo = will hold the unique taxation number generated by the respective bank
- AMNT = will hold the amount for which the transaction was made
- TStat = will hold the transaction status number. See the possible outcomes and their meaning
- DnT = will hold the date and time at which the transaction was made.
- TMode = will hold the mode of transaction. For ex- UPI, Internet Banking.
msg = GetMessage().schedule_msg(uniqueID)
'msg' will have the message to be sent using POST method.
NOTE :You can Python's requests
module to send POST requests to the Query API but while sending POST requests for the payment request,you need to do it from template forms like this so that the user can be properly redirected to billdesk page.
<html>
<body>
<form action="{{url}}" method="post" name="billdesk">
<input name="msg" type="hidden" value="{{msg}}">
</form>
</body>
<script>
document.billdesk.submit();
</script>
</html>
values = ResponseMessage.schedule_resp(<the recieved response>)
Now again proceed only after making sure that values is not equal to False.If it is not,then it will hold a dictionary with the following structure.
{'MID': '', 'OrderID': '', 'TaxnNo': '', 'AMNT': '', 'TStat': '', 'RfndStat': ''}
Variables have their usual meaning as stated above.RfndStat
contains the refund status of the transaction.
Important Always use combination of auth status and refund status to update you database.