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.
| Field | Type | Required | Description |
|---|---|---|---|
accessKey | string | yes | Your access key. |
secretKey | string | yes | Your secret key. |
amount | number | yes | Amount in rupees: more than 0, at most 2 decimals (500, 499.50). |
orderId | string | yes | Your own ID for this deposit, unique in your account (max 2048 characters). Makes the call safe to retry. |
userId | string | yes | Your ID for the user who pays. It comes back in the webhook. |
webhookUrl | string | yes | HTTPS address on your server that receives this pay-in's results. It must be on the public internet. |
redirectUrl | string | yes | HTTPS address the checkout's "Return to …" button takes your user to. |
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"}'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$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"]);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
{
"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"
}
}| Field | Type | Description |
|---|---|---|
paymentUrl | string | The hosted checkout for this pay-in. Redirect your user here, in the same browser they'll pay from. |
transactionId | string | Royal Pay's ID for the pay-in (RP-…). Store it: status calls and webhooks use it. |
orderId | string | Your orderId, as sent. |
amount | number | The amount in rupees. |
status | string | Always progress for a new pay-in. See Statuses. |
userId | string | Your 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 samepaymentUrl. - Same
orderId, different details:409withOrder ID already used with different details. Use a neworderIdfor a new deposit.
Things to know #
- One link, one browser. The first browser that opens
paymentUrlowns 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
cancelledand you get a webhook. Create a new pay-in (with a neworderId) 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 #
| HTTP | message |
|---|---|
| 400 | Access key is required, Secret key is required, orderId is required, userId is required, webhookUrl is required, redirectUrl is required |
| 400 | Invalid amount, A valid HTTPS URL is required |
| 401 | Invalid access key or secret key |
| 409 | Order ID already used with different details, New payments are paused for this merchant |
All errors: Errors.