REST specifications

API reference

Headers, signature generation, checkout APIs, redirection, webhook and status codes for Hamro Pay Checkout.

1. Headers

Every hamropay api request should include certain headers to work. It is mandatory for all the api.

Following are three headers that the client needs to pass while sending every request. The header includes the following:

  1. Client Id: The unique id that will be generated and given by the Hamropay team.
  2. Client API Key: This is the key to access the API for checkout . API Key will be generated and given to the client by the Hamropay team.
  3. Signature: Every request should have a signature header attached, which is a string value. Every api section describes how to generate the signature string for that api.

Headers Example with Key And Values :

Header Key (string / text ) Dummy Values (string / text)
Signaturebase64stringrepresentation==
Client-Idclient@123
Client-API-Keymerchant-api-key-test

2. Signature Generation

This section describes how the signature string should be generated in general, for the values required for generating the signature please consult every api section found below.

Signature must be included in the header section of the request. To generate a signature we need the signature string (described in the individual API section) and client secret.

The client secret used for generating the string will be provided by the Hamro Pay team and shared ONLY between the client and Hamro Pay Checkout API.

Please keep your client secret securely, so we recommend it to be known by your backend only with proper measures taken to protect it.

The signature should be a Base64 string of HMAC512 message output.

Psudo Code Example:

pseudo-signature.txt
client_secret = 'abcdefg'

signature_message_string = field1 + ',' + field2 + ',' + field3 + ',' + field4.. fieldn
(String separated by comma).

final_signature_string = toBase64 ( HmacSHA512Digest(signature_message_string, client_secret) )

(Values separated by comma as a string). Messages are different according to APIs. What field's to be used for generating the signature_message are defined in the every API sections.

2.1. Sample Code For Base64 Signature Generation

signature
public static String signHMAC(String message, String secret) {
   try {

       Mac mac = Mac.getInstance("HmacSHA512");
       SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA512");
       mac.init(secretKeySpec);
       return Base64.getEncoder().encodeToString(mac.doFinal(message.getBytes("UTF-8")));

   } catch (NoSuchAlgorithmException var4) {
       throw new RuntimeException(var4);
   } catch (InvalidKeyException var5) {
       throw new RuntimeException(var5);
   } catch (UnsupportedEncodingException var6) {
       throw new RuntimeException(var6);
   }
}

3. Checkout API

Base URLs
{{API_BASE_URL}} and {{GATEWAY_URL}} are your Hamro Pay UAT endpoints. Find the exact values in the Integrate Checkout APIs step of the checkout quickstart.

3.1. Create Session API

During checkout, the client requests to get the session Id that will be used throughout the checkout cycle. A session ID is a unique identifier that a Hamro Pay server assigns to a single transaction for the duration of the current session. A session is a finite period (around 10 mins) interaction between a web client and server. The session will expire after 10 mins of initial generation.

This API provides the session Id assigned to a specific transaction. All request header required are the same as described in the Header section above.

POST {{API_BASE_URL}}/v1/checkout/sessionId UAT base URL

Intended API User: Merchant backend

Fields required for generating Signature string for Create Session API:

  1. merchantTxnId
  2. transactionAmount
  3. merchantId
  4. client_id
  5. clientApiKey

Use these fields for signature string generation i.e values of the fields combined with ',' to form a single string and see Signature Generation section to see how to generate this.

Generation process psudo code example:

create-session-signature.txt
initial_signature_string = merchantTxnId+','+transactionAmount+','+merchantId+','+client_id+','+clientApiKey
final_signature_string = toBase64 ( HmacSHA512DigestOf(initial_signature_string, using_secret) )

Request Parameters:

