# Create a pay-in

`POST https://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. |

```bash title="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"}'
```

```javascript title="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 title="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 title="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`

```json title="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"
  }
}
```

| 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](https://docs.royalpe.site/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 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](https://docs.royalpe.site/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

| 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](https://docs.royalpe.site/errors).

---

Source: https://docs.royalpe.site/payins/create · All docs: https://docs.royalpe.site/llms-full.txt · Updated 2026-11-30
