How to Avoid Duplicate Charges on UPI Payment APIs: Idempotent Orders and Webhook Handling in 2026
A customer pays once. Your webhook fires twice. Somewhere in between, an order gets fulfilled twice, or not at all, and a support ticket lands in your inbox with the words "I was charged but got nothing." I've had this conversation with more than one merchant building on the UroPay API, and almost every time the root cause is the same: the integration treated a webhook as a guarantee instead of a hint. This post is the write-up I wish I could point people to before it happens, not after.
Why UPI webhooks are unreliable by design, not by accident
Every payment gateway's webhook system, UroPay's included, is built on a "best-effort" delivery promise. A webhook call can arrive late, arrive twice, arrive out of order relative to an earlier event, or not arrive at all if your endpoint was down for a few minutes. This isn't a quality problem specific to any one provider. It's the nature of sending an HTTP request across the internet to a server you don't control, with no guarantee it's listening at that exact moment.
UPI adds its own layer of timing weirdness on top. NPCI's own transaction status check API comes with hard usage limits precisely because banks got overwhelmed by naive polling: PSP and acquiring banks are instructed to wait 90 seconds before the first status check, and to make no more than three status checks per transaction, generally within a two-hour window, according to reporting on NPCI's directive to banks (Inc42). Over-querying that API doesn't just annoy NPCI. It slows the whole queue down for everyone, including the transaction you're trying to check on. If your integration's answer to "did this webhook get lost?" is "poll harder," you're the reason the next outage happens.
The practical upshot: your code has to assume duplicates, gaps, and reordering are normal traffic, not edge cases. That assumption is what "idempotent" actually means here. It's not a synonym for "reliable." It's an admission that the network is unreliable, and a design choice that makes unreliability harmless.
What idempotency means for a payment order, specifically
An idempotent operation produces the same result no matter how many times it's applied. For a UPI order, that means: if your system processes the same payment confirmation five times, exactly one order gets marked paid, exactly one confirmation email goes out, and exactly one unit of inventory gets reserved. The fourth and fifth deliveries of that event should be a no-op, not a repeat.
Two identifiers do the actual work here, and they cover different halves of the problem. The first is your own idempotency key on the request side, so that retrying a create-order call doesn't create two orders for one purchase. The second is a unique event identifier on the notification side, so that a webhook firing twice doesn't trigger your fulfillment logic twice. Miss either one and you get a different flavor of the same bug: double-charging a customer, or double-shipping a product you were only paid for once.
How the UroPay API handles the request side: tenantOrderRef
On POST /v1/orders, you supply your own tenantOrderRef as the idempotency key, alongside the amount and currency. Send the same tenantOrderRef with the same payload twice, on purpose or because your first request timed out and your code retried it, and the API reference documents a 200 response returning the original order, not a fresh one. Send the same tenantOrderRef with a different amount, and you get a 409 instead, because that's not a safe retry anymore, it's a conflicting request pretending to be one. A brand-new tenantOrderRef gets you a 201 and a new order.
That three-way split (201 for new, 200 for a matching retry, 409 for a conflicting one) is doing more work than it looks like. It means your integration doesn't have to build its own "have I already created this order?" check before calling the API. You generate a tenantOrderRef once, at the moment your checkout button is clicked, and it's safe to retry the create-order call as many times as a flaky connection demands. The API guarantees you only ever get one real order for one genuine purchase attempt.
How UroPay handles the notification side: advisory webhook, authoritative GET
Here's the part that trips people up most: the order status webhook is explicitly not the source of truth. UroPay's own documentation states it plainly: delivery is best-effort, failed or blocked deliveries are logged and dropped rather than retried forever, and GET /v1/orders/{orderId} is the authoritative check. If your business logic only reacts to the webhook and never falls back to the GET endpoint, a single dropped delivery becomes an order that sits unpaid in your system forever, even though the customer's money already landed.
The webhook payload carries an eventId, a UUID unique to that delivery attempt group, specifically so your handler can be idempotent on it. The pattern that works: when a webhook arrives, check whether you've already processed that eventId. If you have, acknowledge it and stop. If you haven't, verify its HMAC-SHA256 signature (computed the same way as outbound request signing, over the path /tenant-webhook), process it, and record the eventId as done before you return a response. Recording it before you finish, not just after, matters if your own processing is slow enough that a retry could land mid-handling.
One more wrinkle worth planning for: UroPay recently added a CANCELLED status alongside PAID, FAILED, and EXPIRED, specifically for orders the customer explicitly abandoned rather than ones that simply timed out. If your webhook handler uses a switch statement on status without a default branch, a status value your code wasn't written to expect can fall through silently. Build the default branch in from day one; API surfaces add states over time, and yours should degrade safely rather than break.
The replay protection you get for free, and the one you have to build yourself
UroPay signs every request, outbound and inbound, with HMAC-SHA256 over a canonical string that includes an X-Timestamp and a client-generated X-Nonce. Requests are rejected with a 401 if the timestamp is more than 300 seconds old or more than 30 seconds in the future, and each nonce can only be used once per merchant. That protects the API from replay attacks on the request side automatically, you don't have to build timestamp checking yourself to call the API safely.
What you do have to build yourself is the mirror image: verifying that same signature scheme on webhooks you receive, and deduplicating on eventId in your own database. UroPay hands you the cryptographic primitive and the unique identifier. Turning that into an idempotent handler, with a table tracking which eventIds you've already processed, is integration work on your side, the same as it would be with any provider.
How this compares to Razorpay and Cashfree's approach
Neither of the other two major aggregators leaves you to guess here, and it's worth knowing their conventions if you've ever integrated with them before, since the concepts map closely even where the field names don't. Cashfree asks you to include a unique x-idempotency-key request header, generated as a UUID, on every mutating request, and to reuse that same key only when retrying that exact operation (Cashfree API best practices). Razorpay's payout API uses its own Idempotency Key in a similar way, and separately expects webhook handlers to dedupe on the x-razorpay-event-id header rather than assume single delivery (Razorpay webhook docs).
The shape of the problem, and the shape of the fix, is close to identical across all three: a merchant-supplied key on the way in, a provider-supplied event identifier on the way out, and an explicit warning that "at least once" delivery is the webhook contract, not "exactly once." If you've built a reliable integration against one of these, you already understand 90% of what the UroPay API asks of you.
What this actually costs to get wrong, and what UroPay costs to get right
The failure mode isn't abstract. A duplicated PAID event that isn't deduplicated can mean two confirmation emails, two inventory holds released, or, worst case, a digital product unlocked twice for a customer who paid once, none of which show up as a "payment error" anywhere, because from the gateway's side, the payment succeeded exactly as expected. The bug lives entirely in your own handler, which is exactly why it's easy to ship without noticing until a customer complains.
On the pricing side, the UroPay API charges 5% + ₹5 per transaction with KYC completed (T+3 settlement), or 10% + ₹5 without KYC (T+5 settlement), against a typical mainstream aggregator rate of roughly 2% + GST. That's a real premium, and I'd rather state it plainly here than let a technical post quietly dodge the commercial question. What the premium buys isn't better idempotency semantics specifically (Razorpay and Cashfree both handle this competently), it's the same three things I'd tell you about in any UroPay API post: direct access to me at gaurav@uropay.me if a signature verification issue has you stuck at 2am, meaningfully lighter KYC requirements to start integrating and testing, and a real shot at onboarding if your product sits in a category a bigger aggregator's automated review would flag on sight.
A side-by-side view
| UroPay API | Typical mainstream aggregator (Razorpay/Cashfree) | |
|---|---|---|
| Request idempotency key | tenantOrderRef, merchant-supplied | x-idempotency-key / Idempotency Key header, merchant-supplied |
| Duplicate-request response | 200 with original order (same payload) / 409 (conflicting payload) | Similar retry-safe behavior, provider-specific status codes |
| Webhook dedup identifier | eventId (UUID per delivery) | x-razorpay-event-id or equivalent |
| Source of truth for status | GET /v1/orders/{orderId}, webhook is advisory only | Provider-specific, generally recommend a status-check fallback too |
| Commission | 5% + ₹5 (KYC) / 10% + ₹5 (no KYC) | ~2% + GST, typically |
| KYC to go live | Optional, sets your rate | Mandatory |
| Support for integration issues | Direct email, gaurav@uropay.me | Ticket queue / tiered support |
Building a safe order-confirmation flow, step by step
Start by generating a tenantOrderRef client-side or server-side the moment a customer commits to checkout, before you call POST /v1/orders, so that a retried create-order call is automatically safe. Store that reference alongside a PENDING row in your own orders table right away, not after the API responds, so a crash between the API call and your database write doesn't leave an orphaned payment with no local record.
Configure your webhookUrl and implement signature verification using the HMAC scheme documented in the API reference: canonical string of method, path, timestamp, nonce, query string, and raw body, signed with your secret. When a webhook lands, check eventId against a table of processed events before doing anything else; if it's already there, return a 200 and stop. Update your order's status based on the webhook's status field, with an explicit default branch for values you don't recognize yet.
Don't rely on the webhook alone. Run a periodic reconciliation job, hourly is reasonable for most volumes, that calls GET /v1/orders/{orderId} for any order still PENDING past a few minutes, and treat that GET response as the final word if it disagrees with whatever the webhook told you. This single habit catches every dropped or delayed webhook without needing NPCI-unfriendly aggressive polling; a periodic sweep every few minutes stays well inside sane API usage, unlike hammering a status endpoint immediately after every checkout click.
If you're setting up the UroPay API from scratch rather than adding idempotency to an existing integration, apply at dashboard.uropai.in, get TEST keys immediately (no KYC needed to start testing), build and verify the flow above against the sandbox, then decide on KYC before requesting PRODUCTION access. Full request and response samples for every endpoint are in the API reference.
Testing this before it's live, not after
The UroPay API gives you separate TEST and PRODUCTION key pairs, and whichever key signs a request decides its environment, with no separate flag to remember or forget. TEST orders are fully isolated from PRODUCTION ones, including separate order IDs and separate GET lookups, so you can build and break your idempotency logic on purpose without touching real money. PRODUCTION access itself is gated behind KYC review (or an explicit opt-out under the non-KYC track), so there's a natural checkpoint before you can go live at all.
What's genuinely useful for the exact problem this post is about: in TEST, UroPay routes each order to one of several upstream payment gateways behind the scenes, and the hosted checkout page tells you which one you landed on. That means your sandbox testing exercises real test-VPA and test-card behavior from Cashfree, Razorpay, PayU, and (in production only) Zoho Payments, each with its own documented success and failure values. Trigger a testfailure@gocash decline on one run and a success on the next, and you can watch your webhook handler and reconciliation job react to both outcomes before a paying customer ever does. If your idempotency logic has a gap, this is the cheapest place to find it.
Quick takeaways
- UPI webhooks are best-effort by design across every gateway, including UroPay, Razorpay, and Cashfree. Treat "at least once" delivery as the contract, not "exactly once."
- The UroPay API's
tenantOrderRefis your request-side idempotency key: a matching retry returns200with the original order, a conflicting retry returns409. - The order status webhook is advisory only.
GET /v1/orders/{orderId}is the authoritative source of truth, and your integration should fall back to it on a schedule. - Deduplicate webhook handling on the
eventIdfield, and verify the HMAC-SHA256 signature before trusting any payload. - NPCI limits banks to a 90-second wait and roughly three status checks per transaction, so aggressive client-side polling isn't just wasteful, it works against the network everyone shares.
- The UroPay API's commission (5% + ₹5 with KYC, 10% + ₹5 without) is higher than a typical ~2% + GST mainstream aggregator rate; the trade is direct founder support, lighter KYC, and more flexible category review, not better technical primitives.
- Build a default branch into every webhook status handler. New statuses, like the recently added
CANCELLED, will keep showing up over time.
Where this leaves you
None of this is unique to UroPay, and that's sort of the point. Idempotent order handling and advisory webhooks are how every serious UPI payment API works, because the underlying network guarantees are the same for everyone building on top of NPCI's rails. What changes between providers is the specific field names, the specific status codes, and who you can actually reach when your signature verification is failing at midnight and the documentation doesn't cover your exact case.
If you're building UPI checkout into your own product and want the two-endpoint-plus-webhook model described here, start with the UroPay API page for full pricing and onboarding details, or go straight to dashboard.uropai.in for TEST keys you can start integrating against today. The API reference has the complete signing, idempotency, and webhook specification referenced throughout this post. And if you're earlier stage than a coded integration, no developer, no website yet, just a UPI ID and a product to sell, UroRelay skips all of this entirely with zero-commission, phone-relayed payments; you can always move to the UroPay API once you're ready to own your own checkout.
Frequently asked questions
What does idempotent mean in a payment API?An idempotent operation gives the same result no matter how many times it runs. For a UPI payment API, that means retrying a create-order call with the same idempotency key returns the original order instead of creating a duplicate, and reprocessing the same webhook event doesn't trigger fulfillment logic twice.
Why is my webhook firing more than once for the same UPI payment?Webhook delivery across every major payment gateway, including the UroPay API, Razorpay, and Cashfree, is best-effort, not exactly-once. Network retries, timeouts, and delivery infrastructure can all cause the same event to arrive more than once. Your handler needs to deduplicate on a unique event identifier rather than assume single delivery.
Should I poll the UPI status API or rely on webhooks?Both, with webhooks as the fast path and polling as the safety net. NPCI limits status-check API usage to protect the network from overload, so treat scheduled reconciliation, checking orders still pending after a few minutes, as a backup for missed webhooks rather than a replacement for them or an aggressive real-time polling loop.
What is UroPay's idempotency key called?tenantOrderRef, a merchant-supplied string sent when creating an order via POST /v1/orders. Reusing it with the same payload returns the original order (200); reusing it with a different payload returns a 409 conflict rather than silently creating a second order.
Is the UroPay API's webhook the authoritative payment status?No. UroPay's documentation states the webhook is advisory only, and that GET /v1/orders/{orderId} is the authoritative check. Build your integration to trust the GET response over the webhook whenever the two disagree.
Have you shipped a duplicate-charge or duplicate-fulfillment bug before, and what caught it, a support ticket, a reconciliation job, or something else entirely? I'd like to hear how it played out. Reach me directly at gaurav@uropay.me.
References
- UroPay Merchant API documentation — authentication, idempotency, and webhooks
- UroPay API — pricing, onboarding and prohibited categories
- UPI Outage: NPCI Directs Banks To Limit 'Check Transaction' API Usage — Inc42
- Cashfree API Best Practices — idempotency key usage
- Razorpay Webhooks — best practices for event handling