FieldsData TypeDescription
merchantTxnId *String (LESS THAN or EQUAL to 25 characters)Unique Id. This is the same merchantTxnId used in SigntaureString
merchantId *StringClient’s Hamro Pay Id
transactionAmount *LongAmount in Paisa. Should be in Range of Rs.10 to Rs.50000. i.e Rs.10 = 1000, Rs.89.92 = 8992
productList[ OPTIONAL ] List of product’s json (provided below)List of products contains : name, imageurl, description, price (in Rs) and quantity as provided below in Product List Sample, it will be displayed in the hamropay payment web portal
failedRedirectionUrl *stringUrl used to redirect to clients after the transaction is failed from hamropay
successRedirectionUrl *stringUrl used to redirect to clients after the transaction is success from hamropay
phone_numberstring [OPTIONAL]Hamropay registered phone number if available
metadatamap<string,string>Extra data you sent, which you'll receive in hook response aswell
clientCommissionConfigJson of Client Commission Config [OPTIONAL]JSON Client Commission Config that contains : Commission Receivable Merchant ID, Commission Amount, Commission Percentage

Client Commission Config

Only one of commissionAmount or commissionPercentage should be provided depending on the need.
FieldTypeDescription
commissionMerchantIdStringCommission Receiveable Merchant ID
commissionAmountDoubleCommission Amount
commissionPercentageDoubleCommission Percentage
commission-config.json
"clientCommissionConfig": {
       "commissionMerchantId":"8c9e2ea0-4eb5-11f1-baa3-de257371874e1",
       "commissionPercentage": 3.56
   }

Product List Sample

At Least one product should be present in productList, the sample is as below:

product-list.json
"productList" : [
  {
    "name:" "shirt",
    "imageUrl":
      "https://testUrl.jpg",
    "description": "This is shirt",
    "price": 99.99, //Amount in Rs. for render purpose so Rs.99.99 should be 99.99
    "quantity": 1
  },
];

Response fields:

FieldsData TypeDescription
sessionIdStringUUID
merchantIdStringClient’s Hamro Pay Id

Few Request / Response Samples:

create-session
// Request
{
    "merchantTxnId": {{transactionId}},
    "merchantId" : "PN_-Nd99TBnAlBjCgl8ef_b",
    "transactionAmount": "1000",
    "failedRedirectionUrl":"https://testl.com/payment/",
    "successRedirectionUrl":"https://testl.com/payment/",
    "productList" : [
      { "name:" "shirt", "imageUrl": "https://testUrl.jpg", "description": "This is shirt", "price": 10, "quantity": 1 },
      { "name:" "shirt2", "imageUrl": "https://testUrl2.jpg", "description": "This is shirt 2", "price": 20, "quantity": 1 }
    ]
}

// Response
200 OK

{
    "sessionId": "ca8f7b70-b9c9-11ee-8611-0a73743c8233",
    "merchantId": "PN_-Nd99TBnAlBjCgl8ef_b"
}

3.2. Checkout Proceed API

The checkout API is intent for the web to call. After the Session creation, the client’s website can make a request with Checkout-Form to hamro pay-checkout-gateway. This request has a Checkout-Form where Params need to be sent to hamropay checkout gateway. This will redirect you to hamropay checkout webpage with given params in form data.

Important NOTE
After the Session creation api is called you need to generate the params in your backend service so that the secret is NOT exposed to the client as you need the secret to build a token for the params, i.e directly return data required to build params from the Create Session API as you already have all the details required after calling the session API for params building, after generating the params return the params to your web-client which makes a form-data request using the params to hamro pay-checkout-gateway described below.
POST {{GATEWAY_URL}}/api/checkout UAT base URL

Intended API User: Merchant frontend

Request body ( Form Data) :

Params :

The params of Checkout-Form, also known as body of request contains merchant_id, session_id, Token, merchant_transaction_id, transaction_id and remarks.

Token
Token is a form Signature but with different fields, and rather than passing it to header its passed in params iteself. Token is generated the same as Signature Generation using the your same Secret and Message format described below.

Fields for token generation: 1. merchant_id
2. merchant_transaction_id
3. session_id
4. transaction_amount
5. client_id
6. client_api_key

