RRoyal Pay API docs
Menu

3. Create payment

POSThttps://api.royalpe.site/merchant/initial-payment

Creates a payment order and returns the payment URL and transaction metadata.

Request body #

JSON
{
  "accessKey": "merchant_abc123",
  "secretKey": "secret_xyz456",
  "amount": 200,
  "redirectUrl": "https://merchant.com/payment/return",
  "webhookUrl": "https://merchant.com/webhook/payment",
  "userId": "user_101",
  "orderId": "1234567890"
}
FieldTypeRequiredDescription
accessKeystringyesMerchant access key
secretKeystringyesMerchant secret key
amountnumberyesPayment amount in rupees: more than 0, at most 2 decimals
redirectUrlstringyesHTTPS URL to return the customer to after checkout
webhookUrlstringyesHTTPS endpoint for payment status updates, on the public internet
userIdstringyesMerchant customer identifier (up to 2048 characters)
orderIdstringyesMerchant order identifier, unique in your account (up to 2048 characters)
cURL
curl -X POST https://api.royalpe.site/merchant/initial-payment \
  -H "Content-Type: application/json" \
  -d '{"accessKey":"YOUR_ACCESS_KEY","secretKey":"YOUR_SECRET_KEY","amount":200,"redirectUrl":"https://merchant.com/payment/return","webhookUrl":"https://merchant.com/webhook/payment","userId":"user_101","orderId":"1234567890"}'
Node.js
const res = await fetch("https://api.royalpe.site/merchant/initial-payment", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    accessKey: process.env.ROYALPAY_ACCESS_KEY,
    secretKey: process.env.ROYALPAY_SECRET_KEY,
    amount: 200,
    redirectUrl: "https://merchant.com/payment/return",
    webhookUrl: "https://merchant.com/webhook/payment",
    userId: "user_101",
    orderId: "1234567890",
  }),
});
const { success, message, data } = await res.json();
if (!success) throw new Error(message);
// Store data.transactionId with the order, then redirect the customer to data.paymentUrl
PHP
$ch = curl_init("https://api.royalpe.site/merchant/initial-payment");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode([
    "accessKey" => getenv("ROYALPAY_ACCESS_KEY"),
    "secretKey" => getenv("ROYALPAY_SECRET_KEY"),
    "amount" => 200,
    "redirectUrl" => "https://merchant.com/payment/return",
    "webhookUrl" => "https://merchant.com/webhook/payment",
    "userId" => "user_101",
    "orderId" => "1234567890",
  ]),
]);
$res = json_decode(curl_exec($ch), true);
// header("Location: " . $res["data"]["paymentUrl"]);
Python
import os, requests

res = requests.post("https://api.royalpe.site/merchant/initial-payment", json={
    "accessKey": os.environ["ROYALPAY_ACCESS_KEY"],
    "secretKey": os.environ["ROYALPAY_SECRET_KEY"],
    "amount": 200,
    "redirectUrl": "https://merchant.com/payment/return",
    "webhookUrl": "https://merchant.com/webhook/payment",
    "userId": "user_101",
    "orderId": "1234567890",
}, timeout=15).json()
payment_url = res["data"]["paymentUrl"]

Success response: hosted checkout #

When data.isUpiIntent is false, direct the customer to data.paymentUrl. The response excludes upiIntentUrl. The hosted checkout offers the UPI apps (PhonePe, Google Pay, Paytm and others) itself.

200
{
  "success": true,
  "message": "Payment URL generated successfully",
  "data": {
    "paymentUrl": "https://pay.royalpe.site/gateway/Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp",
    "isUpiIntent": false,
    "token": "Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp",
    "orderId": "1234567890",
    "transactionId": "RP-7f3a9c21d84e5b02",
    "amount": 200,
    "status": "progress",
    "userId": "user_101"
  }
}

Success response: UPI intent #

When data.isUpiIntent is true, open data.upiIntentUrl on the customer's device to launch the UPI app with the payee and amount filled in. UPI intent mode is switched on per merchant by Royal Pay, and applies when the pay-in is paid to a UPI ID (bank-transfer pay-ins stay false).

200
{
  "success": true,
  "message": "Payment URL generated successfully",
  "data": {
    "paymentUrl": "https://pay.royalpe.site/gateway/Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp",
    "isUpiIntent": true,
    "upiIntentUrl": "upi://pay?pa=merchant%40example&pn=Example+Merchant&am=248.75&cu=INR&tn=RP-1796040981234-04821",
    "token": "Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp",
    "orderId": "1234567890",
    "transactionId": "RP-7f3a9c21d84e5b02",
    "amount": 248.75,
    "status": "progress",
    "userId": "user_101"
  }
}

After paying in the app, the customer still needs to prove the payment: send them to paymentUrl to upload the screenshot, or submit their UTR with 6. Manual UTR upload. Payment apps may show a warning, or refuse, for links to offline merchant QR IDs. Scanning the checkout's QR always works.

Response fieldTypeDescription
successbooleanAPI operation outcome
messagestringAPI response message
data.paymentUrlstringHosted checkout URL
data.isUpiIntentbooleanIndicates direct UPI intent mode
data.upiIntentUrlstringUPI app deep link, only when isUpiIntent is true
data.tokenstringCheckout token (the last part of paymentUrl)
data.orderIdstringMerchant order ID
data.transactionIdstringGateway transaction ID (RP-…)
data.amountnumberAlways the amount you sent
data.statusstringInitial transaction state: progress
data.userIdstringMerchant customer identifier

Retrying safely #

orderId makes this call idempotent:

  • Same orderId, same details (userId, amount, webhookUrl, redirectUrl): the same pay-in comes back, with the same paymentUrl.
  • Same orderId, different details: 409 with Order ID already used with different details.

Things to know #

  • One link, one browser. The first browser that opens paymentUrl owns that checkout. Redirect the customer to it directly; don't open it first from a bot or preview tool. See Hosted checkout.
  • Leaving cancels. If the customer leaves the checkout before submitting payment proof, the pay-in becomes cancelled and you get a webhook. Create a new pay-in, with a new orderId, if they try again.

Error responses #

Error
{ "success": false, "message": "Invalid access key or secret key" }
HTTP codeMessage
400Access key is required, Secret key is required, orderId is required, userId is required, webhookUrl is required, redirectUrl is required
400Invalid amount, A valid HTTPS URL is required
401Invalid access key or secret key
409Order ID already used with different details, New payments are paused for this merchant
500Something went wrong