BillDesk Hosted Payment Page

Before you start with the integration process, check the steps that are involved to create a request. Let us take step-by-step approach to understand how request is created.

A payload for a request made to BillDesk consists of three parts that are base64-url encoded.

1. Header

2. JSON Request

3. Signature

For each of the part, below section helps to generate the request

Step 1 - Create the header

Header consists of 2 attributes, one of the attribute ("alg") has fixed value "HS256", the other attribute is "clientid" that has a value which is shared by BillDesk. Use these 2 attributes to create a JSON request as shown below

                 {

                        "alg": "HS256",
                        "clientid": "use client id shared by BillDesk"

                 }

Step 2 - Create the JSON Request (with the required fields)

Merchant must use the Id provide by BillDesk in mercid attribute

                        {  
                              "mercid": "BDMERCID",  
                              "orderid": "order45608988",	  
                              "amount": "300.00",  
                              "order_date": "2021-03-05T10:59:15+05:30",  
                              "currency": "356",  
                              "ru": "<https://merchant.com>",  
                              "additional_info": {  
	                                 "additional_info1": "Details1",  
	                                 "additional_info2": "Details2"  
                               },  
                              "itemcode": "DIRECT",  
                              "device": {  
	                                "init_channel": "internet",  
	                                "ip": "124.124.1.1",  
   																"mac": "11-AC-58-21-1B-AA",  
																	"imei": "990000112233445",  
																	"accept_header": "text/html",  
																	"fingerprintid": "61b12c18b5d0cf901be34a23ca64bb19"  
											        }
                        }  

Step 3 - Create the signature for the header and JSON request

BillDesk will share the secret key with the merchant. A sample code in java (mentioned below) will help

private static String encryptAndSignJWSWithHMAC(String reqStr, String secretKey, String clientid)  
    throws JOSEException {
          JWSSigner signer = new MACSigner(secretKey);
          HashMap<String, Object> customParams = new HashMap<String, Object>();
          customParams.put("clientid", clientid);
  
  JWSHeader jwsHeader = new JWSHeader(JWSAlgorithm.HS256, null, null, null, null, null,
                                    null, null, null, null, null, customParams, null);
  
  JWSObject jwsObject = new JWSObject(jwsHeader, new Payload(reqStr)); // Apply the HMAC
  
  jwsObject.sign(signer);
  
return jwsObject.serialize();
}
using System.Collections.Generic;
using Jose;
using Newtonsoft.Json.Linq;

private static string EncryptAndSignJWSWithHMAC(string reqStr, string secretKey, string clientid)
{
    var signer = new HMACSigner(secretKey);
    var customParams = new Dictionary<string, object>();
    customParams.Add("clientid", clientid);
    var jwsHeader = new JWSHeader(JWSAlgorithm.HS256, null, null, null, null, null,
                                  null, null, null, null, null, customParams, null);
    var jwsObject = new JWSObject(jwsHeader, new Payload(reqStr));
    jwsObject.Sign(signer);
    return jwsObject.Serialize();
}

Step 4 - Create the final payload

The output of the Step 3 is used as final payload to initiate API request to BillDesk

Step 5 - Initiate the API Request and BD

Step 5.1 - Set the header as below

AttributeTypeDescription
Content-TypeStringRequest Content-Type to take the values application/jose
AcceptStringAccept Response Content-Type to take the values application/jose
BD-TraceidStringTraceid is used for idempotency and the request with the same
Traceid within the day will be rejected. Traceid can be alphanumeric
without any spaces or special characters and should be a maximum
size of 35
BD-TimestampStringepoch timestamp of the server

Step 5.2 - Use the payload mentioned in Step 4

Step 5.3 - Select the end point as mentioned below in the table

EndpointMethodDescription
https://uat1.billdesk.com/u2/payments/ve1_2/orders/createUse the API URL to create an order
https://uat1.billdesk.com/u2/payments/ve1_2/transactions/getUse the API URL to retrieve a transaction
https://uat1.billdesk.com/u2/payments/ve1_2/refunds/createUse the API URL to create a refund against a transaction

Step 5.4 - Send the request to the selected API endpoint

Step 5.5 - Capture, read, validate & process response at merchant end.


Did this page help you?