Use these fields for signature string generation i.e values of the fields combined with ',' to form a single string and see Signature Generation section to see how to generate this.

Params for request body :

params.js
params = {
            merchant_id: "Your merchant id" ,
            session_id: "Session ID",
            token: "Your Token" ,
            merchant_transaction_id: "Your Transaction ID (length less or equal to 25 chars)",
            remarks: " Remarks (upto 250 chars) ",
            phone_number: "phone number of hamropay user if available [OPTIONAL]"
          };

Js Sample Checkout-Form using params above

checkout-form.js
const form = document.createElement("form");
  form.method = method;
  form.action = path;
  form.enctype = "application/x-www-form-urlencoded";
  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      const hiddenField = document.createElement("input");
      hiddenField.type = "hidden";
      hiddenField.id = key;
      hiddenField.name = key;
      hiddenField.value = params[key];
      form.appendChild(hiddenField);
    }
  }

  document.body.appendChild(form);
  form.submit();

Response after the request: Redirection to Hamro pay checkout gateway.

How it looks in web :
Hamropay redirection after params post
How it looks in Mobile :
Hamro Pay mobile checkout UI

3.3. Get Transaction API

This API is used to get the transaction & its status after payment is made. The request header is the same as described in the Header section.

POST {{API_BASE_URL}}/v1/checkout/transaction UAT base URL

Intended API User: Merchant backend

Fields required for generating Signature string:

  1. merchantTxnId
  2. merchantId
  3. client_id
  4. clientApiKey

Use these fields for signature string generation i.e values of the fields combined with ',' to form a single string and see Signature Generation section to see how to generate this.

Generation process example:

get-transaction-signature.txt
initial_signature_string = merchantTxnId+','+merchantId+','+client_id+','+clientApiKey
final_signature_string = toBase64 ( HmacSHA512DigestOf(initial_signature_string, using_secret) )

Request :

FieldsData TypeDescription
merchantId *StringUnique id merchant
merchantTxnId *StringMerchant Transaction ID from previous requests

Response:

FieldsData TypeDescription
merchantTransactionIdStringMerchant Transaction ID
statusStringStatus of the transaction. (PENDING, PROCESSING, FAILED, COMPLETED)
amountDoubleAmount in Rupees.
remarksStringRemarks of the transaction.
messageStringMessage about the transaction.

Request / Response Samples:

get-transaction
// Request
{
    "merchantId" : "PN_-Nd99TBnAlBjCgl8ef_b",
    "merchantTxnId" : "erftycnmiim"
}

// Response
{
    "merchantTransactionId": "erftycnmiim",
    "trackingId": "",
    "status": "NOT_INITIATED",
    "amount": 0,
    "remarks": "",
    "message": "TRANSACTION NOT INITIATED YET"
}

Once the transaction is successful or failed, Hamropay provides the response of the transaction through the Client’s response url provided during Create Session API Or through the webhook . The response is sent to the provided response url after the transaction is successful/Failed.

4. Success / Failed Redirection

After the transaction, HamroPay will redirect to the provided success or failure URL.

Regarding the Success Redirection URL. If the URL provided is https://something.com/success, HamroPay will redirects to client appending the MerchantTxnId as below:

success-redirect.url
https://something.com/success?MerchantTxnId=123213

Where, MerchantTxnId represents the actual transaction ID, which Client can utilize to confirm the transaction from their end.

Regarding the Failure Redirection URL. If the URL provided is https://something.com/failure, HamroPay will redirects to client appending the MerchantTxnId as below:

failure-redirect.url
https://something.com/failure?MerchantTxnId=123213

Where, MerchantTxnId represents the actual transaction ID, which Client can utilize to confirm the transaction from their end.

5. Webhook (Optional)

Merchants / Clients will receive a webhook to their provided POST REQUEST URL (endpoint) from hamro pay after the Checkout transaction is successful or failed. The webhook can be used to trigger the actual transaction without having to poll for the transaction status.

