Post an UPI Recurring transaction
Posting a UPI recurring transaction for cross-border payments involves the following steps:
Step 1: Pre-Debit Notification
Post the pre-debit notification before 48 hours of the actual debit to notify the customer. For more information, refer to Pre-Debit Notification API .
Environment
| Production Environment | <https://info.payu.in/merchant/> |
| Test Environment | <https://test.payu.in/merchant/> |
Sample request
curl --location --request POST 'https://test.info.payu.in/merchant/postservice.php?form=2' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data
'key=JF****g&hash=9f5faabedb7f5d41f519db3a223cf5318ecc0b7e669f49e0a699d4c4879e1ccaed5b99f5cd
8be4f2cbddefe5272ec983abd8f38480d9c2609a29447f750a3158&command=check_action_status_txnid&var
1=7043873219"Sample response
Successful sceanario
{
"status": 1,
"action": "MANDATE_PRE_DEBIT",
"message": "Request Processed Successfully",
“invoiceId”:” ADDA049409”
}Failure Scenarios
- Mandate is active in PayU DB and Pre-Debit gets declined from Bank/NPCI
{
"status": “QC” ----- >> Bank/NPCI Error Code
"action": "MANDATE_PRE_DEBIT",
"message": “MANDATE HAS BEEN REVOKED”. ---- >> Description against error code
}Where, the message parameter in the response will display error code according to the scenario
- Mandate is already Paused/ Revoked in PayU DB
{
"status": 0,
"action": "MANDATE_PRE_DEBIT",
"message": "Mandate is not active” --- >> Description will change based on Scenario
}Where, the message parameter in the response will display according to the scenario.
Step 2: Recurring Payment Transaction
Initiate recurring using the Recurring Payment Transaction API including the below UDF params under var1 object required for PACB flow. For more information, refer to Recurring Payment Transaction API.
Environment
| Production Environment | <https://info.payu.in/merchant/> |
| Test Environment | <https://test.payu.in/merchant/> |
Request parameters
| Parameter | Description | Example |
|---|---|---|
amountmandatory |
String - Monetary value of the recurring transaction. Part of var1 JSON object. |
1000.00 |
authpayuidmandatory |
String - Unique authentication payment ID from an earlier successful registration. Part of var1 JSON object. Required for recurring payments. |
auth_pay_123456789 |
commandmandatory |
String - Specifies the API command type. For the recurring payment API, the value will be "si_transaction". |
si_transaction |
emailmandatory |
String - Customer's email ID for communication and receipts. Part of var1 JSON object. |
[email protected] |
hashmandatory |
String - A SHA512 hash generated by concatenating specific fields (key|command|var1|salt) and securely hashed. Used for authentication. |
abcd1234567890efgh... |
invoiceDisplayNumberoptional |
String - User-friendly invoice number to display to the customer. Part of var1 JSON object. |
INV-2024-001 |
keymandatory |
String - Contains the merchant key provided by PayU. Used for authentication. |
rjQUPktU |
phonemandatory |
String - Customer's contact number. Part of var1 JSON object. Echoed back in responses. |
9876543210 |
txnidmandatory |
String - Merchant-generated unique transaction ID. Part of var1 JSON object. |
TXN123456789 |
udf1mandatory |
String - Must include the PAN and DOB of the buyer in the format: PAN||DOB. The PAN and DOB are separated with two pipe (||) characters. |
ABCDE1234F||1990-01-15 |
udf2optional |
String - Custom user-defined field for additional data. Part of var1 JSON object. Echoed back in responses. |
additional_info_2 |
udf3mandatory |
String - Must include the invoice_id and seller name (for PACB reseller use case) in the format: invoice_id||sellerName. The invoice_id and seller name are separated with two pipe (||) characters. |
INV-789||SellerName |
udf4optional |
String - Custom user-defined field for additional data. Part of var1 JSON object. Echoed back in responses. |
additional_info_4 |
udf5optional |
String - Custom user-defined field for additional data. Part of var1 JSON object. Echoed back in responses. |
additional_info_5 |
var1mandatory |
Object - JSON object combining various mandatory and optional fields needed for the request. Contains authpayuid, invoiceDisplayNumber, amount, txnid, phone, email, and udf1-udf5 fields. |
{"authpayuid":"auth_pay_123","amount":"1000.00","txnid":"TXN123","phone":"9876543210","email":"[email protected]"} |
Notes: For the UDFs above:
- If first value is absent, then UDF param will be sent as NULL || <VALUE>
- If second value is absent, then UDF param will be sent as \ <VALUE>
Sample request
curl -X POST "https://test.payu.in/merchant/postservice?form=2" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "key=JP***g&command=si_transaction&var1={\"authpayuid\": \"6611192557\",\"invoiceDisplayNumber\":\"12345678910\",\"amount\": 3,\"txnid\": \"REC15113506209\",\"phone\": \"9999999999\",\"email\": \"[email protected]\",\"udf2\": \"\",\"udf3\": \"\",\"udf4\": \"\",\"udf5\": \"\"}&hash=jbUS07Og8BToVZ"Perfect! I've analyzed your CURL request and converted it to equivalent code in all requested languages. This appears to be a PayU payment gateway API call for subscription/installment transactions.
Python 🐍
import requests
import urllib.parse
# PayU API endpoint
url = "https://test.payu.in/merchant/postservice?form=2"
# Headers
headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
}
# Form data
form_data = {
"key": "JP***g",
"command": "si_transaction",
"var1": '{"authpayuid": "6611192557","invoiceDisplayNumber":"12345678910","amount": 3,"txnid": "REC15113506209","phone": "9999999999","email": "[email protected]","udf2": "","udf3": "","udf4": "","udf5": ""}',
"hash": "jbUS07Og8BToVZ"
}
# Make the POST request
try:
response = requests.post(url, headers=headers, data=form_data)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string url = "https://test.payu.in/merchant/postservice?form=2";
// Set headers
client.DefaultRequestHeaders.Add("accept", "application/json");
// Prepare form data
var formData = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("key", "JP***g"),
new KeyValuePair<string, string>("command", "si_transaction"),
new KeyValuePair<string, string>("var1", "{\"authpayuid\": \"6611192557\",\"invoiceDisplayNumber\":\"12345678910\",\"amount\": 3,\"txnid\": \"REC15113506209\",\"phone\": \"9999999999\",\"email\": \"[email protected]\",\"udf2\": \"\",\"udf3\": \"\",\"udf4\": \"\",\"udf5\": \"\"}"),
new KeyValuePair<string, string>("hash", "jbUS07Og8BToVZ")
};
var formContent = new FormUrlEncodedContent(formData);
try
{
HttpResponseMessage response = await client.PostAsync(url, formContent);
string responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status Code: {response.StatusCode}");
Console.WriteLine($"Response: {responseContent}");
}
catch (HttpRequestException e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}// PayU API call using modern Async/Await Fetch
async function makePayURequest() {
const url = "https://test.payu.in/merchant/postservice?form=2";
// Headers
const headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
};
// Form data
const formData = new URLSearchParams({
"key": "JP***g",
"command": "si_transaction",
"var1": '{"authpayuid": "6611192557","invoiceDisplayNumber":"12345678910","amount": 3,"txnid": "REC15113506209","phone": "9999999999","email": "[email protected]","udf2": "","udf3": "","udf4": "","udf5": ""}',
"hash": "jbUS07Og8BToVZ"
});
try {
const response = await fetch(url, {
method: "POST",
headers: headers,
body: formData
});
const responseText = await response.text();
console.log(`Status: ${response.status}`);
console.log(`Response: ${responseText}`);
return {
status: response.status,
data: responseText
};
} catch (error) {
console.error("Error:", error);
throw error;
}
}
// Call the function
makePayURequest()
.then(result => console.log("Success:", result))
.catch(error => console.error("Failed:", error));import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class PayUApiClient {
private static final HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30))
.build();
public static void main(String[] args) {
try {
makePayURequest();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
public static void makePayURequest() throws IOException, InterruptedException {
String url = "https://test.payu.in/merchant/postservice?form=2";
// Prepare form data
Map<String, String> formData = new HashMap<>();
formData.put("key", "JP***g");
formData.put("command", "si_transaction");
formData.put("var1", "{\"authpayuid\": \"6611192557\",\"invoiceDisplayNumber\":\"12345678910\",\"amount\": 3,\"txnid\": \"REC15113506209\",\"phone\": \"9999999999\",\"email\": \"[email protected]\",\"udf2\": \"\",\"udf3\": \"\",\"udf4\": \"\",\"udf5\": \"\"}");
formData.put("hash", "jbUS07Og8BToVZ");
// Convert to URL encoded string
String formBody = formData.entrySet().stream()
.map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) +
"=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
// Build request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(formBody))
.build();
// Send request
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status Code: " + response.statusCode());
System.out.println("Response: " + response.body());
}
}// PayU API endpoint
$url = "https://test.payu.in/merchant/postservice?form=2";
// Form data
$postData = [
'key' => 'JP***g',
'command' => 'si_transaction',
'var1' => '{"authpayuid": "6611192557","invoiceDisplayNumber":"12345678910","amount": 3,"txnid": "REC15113506209","phone": "9999999999","email": "[email protected]","udf2": "","udf3": "","udf4": "","udf5": ""}',
'hash' => 'jbUS07Og8BToVZ'
];
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($postData),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'accept: application/json',
'Content-Type: application/x-www-form-urlencoded'
],
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false, // Only for testing
]);
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
// Close cURL
curl_close($ch);
// Handle response
if ($error) {
echo "cURL Error: " . $error . PHP_EOL;
} else {
echo "Status Code: " . $httpCode . PHP_EOL;
echo "Response: " . $response . PHP_EOL;
}Sample response
Success scenario
Here is a sample response object returned against recurring payment API when the transaction is successfully charged.
{
"status": 1,
"message": "Transaction Processed successfully",
"details": {
"REC15113506209": {
"transactionid": "REC15113506209",
"amount": "3",
"payuid": "6611427463",
"status": "captured",
"field9": "Transaction Completed Successfully",
"phone": "9999999999",
"email": "[email protected]",
"udf2": "",
"udf3": "",
"udf4": "",
"udf5": ""
}
}
} Failure scenarios
- Invalid hash
{
"status": 0,
"msg": "Invalid Hash."
}- Basic authentication check failed
{
"status": 1,
"message": "Transaction Processed successfully",
"details": {
"REC9812123123": {
"authpayuid": "6611192559",
"transactionid": "REC9812123123",
"amount": "1",
"user_credentials": " ",
"card_token": " ",
"payuid": "",
"status": "failed",
"field9": "Basic authentication check failed",
"phone": "",
"email": ""
}
}
}Response parameters
JSON fields description of the Details parameter
| JSON Field | Description |
|---|---|
| transactionid | This field contains the value of transaction ID parameter which is echoed back in the response. This is unique transaction ID generated by merchant during calling recurring API. |
| amount | This field contains the requested transaction amount is echoed back in the payment response. |
| payuid | This field contains the PayU’s transaction ID for processed recurring transaction. Merchant can use this field for reference point in the settlement report. |
| status | This field gives the status of the transaction. Hence, the value of this field depends on whether the transaction was successful or not. |
| field9 | This field returns the description of transaction status which can help the merchant in providing better customer communication. |
| phone | The mobile number of the customer echoed back. |
| Email ID of the customer echoed back. | |
| udf1 | Extra information received in the request echoed back. |
| udf2 | Extra information received in the request echoed back. |
| udf3 | Extra information received in the request echoed back. |
| udf4 | Extra information received in the request echoed back. |
| udf5 | Extra information received in the request echoed back. |
status field description
This field gives the status of the transaction. Hence, the value of this field depends on whether the transaction was successful or not.
You must map the order status using this parameter only. The possible values of this parameter are:
- captured: If the transaction is successful, the value will be captured. In some cases, the response of Net banking recurring can be captured over real-time basis (ICICI bank in the specific scenario).
- pending: This is common with most Net Banking (except ICICI in the specific scenario) or UPI recurring transaction. In that case, the merchant should consider this as successful initiation of payment with bank / NPCI. The status will be notified back to the merchant over payment processing with individual bank gets completed.
For UPI, “pending” transactions get usually get converted into captured or failed within 10 mins from the time of initiation. The Query API can be called post 10 mins from initiation, whereas for Net Banking, it can be called up to T+2 once a day. For more information, refer to Capture response of Recurring Transaction.
For Net Banking, “pending” transaction gets converted into “captured” or “failed” from the same day till T+2 anytime, depending upon the bank account used by the customer in setting up registration. - failed: The value of the status as “failed” or blank must be treated as a failed transaction only.
- in-progress: The status of transaction is in progress.
To capture the final status of “pending” transaction to either “captured” or “failed”, PayU recommends merchants to either implement Webhook URL or call verify_payment API after regular intervals. For more information on:
- Webhook: Refer to Webhooks
- verify_payment API: Refer to Verify Payment API
Note:For UPI, call the verify_settlement API after 10 mins from time of initiation whereas for Net Banking it can be called up to T+2 once in a day.
Step 3: Update Invoice ID [Optional]
If the Invoice ID value was unavailable when posting the transaction at Step 1, it can be updated using the UDF Update API by posting it in the UDF5 parameter.
Environment
| Test Environment | <https://test.payu.in/merchant/postservice.php?form=2> |
| Production Environment | <https://info.payu.in/merchant/postservice.php?form=2> |
Sample request other then UPI AutoPay
curl --location --globoff 'https://test.payu.in/merchant/postservice.php?form=2' \
--form 'key="PRiQvJ"' \
--form 'command="udf_update"' \
--form 'var1="my_order_642"' \
--form 'var2="AAAPZ1234C"' \
--form 'var4="22/08/1972"' \
--form 'var5="SellerName"' \
--form 'var6="INV000000005"' \
--form 'hash="{{hash}}"'Sample response
Success Scenario
- If successfully updated for cards
{
"status": "UDF values updated",
"transaction_id": "my_order_64240",
"udf1": "AAAPZ1234C",
"udf2": "",
"udf3": "22/08/1972",
"udf4": "SellerName",
"udf5": "INV000000005"
}- If successfully updated for UPI autopay:
{
"status": "UDF values updated",
"transaction_id": "my_order_64240",
"udf1": "AAAPZ1234C",
"udf2": "",
"udf3": "22/08/1972",
"udf4": "SellerName",
"udf5": "INV000000005"
}Failure Scenarios
- If the transaction ID is empty
(
[status] => 0
[msg] => Parameter missing
) - If the transaction ID is invalid
(
[status] => 0
[msg] => Invalid TXN ID
) - If Hash is invalid:
{
"status": 0,
"msg": "Invalid Hash."
}- If the merchant is not enabled for UDF updates:
{
"status": "0",
"msg": "Update not allowed on provided Field"
}- If no data found in the transaction ID:
{
"status": "0",
"msg": "No Data Found for txnid: 3424"
}- If the merchant is inactive:
{
"msg": "Merchant is not authorized to use PayU API",
"status": 0
}Step 4: Upload the Invoices
According to the RBI guidelines, the invoice file must be shared with PayU within 10 days of the transaction. The invoices can be uploaded using the Invoice Upload API.
Environment
| Test Environment | <https://test.payu.in/merchant/postservice.php?form=2> |
| Production Environment | <https://info.payu.in/merchant/postservice.php?form=2> |
Sample request
curl --location -g --request POST '{{baseUrl}}/merchant/postservice?form=2' \
--form 'key="{{merchantKey}}"' \
--form 'command="opgsp_upload_invoice_awb"' \
--form 'var1="403993715525825059"' \ - PayuId
--form 'var2="TestInv0001234568"' \ - invoice Id
--form 'var3="Invoice"' \ - type of upload - Invoice/AWB
--form 'file=@"/path/to/file"' \ - file
--form 'hash="{{hash}}"' Sample response
Success Scenario
- When a file is uploaded successfully:
{
"responseCode":"00",
"responseMsg":"File Uploaded Successfully"
}Failure Scenarios
- When there is an error in uploading the file:
{
"responseCode": "103",
"responseMsg": "Failed to Upload"
} - When the file format is not supported:
{
"responseCode": "105",
"responseMsg": "Not an PACB merchant, contact KAM"
} - When the payuid is invalid:
{
"responseCode":"107",
"responseMsg":"The PayuID in request is invalid"
}- When a mandatory field is missing:
{
"responseCode":"109",
"responseMsg":"All fields are mandatory, please check!"
} Response Code and Description
Updated 20 days ago
