PayNexa API integration
Server-side order creation, hosted checkout, signed webhooks and integration examples.
Overview
With PayNexa you can accept UPI payments on your website. The customer pays by scanning a QR or using a UPI app, the payment is auto-verified from the bank’s email, and your server receives a signed webhook.
- Your server creates an order via the API → you get a
checkout_url. - Send the customer to the checkout page (redirect) or open it as a popup on your site.
- The customer pays the value in the
amountfield. - PayNexa matches the payment against the bank email → the order becomes
paid. - The webhook arrives → you fulfil the order.
amount, not the requested_amount. That is how the payment is matched to the right order.Base URL: https://YOUR_DOMAIN · All requests/responses are JSON. Currency is always INR, amounts in rupees.
Quick start
- Create a
pv_test_…API key on the dashboard’s API page. Keep the key only on your server. - Create a test order from your server:
curl -X POST https://YOUR_DOMAIN/api/v1/orders \
-H "Authorization: Bearer pv_test_xxx" \
-H "Content-Type: application/json" \
-d '{"amount":149,"order_id":"INV-1001","return_url":"https://yoursite.com/thanks"}'- Open the response’s
checkout_urlin the browser → press Simulate payment in the sandbox. - Enter your URL in API → Webhooks, press Send test event, and verify the signature.
- After the test passes, switch to a live API key and verify the live webhook signature.
Authentication
Send the API key with every request:
Authorization: Bearer pv_live_xxxxxxxxxxxxxxxx(The X-API-Key: <key> header also works.) Keep the API key only on your server — never in a browser, JS, or mobile app.
| Item | Detail |
|---|---|
| Live key | pv_live_… — real UPI payments. |
| Test key | pv_test_… — sandbox; works without a UPI ID, no real payment is matched. |
| Scopes | orders:read (GET) and orders:write (POST, simulate). With fewer permissions you get 403 insufficient_scope. |
| Mode header | Every response carries X-PayVerify-Mode: live|test. Live and test orders are separate — one key cannot see the other mode’s orders. |
Create an order
/api/v1/ordersorders:write
| Field | Type | Detail |
|---|---|---|
amount * | number | Bill in rupees (149 or 149.50). ₹1 to ₹1,00,000. |
order_id | string | Your own reference (max 100). Calling again with the same order_id returns the same pending/paid order (200). |
customer_name | string | Max 100 characters. |
note | string | Max 200 characters. |
return_url | string | After payment, a "Back to merchant" button appears on checkout. It must start with http(s)://. |
A new order returns 201, a reused order returns 200. An order stays valid for 5 minutes by default (the merchant can set 3–30 minutes in Branding → Checkout options; read expires_at from the order).
curl -X POST https://YOUR_DOMAIN/api/v1/orders \
-H "Authorization: Bearer $PAYVERIFY_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-INV-1001" \
-d '{"amount":149,"order_id":"INV-1001","customer_name":"Rahul","note":"Pro plan","return_url":"https://yoursite.com/thanks"}'Response
{
"id": "A1B2C3D4E5F60718",
"order_id": "INV-1001",
"status": "pending",
"currency": "INR",
"livemode": true,
"requested_amount": 149,
"amount": 149.37,
"checkout_url": "https://YOUR_DOMAIN/pay/A1B2C3D4E5F60718",
"customer_name": "Rahul",
"note": "Pro plan",
"created_at": "2026-12-01T10:00:00.000Z",
"expires_at": "2026-12-01T10:05:00.000Z",
"paid_at": null,
"utr": null
}Idempotency
Send the Idempotency-Key header (1–200 printable characters). A network retry will not create a duplicate order:
- Same key + same body (up to 24 hours) → the same response, with header
Idempotent-Replayed: true. - Same key + different body →
422 idempotency_key_reuse. - Tie the key to your order (
"order-" + orderId) — do not generate a random UUID on every call, or retries gain nothing.
Retrieve & list orders
/api/v1/orders/:idorders:read
curl https://YOUR_DOMAIN/api/v1/orders/A1B2C3D4E5F60718 \
-H "Authorization: Bearer $PAYVERIFY_KEY"Returns the order object (as above); if not found, 404 not_found. Before fulfilling, this call (or the webhook) is the trusted source.
/api/v1/orders| Query | Detail |
|---|---|
order_id | Search by your reference. |
status | pending | paid | expired | late_paid |
limit | Default 20, max 100. Newest orders first. |
{ "data": [ { /* order */ }, { /* order */ } ] }Order object & statuses
| Field | Detail |
|---|---|
id | PayNexa order ID (also in the checkout URL). |
order_id | Your reference (or null). |
status | pending, paid, late_paid, expired. |
requested_amount | Your bill. |
amount | What the customer must pay (bill + 1–99 paise). |
livemode | false = sandbox order. |
created_at, expires_at, paid_at | ISO 8601 UTC. |
utr | The bank’s UPI Ref/UTR (once paid). |
| Status | Meaning | What you do |
|---|---|---|
pending | Waiting for payment (5 min). | Nothing. |
paid | Verified from the email. | Fulfil the order. |
expired | No payment arrived within 5 min. | Create a new order. |
late_paid | The correct amount arrived after expiry (within 30 min). | In the merchant dashboard, Approve (→ paid) or Reject (→ expired, refund manually). Do not fulfil until then. |
Checkout: redirect & popup
1. Redirect
Send the customer straight to checkout_url. After payment, the return_url button appears.
2. Popup (checkout.js)
The customer stays on your site. Create the order on your server, and give only the checkout_url to the browser:
<script src="https://YOUR_DOMAIN/checkout.js"></script>
<script>
PayVerify.open({
url: checkoutUrlFromYourServer,
redirect: false, // true = send to return_url on "done"
onSuccess: function (e) { /* e.orderId, e.status — UI only */ },
onLate: function (e) {},
onExpired: function (e) {},
onClose: function (e) { /* e.reason: user | done | api | replaced */ }
});
</script>
<!-- without JS -->
<button data-payverify-url="https://YOUR_DOMAIN/pay/ORDER_ID">Pay now</button>GET /api/v1/orders/:id.Parameters: ?embed=1 for the iframe layout. Only /pay/:id can open in any site’s iframe; other pages stay same-origin. postMessage only sends status/orderId, and checkout.js only listens to messages from its own iframe’s origin.
Webhooks
Set the URL in API → Webhooks. Every event is POSTed to your URL:
| Event | When |
|---|---|
order.paid | Payment verified (or a late payment was approved). |
order.late_paid | Payment arrived after expiry — for review. |
order.expired | Order expired without payment. |
webhook.test | "Send test event" from the API page (data.message, no order). |
{
"id": "evt_9f2c7a1e0b1d4c539d6f2f4f",
"type": "order.paid",
"created": 1764583200,
"livemode": true,
"data": { "order": { /* order object */ } }
}Headers
| Header | Detail |
|---|---|
X-PayVerify-Signature | t=<unix>,v1=<hex> — v1 = HMAC-SHA256(secret, t + "." + rawBody). t is new on every attempt. |
X-PayVerify-Event | Event type. |
X-PayVerify-Event-Id | Event ID (same on retry). |
X-PayVerify-Delivery, -Attempt | Delivery number and which attempt (1…8). |
Verify the signature
The secret is in API → Webhooks (you can rotate it too). The signature is built on the raw body — if you parse the JSON and stringify it again, it will not match.
const express = require("express");
const crypto = require("crypto");
const app = express();
// Need the RAW body — do not use express.json() on this route
app.post("/payverify/webhook", express.raw({ type: "application/json" }), (req, res) => {
const header = req.get("X-PayVerify-Signature") || "";
const t = (header.match(/t=(\d+)/) || [])[1];
const v1 = (header.match(/v1=([a-f0-9]+)/) || [])[1];
if (!t || !v1) return res.sendStatus(400);
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return res.sendStatus(400); // replay guard (5 min)
const raw = req.body.toString("utf8");
const expected = crypto.createHmac("sha256", process.env.PAYVERIFY_WEBHOOK_SECRET)
.update(t + "." + raw).digest("hex");
const a = Buffer.from(expected), b = Buffer.from(v1);
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) return res.sendStatus(400);
const event = JSON.parse(raw);
// 1) Dedupe by event.id (retries send the same id)
// 2) Verify/fulfil the order:
if (event.type === "order.paid") {
const order = event.data.order; // order.order_id = your reference, order.amount = paid amount
// markPaid(order.order_id, order.id, order.utr);
}
res.sendStatus(200); // 2xx = delivered
});Delivery rules
- Return 2xx (within 10 seconds). Otherwise it retries: 30s → 2m → 10m → 1h → 4h → 12h → 24h (1 + 7 attempts).
- On retry, the same event
idarrives — do not process duplicates. Events have no ordering guarantee. - When retries are exhausted, a 🔔 alert appears in the dashboard. The delivery log (30 days), Resend button, and attempt details are on the API page.
- The webhook URL must be a public
httpsURL — localhost/private IPs are blocked (SSRF guard), redirects are not followed, and credentials in the URL are not allowed. - Webhooks are sent only for orders made via the API (not dashboard test orders).
Sandbox (test mode)
Orders made with a pv_test_… key are test orders: they are created without a UPI ID, are never matched against real email verification, and are not counted in analytics. The checkout shows Simulate payment / expiry buttons.
/api/v1/orders/:id/simulateorders:write, test key only
curl -X POST https://YOUR_DOMAIN/api/v1/orders/A1B2C3D4E5F60718/simulate \
-H "Authorization: Bearer pv_test_xxx" -H "Content-Type: application/json" \
-d '{"outcome":"paid"}'outcome: paid | late_paid | expired (default paid). The webhook fires too (livemode:false). Calling with a live key gives 403 sandbox_only; a wrong state gives 409 invalid_state.
Errors
Errors always have this shape:
{ "error": { "code": "invalid_amount", "message": "amount is required (in rupees, e.g. 149 or 149.50)" } }| HTTP | code | Meaning |
|---|---|---|
| 400 | invalid_amount, invalid_request | Amount outside ₹1–₹1,00,000, bad return_url, or UPI ID not set (live). |
| 400 | invalid_idempotency_key | The key must be 1–200 printable characters. |
| 401 | missing_api_key, invalid_api_key | Header missing, or the key is wrong/revoked. |
| 403 | insufficient_scope | The key lacks the required permission. |
| 403 | account_suspended | The merchant account is suspended. |
| 403 | sandbox_only | Simulate works only with a test key. |
| 404 | not_found | Order/endpoint not found (or it belongs to the other mode). |
| 409 | invalid_state | This action is not possible in the order’s current state. |
| 422 | idempotency_key_reuse | Same key, different body. |
| 429 | rate_limited | Limit exceeded (see below). Wait a little and retry. |
| 503 / 500 | error | Server busy or error — retry with backoff (safe with an Idempotency-Key). |
Limits
| Item | Limit |
|---|---|
| Amount | ₹1 – ₹1,00,000 per order |
| Create orders | 120 requests / minute / key |
| Read (GET) | 600 requests / minute / key |
| Order validity | 5 minutes; then a 30-minute late-payment review window |
| Field lengths | order_id 100, customer_name 100, note 200 |
| Idempotency | 24 hours |
| Webhook timeout | 10 seconds; retry up to 8 attempts; delivery log 30 days |
| Request body | 100 KB |
Postman collection
Ready-made collection: create / get / list / simulate, plus a request that sends a signed test event to your webhook endpoint (the pre-request script builds the signature itself).
In Postman, click Import → set baseUrl (https://YOUR_DOMAIN) and apiKey (a pv_test_… key first) in the collection’s Variables. orderId is saved automatically after the create request. For the webhook test, also set webhookUrl and webhookSecret.
WordPress plugin sample
A small plugin: a pay button via shortcode, a server-side order on click, popup checkout, and a signature-verified webhook. (A WooCommerce gateway is not included yet.)
wp-content/plugins/payverify-pay-button/payverify-pay-button.phpput the code below.wp-config.phpdefinePAYVERIFY_KEYandPAYVERIFY_WEBHOOK_SECRET.- URL in API → Webhooks:
https://yoursite.com/wp-json/payverify/v1/webhook. - Add
[payverify_button amount="149" label="Pay ₹149"]to a page.
<?php
/**
* Plugin Name: PayNexa Pay Button
* Description: [payverify_button amount="149" label="Pay ₹149"] shortcode + signed webhook endpoint.
*/
if (!defined("ABSPATH")) exit;
define("PAYVERIFY_BASE", "https://YOUR_DOMAIN");
// Put this in wp-config.php (not in the plugin file):
// define("PAYVERIFY_KEY", "pv_live_...");
// define("PAYVERIFY_WEBHOOK_SECRET", "...");
add_action("wp_enqueue_scripts", function () {
wp_enqueue_script("payverify", PAYVERIFY_BASE . "/checkout.js", [], null, true);
});
// The amount is signed so a visitor cannot change it in the browser
add_shortcode("payverify_button", function ($atts) {
$a = shortcode_atts(["amount" => "100", "label" => "Pay now"], $atts);
$amount = (float) $a["amount"];
$sig = hash_hmac("sha256", (string) $amount, wp_salt("auth"));
return sprintf('<button type="button" class="payverify-btn" data-amount="%s" data-sig="%s">%s</button>',
esc_attr($amount), esc_attr($sig), esc_html($a["label"]));
});
// The order is created on click (not on page view)
foreach (["wp_ajax_payverify_create", "wp_ajax_nopriv_payverify_create"] as $hook) {
add_action($hook, function () {
$amount = (float) ($_POST["amount"] ?? 0);
$good = hash_hmac("sha256", (string) $amount, wp_salt("auth"));
if (!hash_equals($good, (string) ($_POST["sig"] ?? ""))) wp_send_json_error("bad signature", 400);
$order_id = "WP-" . wp_generate_uuid4();
$res = wp_remote_post(PAYVERIFY_BASE . "/api/v1/orders", [
"timeout" => 15,
"headers" => [
"Authorization" => "Bearer " . PAYVERIFY_KEY,
"Content-Type" => "application/json",
"Idempotency-Key" => "order-" . $order_id,
],
"body" => wp_json_encode(["amount" => $amount, "order_id" => $order_id, "return_url" => home_url("/")]),
]);
if (is_wp_error($res) || wp_remote_retrieve_response_code($res) >= 400) wp_send_json_error("order failed", 502);
$data = json_decode(wp_remote_retrieve_body($res), true);
wp_send_json_success(["url" => $data["checkout_url"]]);
});
}
add_action("wp_footer", function () { ?>
<script>
document.addEventListener("click", function (e) {
var b = e.target.closest(".payverify-btn"); if (!b) return;
b.disabled = true;
var f = new FormData();
f.append("action", "payverify_create"); f.append("amount", b.dataset.amount); f.append("sig", b.dataset.sig);
fetch("<?php echo esc_js(admin_url("admin-ajax.php")); ?>", { method: "POST", body: f })
.then(function (r) { return r.json(); })
.then(function (j) {
b.disabled = false;
if (j.success) PayVerify.open({ url: j.data.url, onSuccess: function () { /* UI only */ } });
else alert("Could not start the payment, please try again.");
})
.catch(function () { b.disabled = false; });
});
</script>
<?php });
// Webhook URL: https://yoursite.com/wp-json/payverify/v1/webhook
add_action("rest_api_init", function () {
register_rest_route("payverify/v1", "/webhook", [
"methods" => "POST",
"permission_callback" => "__return_true",
"callback" => function (WP_REST_Request $r) {
$raw = $r->get_body();
$hdr = (string) $r->get_header("X-PayVerify-Signature");
if (!preg_match('/t=(\d+)/', $hdr, $t) || !preg_match('/v1=([a-f0-9]+)/', $hdr, $v)
|| abs(time() - (int) $t[1]) > 300) return new WP_REST_Response(["error" => "bad signature"], 400);
$expected = hash_hmac("sha256", $t[1] . "." . $raw, PAYVERIFY_WEBHOOK_SECRET);
if (!hash_equals($expected, $v[1])) return new WP_REST_Response(["error" => "bad signature"], 400);
$event = json_decode($raw, true);
// Dedupe: store $event["id"] in an option/transient
if ($event["type"] === "order.paid") do_action("payverify_order_paid", $event["data"]["order"]);
return new WP_REST_Response(["ok" => true], 200);
},
]);
});
// In your code: add_action("payverify_order_paid", function ($order) { /* fulfil */ });Go-live checklist
- The live API key is kept only in server-side secret storage; not in a browser or repository.
- The production webhook URL verifies the signature from the raw request body.
- Orders are created only from the server; the API key is not in a browser/repo.
- The webhook signature is verified (raw body, timing-safe compare, 5 min tolerance).
- Fulfil only on
order.paid;late_paidonly after manual review. - Events are deduped by
id; the endpoint returns 2xx within 10 seconds. - Do not trust browser callbacks (
onSuccess) — UI only. - All three flows (paid / late_paid / expired) tested in the sandbox.
- The live key (
pv_live_…) is in a separate env var; you can Rotate it when needed.