# 3. Create payment

`POST https://api.royalpe.site/merchant/initial-payment`

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

## Request body

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

| Field | Type | Required | Description |
|---|---|---|---|
| `accessKey` | string | yes | Merchant access key |
| `secretKey` | string | yes | Merchant secret key |
| `amount` | number | yes | Payment amount in rupees: more than 0, at most 2 decimals |
| `redirectUrl` | string | yes | HTTPS URL to return the customer to after checkout |
| `webhookUrl` | string | yes | HTTPS endpoint for payment status updates, on the public internet |
| `userId` | string | yes | Merchant customer identifier (up to 2048 characters) |
| `orderId` | string | yes | Merchant order identifier, unique in your account (up to 2048 characters) |

```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":200,"redirectUrl":"https://merchant.com/payment/return","webhookUrl":"https://merchant.com/webhook/payment","userId":"user_101","orderId":"1234567890"}'
```

```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: 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 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" => 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 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": 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.

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

```json title="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](https://docs.royalpe.site/payin/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 field | Type | Description |
|---|---|---|
| `success` | boolean | API operation outcome |
| `message` | string | API response message |
| `data.paymentUrl` | string | Hosted checkout URL |
| `data.isUpiIntent` | boolean | Indicates direct UPI intent mode |
| `data.upiIntentUrl` | string | UPI app deep link, only when `isUpiIntent` is `true` |
| `data.token` | string | Checkout token (the last part of `paymentUrl`) |
| `data.orderId` | string | Merchant order ID |
| `data.transactionId` | string | Gateway transaction ID (`RP-…`) |
| `data.amount` | number | Always the amount you sent |
| `data.status` | string | Initial transaction state: `progress` |
| `data.userId` | string | Merchant 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](https://docs.royalpe.site/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

```json title="Error"
{ "success": false, "message": "Invalid access key or secret key" }
```

| HTTP code | 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` |
| 500 | `Something went wrong` |

---

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