Home / Developer guide

Developer guide

Everything you need to collect UPI payments on your website, app or WhatsApp, from a no-code payment link to a full API integration with webhooks.

Choose your integration

There are three ways to use UPIDirect. Start with the one that fits you; you can add the others later.

How money flows

UPIDirect never touches the money. The payer’s bank sends it to your bank over UPI, to the UPI ID you set in Settings. We create the request, show the payment page, track the status and tell your systems.

1. Your servercreates a payment request with your secret key
2. Payeropens payment_url and taps “Pay with UPI”
3. UPI appmoves the money from their bank to yours
4. Confirmationthe UTR is checked and the request becomes paid
5. Webhookpayment_request.paid reaches your server
Base URL: https://upidirect.codepeacock.com/api. All amounts are in rupees, with up to 2 decimals: 2000, 2000.50 or 99.99. You may send a number or a string. The minimum is ₹1 and the maximum ₹5,00,000.
  1. Create an account and add your UPI ID under Settings.
  2. Click New payment link, enter the amount, what it is for and, if you like, the payer’s name and mobile number.
  3. Copy the link, or press WhatsApp to send it straight to the payer. The link page has a UPI button for phones and a QR code for computers.
  4. When the payer has paid and entered their UTR, the payment appears under To confirm. Check it in your bank app and press Received.

You can also put a link behind a “Pay now” button on any web page, in an email or in a PDF invoice. Each link is for one payment, so create a new link for each invoice or fee.

Keys and test mode

Create keys under Dashboard → Developers.

Keep secret keys on your server. Put them in an environment variable or a secrets manager. Never put them in browser JavaScript, a mobile app or a public repository. If a key leaks, revoke it in the dashboard and create a new one.

Send the key in the Authorization header: Authorization: Bearer sk_test_…. Check that a key works with GET /v1/me.

Website checkout

The usual website flow is: the customer clicks “Pay”, your server creates a payment request and redirects them to payment_url. After paying, they can come back to your return_url. Your server marks the order paid only when the payment_request.paid webhook arrives, never because the browser came back.

curl -X POST https://upidirect.codepeacock.com/api/v1/payment_requests \
  -H "Authorization: Bearer sk_test_..." \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: fee-stu_123-2026-12" \
  -d '{
    "amount": 2000.50,
    "purpose": "December fee",
    "customer": { "name": "Ravi Kumar", "phone": "9876543210", "external_ref": "stu_123" },
    "external_ref": "invoice_789",
    "return_url": "https://yoursite.com/fees/thanks",
    "metadata": { "student_id": "stu_123", "month": "2026-12" }
  }'

Create a payment request

POST /v1/payment_requests. Always send an Idempotency-Key header (for example your order ID). If you retry with the same key, you get the same request back instead of a duplicate.

FieldTypeDescription
amountnumber, requiredAmount in rupees, up to 2 decimals, from 1 to 500000 (e.g. 2000.94).
purposestring, requiredWhat the payment is for (up to 80 characters). Shown to the payer.
customerobjectname, phone (10 to 15 digits), email, external_ref (your customer ID).
external_refstringYour own ID for this payment, such as an order or invoice ID. Returned in webhooks.
return_urlURLWhere the payer can continue after the payment is confirmed.
expires_atISO 8601 date-timeWhen the link stops accepting payments. Default: 30 days.
metadataobjectUp to 20 keys of your own data (strings, numbers, booleans). Returned unchanged.

The response is 201 Created, or 200 when the same Idempotency-Key was used before.

The payment request object

{
  "id": "4b1c2f0e-…",
  "object": "payment_request",
  "reference": "UPD-7K2M9QX4",
  "mode": "test",
  "status": "pending",            // pending | paid | expired | cancelled | disputed
  "amount": 2000.50,
  "currency": "INR",
  "purpose": "December fee",
  "customer": { "name": "Ravi Kumar", "phone": "9876543210", "email": null, "external_ref": "stu_123" },
  "external_ref": "invoice_789",
  "metadata": { "student_id": "stu_123", "month": "2026-12" },
  "payment_url": "https://upidirect.codepeacock.com/r/UPD-7K2M9QX4",
  "upi_uri": null,                // live mode: the raw upi://pay link
  "awaiting_confirmation": false, // true once the payer has entered a UTR
  "confirmation": null,           // { "utr": "412345678901", … } when confirmed
  "return_url": "https://yoursite.com/fees/thanks",
  "expires_at": "2027-01-03T10:00:00.000Z",
  "paid_at": null,
  "created_at": "2026-12-04T10:00:00.000Z"
}

upi_uri is only set in live mode. Mobile apps can open it directly to launch the payer’s UPI app.

