Here below I want to share how a bill desk payment gateway can be integrated into a website. Last week I tried to integrate it and I am sharing how I did it. Hope it may help you to some extent.
The approach between the merchant (i.e. User/Service Provider) website and Bill Desk is described below:
Merchant website constructs a pipe separated message [‘|’] containing some key inputs such as:
o. Order Number – is a unique reference generated by Merchant for each transaction initiated by Merchant
o. Amount – is the transaction amount
o. Unique Customer Reference Number
o. Payment Options
o. Return Response URL
Message Details Format
NOTE : MerchantID, SecurityID and ChecksumKey is provided by billdesk
Message description
MerchantID|CustomerID|NA|TxnAmount|NA|NA|NA|CurrencyType|NA|TypeField1|SecurityI
D|NA|NA|TypeField2|Txtadditionalinfo1| Txtadditionalinfo2| Txtadditionalinfo3|
Txtadditionalinfo4| Txtadditionalinfo5| Txtadditionalinfo6| Txtadditionalinfo7|RU
Sample message for checksum value generation
$str = ABCD|ARP10234|NA|94.00|NA|NA|NA|INR|NA|R|abcd|NA|NA|F|NA|NA|NA|NA|NA|NA|NA|http://www.domain.com/response.php
The checksum is an important part while someone receives the message from BillDesk.
Once the User (site owner) gets the response from BillDesk, a new checksum is generated at the user site to verify the received one. Any differences in the checksum indicate that the messages have been modified or received erroneously.
BillDesk provides a checksum component to the user (site owner) to generate the checksum.
Note: How to generate checksum value
$checksum = hash_hmac(‘sha256’,$str,$checksum_key, false);
$checksum_value = strtoupper($checksum);
The Checksum component will require a message string and common string, i.e. password shared by the bill desk to generate the checksum.
Let’s assume that the checksum is 987878789789778
Sample transaction Message to be sent to Bill Desk URL as parameter ‘msg’ through “POST” mechanism
$msg= ABCD|ARP10234|NA|94.00|NA|NA|NA|INR|NA|R|abcd|NA|NA|F|NA|NA|NA|NA|NA|NA|NA|http://www.domain.com/response.php|987878789789778
Payment Response
The payment response is sent to the Return URL [RU] specified dynamically by Merchant for each transaction.
This response is a browser response and the message will be posted to the Merchant‟s Return URL as a parameter – msg
Response Message Description:
MerchantID|CustomerID|TxnReferenceNo|BankReferenceNo|TxnAmount|BankID|BankMerch antID|TxnType|CurrencyName|ItemCode|SecurityType|SecurityID|SecurityPassword|TxnDa te|AuthStatus|SettlementType|AdditionalInfo1|AdditionalInfo2|AdditionalInfo3|AdditionalInf o4|AdditionalInfo5|AdditionalInfo6|AdditionalInfo7|ErrorStatus|ErrorDescription|CheckSum
Sample Response Message
MERCHANTID|ARP10234|MSBI0412001668|NA|00000094.00|SBI|22270726|NA|INR|NA|NA |NA|NA|12-12-2004 16:08:56|0300|NA|NA|NA|NA|NA|NA|NA|NA|NA|NA|3734835005
APPROACH:
1. You can store some of the key information in the config file
<input type=”hidden” name=”MerchantId” value=”MERCHANT_KEY”/>
<input type=”hidden” name=”CurrencyType” value=”INR”/>
<input type=”hidden” name=”SecurityId” value=”Security_ID”/>
<input type=”hidden” name=”txtCustomerID” value=”CustomerID” />
<input type=”hidden” name=”txtTxnAmount” value=”Amount” />
<input type=”hidden” name=”txtAdditionalInfo1″ value=” />’
<input type=”hidden” name=”RU” value=”RU” />
<input type=”hidden” name=”CheckSumKey” value=”checksum_key”/>
<input type=”hidden” name=”CheckSum” value=”checksum_value”/>
<input type=”hidden” name=”msg” value=”<?php echo $msg;?>” />
Receive the information from the bill desk through response and extract the required information. Store and display as per your requirement.
Success page (RU)
Get post data and split it as
$msg=$_POST[“msg”];
echo $msg;
$splitdata = explode(‘|’, $msg);
$common_string=”CGFB23KK”; // checksum key provided by BillDesk
if($msg!=””)
{
$code = substr(strrchr($msg, “|”), 1); //Last check sum value
$string_new=str_replace(“|”.$code,””,$msg);//string replace : with empy space
$checksum = strtoupper(hash_hmac(‘sha256’,$string_new,$common_string, false));// calculated check sum
if($checksum==$code && $splitdata[14]==”0300″) // success trans condition
{
// Here success txn data base save code
echo “success”;
}else{
echo “Txn Failed “;
}
}
Hope it will make you clear on how to integrate the Bill Desk Payment Gateway in your PHP-coded website.
Thanks