Environment
Test Environment | <https://test.payu.in/info/linkAndPay/delinkInstrument> |
Production Environment | <https://info.payu.in/linkAndPay/delinkInstrument> |
Request Parameters
Header
The request header contains the following fields:
Field | Description | Example |
---|---|---|
Date |
The date and time should be in the GMT time conversion(not the IST). For example, current time in India is 18:00:00 IST, the time in the date header should be 12:30:00 GMT. |
Thu, 17 Feb 2022 08:17:59 GMT |
Digest |
Base 64 encode of (sha256 hash of the JSON data (post to server). |
|
Authorization |
This field is in the following format:
|
hmac username="smsplus", algorithm="hmac-sha256", headers="date digest", signature="zGmP5Zeqm1pxNa+d68DWfQFXhxoqf3st353SkYvX8HI=" |
platformId |
This field contains the platform ID and include the value as 1. |
1 |
Required parameters for calculating authorization
- Date
- Authorization
The following sample Java code contains the logic used to encrypt as described in the above table:
package com.payu.apilayer.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class HmacAuth {
public static JsonObject getRequestBody(){
JsonObject requestJson = new JsonObject();
requestJson.addProperty("udf1","123");
return requestJson;
}
public static String getSha512Hash(String hashString) {
{
try {
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] messageDigest = md.digest(hashString.getBytes());
BigInteger signumBytes = new BigInteger(1, messageDigest);
String hashtext = signumBytes.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
String key = "smsplus";
String secret = "admin";
Gson gson = new Gson();
String date = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withZoneUTC().print(new DateTime());
System.out.println(date);
JsonObject requestJson = getRequestBody();
String hashString = new StringBuilder()
.append(gson.toJson(requestJson))
.append("|")
.append(date)
.append("|")
.append(secret).toString();
System.out.println("Hash String is " + hashString);
String hash = getSha512Hash(hashString);
String authorization = new StringBuilder()
.append("hmac username=\"")
.append(key)
.append("\", algorithm=\"sha512\", headers=\"date\", signature=\"")
.append(hash)
.append("\"").toString();
System.out.println(authorization);
}
}
Body parameters
Note:You can use any of the following combination of the mandatory parameters apart from requestId and amount:
- pg+bankcode+user_credentials
- payuToken+user_credentials
Field | Description | Example |
---|---|---|
requestId |
|
Test1234 |
amount |
|
{"amount":"10000"} |
pg |
|
BNPL |
bankcode |
|
LAZYPAY |
phone |
|
“9999999999” |
payuToken |
|
Token12345 |
user_credentials |
|
abc:xyz |
key |
|
Your Test Key |
Sample request
With pg, bankcode and user_credentials
curl --location 'https://test.payu.in/info/linkAndPay/delinkInstrument' \
--header 'Content-Type: application/json' \
--header 'authorization: hmac username="smsplus", algorithm="sha512", headers="date", signature="55266f0988fbd42114f9d36c395c6cb32ec27b86d204ac06b2e7e580cf1a62b24dc30c987a37f03d628b14f3c7df5950eb513d560f048daa5627a6aeae79fe59"' \
--header 'date: Tue, 14 Jan 2025 10:03:47 GMT' \
--data '{
"requestId": 12233,
"pg": "BNPL",
"bankcode": "LAZYPAY",
"phone": "9999999999",
"userCredentials": "abc:xyz"
} '
With payuToken and user_credentials
curl --location 'https://test.payu.in/info/linkAndPay/delinkInstrument' \
--header 'Content-Type: application/json' \
--header 'authorization: hmac username="smsplus", algorithm="sha512", headers="date", signature="56cb0e25b6ed0343440946a839db97d9c55c8bc69917611d350ac64b040cd1931a5b3a002bbd7a291d40d5072072a1a8021465616a66d8a32cea71c0b84ed03b"' \
--header 'date: Tue, 14 Jan 2025 10:17:13 GMT' \
--data '{
"requestId": 12233,
"phone": "9999999999",
"payuToken": "beba5b1bb841945c2d881",
"userCredentials": "abc:xyz"
}'
Sample response
Success scenario
{
"msg": "Instrument deleted",
"status": "SUCCESS"
}
Failure scenario
User not found
{
"msg": "User not found", // when user cannot be found uniquely found corresponding to the token and user credentials combination
"status": “FAILURE”
}
Instrument already deleted
{
"msg": "Instrument already deleted", // when payment instrument has already been deleted against a user
"status": “FAILURE”
}
Instrument not found
{
"msg": "Instrument not found", // when payment instrument cannot be found uniquely found corresponding to the token and user credentials combination
"status": “FAILURE”
}