RRoyal Pay API docs
Menu

Create a pay-in

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

Creates a pay-in for one of your users and returns the checkout link to send them to.

Request #

Send JSON with Content-Type: application/json.

FieldTypeRequiredDescription
accessKeystringyesYour access key.
secretKeystringyesYour secret key.
amountnumberyesAmount in rupees: more than 0, at most 2 decimals (500, 499.50).
orderIdstringyesYour own ID for this deposit, unique in your account (max 2048 characters). Makes the call safe to retry.
userIdstringyesYour ID for the user who pays. It comes back in the webhook.
webhookUrlstringyesHTTPS address on your server that receives this pay-in's results. It must be on the public internet.
redirectUrlstringyesHTTPS address the checkout's "Return to …" button takes your user to.
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":500,"orderId":"ORDER-10045","userId":"USER-881","webhookUrl":"https://shop.example.com/royalpay/webhook","redirectUrl":"https://shop.example.com/deposit/done"}'
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: 500,
    orderId: "ORDER-10045",
    userId: "USER-881",
    webhookUrl: "https://shop.example.com/royalpay/webhook",
    redirectUrl: "https://shop.example.com/deposit/done",
  }),
});
const { success, message, data } = await res.json();
if (!success) throw new Error(message);
// Save data.transactionId with your order, then redirect the user 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" => 500,
    "orderId" => "ORDER-10045",
    "userId" => "USER-881",
    "webhookUrl" => "https://shop.example.com/royalpay/webhook",
    "redirectUrl" => "https://shop.example.com/deposit/done",
  ]),
]);
$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": 500,
    "orderId": "ORDER-10045",
    "userId": "USER-881",
    "webhookUrl": "https://shop.example.com/royalpay/webhook",
    "redirectUrl": "https://shop.example.com/deposit/done",
}, timeout=15).json()
payment_url = res["data"]["paymentUrl"]

Response #

200 OK

200
{
  "success": true,
  "message": "Payment URL generated successfully",
  "data": {
    "paymentUrl": "https://pay.royalpe.site/gateway/Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp",
    "orderId": "ORDER-10045",
    "transactionId": "RP-7f3a9c21d84e5b02",
    "amount": 500,
    "status": "progress",
    "userId": "USER-881"
  }
}
FieldTypeDescription
paymentUrlstringThe hosted checkout for this pay-in. Redirect your user here, in the same browser they'll pay from.
transactionIdstringRoyal Pay's ID for the pay-in (RP-…). Store it: status calls and webhooks use it.
orderIdstringYour orderId, as sent.
amountnumberThe amount in rupees.
statusstringAlways progress for a new pay-in. See Statuses.
userIdstringYour userId, as sent.

Retrying safely #

orderId makes this call idempotent. If a call times out, send the exact same request again:

  • Same orderId, same details (userId, amount, webhookUrl, redirectUrl): you get the same pay-in back, with the same paymentUrl.
  • Same orderId, different details: 409 with Order ID already used with different details. Use a new orderId for a new deposit.

Things to know #

  • One link, one browser. The first browser that opens paymentUrl owns that checkout. Don't open it yourself (for example in a test or link-preview step). See Hosted checkout.
  • Leaving cancels. If your user closes the checkout before paying, the pay-in is cancelled and you get a webhook. Create a new pay-in (with a new orderId) if they try again.
  • Limits. Pay-ins outside your account's deposit limits, or while new payments are paused (409), are refused. Ask Royal Pay for your limits.

Errors #

HTTPmessage
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

All errors: Errors.