Using Hamro Pay webhook

  1. 1. Integration Setup: To begin, the client integrates their application with Hamro Pay's payment system. This involves providing a callback URL, typically a POST endpoint, where Hamro Pay will send webhook notifications which is a json body regarding payment details.
  2. 2. Webhook Configuration: Once integrated, Hamro Pay configures its system to send payment webhook notifications to the provided URL whenever a payment status changes, such as success or failure.
  3. 3. Handling Webhook Requests: The client's server needs to implement an endpoint to receive and process webhook requests. This endpoint should be capable of handling POST requests and parsing the incoming data.
  4. 4. Processing Payment Status: Upon receiving a webhook notification, the client's server extracts relevant information from the payload, such as transaction ID, status, and any associated metadata.
  5. 5. Handling Success or Failure: Depending on the received status, the client's application can take appropriate actions. For instance, if the payment was successful, it can update the user's account or trigger a confirmation message. If the payment failed, it can initiate a refund process or notify the user about the issue.
  6. 6. Signature Verification (Optional but Recommended): To ensure the authenticity of webhook requests and prevent unauthorized access or tampering, HamroPay can include a signature along with the payload. The client's server then verifies this signature to confirm that the request indeed originates from HamroPay.

Webhook Body:

These are the json body fields you will receive in request from hamropay backend to your provided endpoint.

FieldsData TypeDescription
merchantTxnIdStringMerchantTransactionId generated from client, can be used to fetch transaction with merchantId
merchantIdStringFor Reconciliation purpose
amountdoubleTransaction amount in Rs.
statusStringStatus of the transaction. (PENDING,PROCESSING,FAILED,COMPLETED)
metadatamap<string,string>Same Extra data returned, that you send while creating payment intent

Json Representation

webhook-payload.json
//HEADER
// Signature: <<Signature String generated from hamropay>>

{
  "merchantTxnId": "Txn Id used for reconciliation purposed initially from client",
  "merchantId": "your merchant Id",
  "amount": 9.99, //in Rs.
  "status": "COMPLETED OR FAILED" //either or,
  "metadata": {"field1":"fieldValue1","field2":"fieldValue2"}
}

Webhook Verification

You will get a webhook request containing the signature in the header. The signature string is available in header in key Signature i.e header.get("Signature"). The {{merchantWebHookSigningSecret}} will be provided by Hamro Pay team.

The {merchantWebHookSigningSecret} is only used to validate the webhook request and for nothing else
webhook-verify.java
//Use the following fields from the body, to generate the signature string:
// Seperated by commas
var signatureString = merchantTxnId +','+ merchantId +','+ status +','+ amount;

var signatureFromHeader = header.get("Signature");
var signatureGenFromBodyInBase64 = Base64( HMAC.signHMAC(signatureString , {{merchantWebHookSigningSecret}}) );

var isValid = signatureFromHeader.equals(signatureGenFromBodyInBase64);

You can Signature Generation to see code sample how to generate signature string using the fields merchantTxnId +','+ merchantId +','+ status +','+ amount

6. Code with Description

  • OK OR ACTIVE = 0
  • CANCELED = 1
  • UNKNOWN = 2
  • INVALID_ARGUMENT = 3
  • TIME_OUT = 4
  • NOT_FOUND OR SUSPENDED = 5
  • ALREADY_EXISTS = 6
  • PERMISSION_DENIED = 7
  • LIMIT_EXCEEDED = 8
  • FAILED_PRECONDITION = 9
  • ABORTED = 10
  • OUT_OF_RANGE = 11
  • UNIMPLEMENTED = 12
  • INTERNAL = 13
  • UNAVAILABLE = 14
  • DATA_LOSS = 15
  • UNAUTHENTICATED = 16

Test your integration

Once you have wired up the endpoints above, run an end-to-end payment with the sandbox test credentials and verify the success, failed, and pending flows.

Go to checkout integration testing

Hamro Pay Support

Grievance officer

Follow Us

© 2026 HamroPay. All Rights Reserved.