All endpoints

Method and pathWhat it does
POST /v1/payment_requestsCreate a payment request
GET /v1/payment_requests/:idGet one request
GET /v1/payment_requestsList requests, newest first. Filters: status, external_ref, limit (up to 100), starting_after (an ID, for paging)
POST /v1/payment_requests/:id/cancelCancel a pending request
POST /v1/payment_requests/:id/confirmMark as received, optionally with { "utr": "412345678901" }
GET /v1/webhook_endpointsList webhook URLs
POST /v1/webhook_endpointsAdd a webhook URL: { "url": "https://…" }
DELETE /v1/webhook_endpoints/:idRemove a webhook URL
GET /v1/meCheck which account and mode a key belongs to

Webhook events

Add your webhook URL under Dashboard → Developers (separately for test and live) and copy its signing secret (whsec_…).

EventWhen it is sent
payment_request.paidThe payment is confirmed. Fulfil the order here.
payment_request.utr_submittedThe payer says they have paid and entered a UTR. It is waiting for your check.
payment_request.expiredThe link expired before it was paid.
payment_request.cancelledThe request was cancelled.

Each delivery is a POST with a JSON body { id, type, mode, created_at, data }, where data is the payment request object. Headers: UPD-Signature, UPD-Event-Id and UPD-Event-Type.

Reply with any 2xx status within a few seconds. If your server fails or times out, we retry with increasing delays for 24 hours. Because of retries, the same event can arrive more than once: store UPD-Event-Id and ignore repeats, and make your update idempotent (for example UPDATE … WHERE status <> 'paid').

Verify webhook signatures

The UPD-Signature header looks like t=1764842400,v1=5f2b…. v1 is the hex HMAC-SHA256 of "{t}.{raw body}" with your signing secret. Always verify it, and reject events older than five minutes. Use the raw request body: parsing and re-serialising the JSON changes the bytes and the check fails.

import { createHmac, timingSafeEqual } from 'node:crypto'

function verifyUpiDirect(rawBody, header, secret) {
  const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header ?? '')
  if (!m) return false
  const [, t, sig] = m
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false // older than 5 minutes
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex')
  return timingSafeEqual(Buffer.from(expected), Buffer.from(sig))
}

// Express: read the RAW body, never re-serialised JSON
app.post('/upidirect/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const raw = req.body.toString('utf8')
  if (!verifyUpiDirect(raw, req.get('UPD-Signature'), process.env.UPIDIRECT_WEBHOOK_SECRET)) return res.sendStatus(400)
  const event = JSON.parse(raw)
  if (await db.events.seen(event.id)) return res.sendStatus(200) // retries can repeat an event
  if (event.type === 'payment_request.paid') {
    await db.orders.markPaid(event.data.external_ref, { utr: event.data.confirmation?.utr })
  }
  await db.events.remember(event.id)
  res.sendStatus(200)
})

Example: Supabase Edge Functions

This is how School of Carnatic Music connects its fee system:

  1. Store the keys as secrets: supabase secrets set UPIDIRECT_SECRET_KEY=sk_test_… UPIDIRECT_WEBHOOK_SECRET=whsec_…
  2. Edge Function create-fee-payment: checks the logged-in parent, loads the fee, calls POST /v1/payment_requests with external_ref and Idempotency-Key set to the fee ID, and returns payment_url to the app.
  3. Edge Function upidirect-webhook (public URL, added in the dashboard): verifies the signature with the Node.js code above (it works in Deno with node:crypto and node:buffer), and on payment_request.paid marks the fee with id = data.external_ref as paid.
  4. Test end to end with a test key and the Simulate successful payment button, then switch to the live key.

How payments are confirmed

UPI does not send an automatic receipt to a personal or business UPI ID, so today a request becomes paid when:

Next, we are adding automatic matching from your bank statement, and later direct bank connections for real-time confirmation. Your integration does not change: you always just listen for payment_request.paid.

Errors and retries

Errors always have the same shape:

{ "error": { "code": "invalid_request", "message": "amount: must be between ₹1 and ₹5,00,000" } }
StatusMeaning
400The request is invalid. The message says which field.
401The API key is missing, wrong or revoked.
404No such payment request for this key’s account and mode.
409The action does not fit the current status (for example cancelling a paid request).
429Too many requests. Wait a moment and retry.
5xxOur side failed. Retry with the same Idempotency-Key.

Go-live checklist

Get help

Stuck on an integration? Write to info@codepeacock.com with your business name and, if you have one, the payment reference (UPD-…). Never send us your secret key.

Share UPIDirect: WhatsApp LinkedIn X Facebook Email