Signature Generation

Required for All V2 APIs

All requests to our V2 API endpoints must be authenticated. This is done by including a signature in your JSON request body.

The signature is a SHA256 hash that you generate. It proves two things:

  1. Authentication: That the request is from you (you have the secret key).

  2. Integrity: That the request body has not been tampered with.

Your server must generate this signature for every API call. Our server will perform the exact same calculation to verify its authenticity.

Note

Signature is not needed for Status Polling APIs as it has post_hash verification.

Signature Generation Logic

The signature is a SHA256 hash of a specific string. This string is built by following these 5 steps precisely.

  1. Prepare Parameters: Create an object or dictionary containing all parameters you are sending in the request body, except for the signature field itself.

  2. Sort Parameters: Sort the parameters object alphabetically by its keys (A-Z). This is the most critical step.

  3. Create JSON String: Convert the sorted object into a compact, single-line JSON string.

  4. Append Secret Key: Concatenate your unique secret_key (provided to you during onboarding) to the end of the escaped JSON string.

  5. Calculate Hash: Generate a SHA256 hash of the combined string from Step 4. The result should be a lowercase hexadecimal string. This is your final signature.

Step-by-step Walk through

Let's walk through an example.

Your Secret Key: your-secret-key

Step 1: Original Request Parameters

{
    "pid": "your-partner-id",
    "amount": 100,
    "redirect_url": "https://your-domain.com/return_page",
    "ip": "your-server-ip",
    "name": "Customer Name",
    "email": "[email protected]",
    "phone": "9876543210",
    "latitude": "28.7041",
    "longitude": "77.1025",
    "customer_id": "CUST001"
}

Step 2: Sorted Parameters After sorting alphabetically by key, the new order is: amount, customer_id, email, ip, latitude, longitude, name, phone, pid, redirect_url

Step 3: Create Compact & Escaped JSON String The sorted object is encoded, and the / characters are escaped:

{"amount":100,"customer_id":"CUST001","email":"[email protected]","ip":"your-server-ip","latitude":"28.7041","longitude":"77.1025","name":"Customer Name","phone":"9876543210","pid":"your-partner-id","redirect_url":"https:\/\/your-domain.com\/return_page"}

Step 4: Append Secret Key We append your secret key to this escaped string:

{"amount":100,"customer_id":"CUST001","email":"[email protected]","ip":"your-server-ip","latitude":"28.7041","longitude":"77.1025","name":"Customer Name","phone":"9876543210","pid":"your-partner-id","redirect_url":"https:\/\/your-domain.com\/return_page"}your-secret-key

Step 5: Generate SHA256 Hash The final signature is the SHA256 hash of the string from Step 4:

280b18e380f7d998a46b50e32f0b8da9f54668b577045b416973e4b772c72b2c

Code Implementation

<?php
function generateSignature($params, $secretKey) {
    // Remove signature field if exists
    unset($params['signature']);
    
    // Sort parameters alphabetically
    ksort($params);
    
    // JSON encode the parameters
    $jsonString = json_encode($params);
    
    // Generate SHA256 hash
    $signature = hash('sha256', $jsonString . $secretKey);
    
    return $signature;
}

// Example usage
$params = [
    "pid" => "your-partner-id",
    "amount" => 100,
    "order_id" => "order-123",
    "ip" => "your-server-ip",
    "name" => "Customer Name",
    "email" => "[email protected]",
    "phone" => "9876543210",
    "latitude" => "28.7041",
    "longitude" => "77.1025",
    "customer_id" => "CUST001"
];

$secretKey = 'your-secret-key';
$signature = generateSignature($params, $secretKey);

// Add signature to request
$params['signature'] = $signature;
?>

Final API Request

After generating the signature, add it to your parameters object under the key signature. You are now ready to send the complete object as the JSON body of your API request

Final JSON Payload to be Sent:

{
    "pid": "your-partner-id",
    "amount": 100,
    "redirect_url": "https://your-domain.com/return_page",
    "ip": "your-server-ip",
    "name": "Customer Name",
    "email": "[email protected]",
    "phone": "9876543210",
    "latitude": "28.7041",
    "longitude": "77.1025",
    "customer_id": "CUST001",
    "signature": "280b18e380f7d998a46b50e32f0b8da9f54668b577045b416973e4b772c72b2c"
}

Note on Other V2 APIs

The code examples above use parameters for a payment initiation request (e.g., amount, redirect_url, name, etc.).

This exact same signature logic must be used for all other V2 API endpoints (Payin and Payout).

For example, when calling the V2 UTR submit API your parameters object might just be {"pid": "...", "ref_code": "...", "utr": "...", "amount": "..."}. You would sort that object, JSON-encode it, append your key, and generate a SHA256 hash in the same way.

Last updated