Manual refunds don't scale past the point where someone on your team spends Friday afternoon clicking through the Razorpay Dashboard with a spreadsheet open in the next tab. Then one gets refunded twice, or a partial refund goes out for the full amount, and finance wants to know why the numbers don't match. This post covers razorpay refund automation API work as we'd build it: full and partial refunds, instant versus normal speed, the webhooks that tell you what actually happened, and the bookkeeping that stops double refunds.
The refund call, and what it accepts
A refund is created against a captured payment with POST https://api.razorpay.com/v1/payments/{payment_id}/refund. According to Razorpay's refund API reference, the useful parameters are:
amount(optional, in paise for INR). Leave it out for a full refund. Pass less than the captured amount for a partial one.speed(optional).normalis the default.optimumasks Razorpay to refund instantly where it can and fall back to normal where it can't.receipt(optional). Your own unique reference. Use it.notes(optional). Up to 15 key-value pairs.
Multiple partial refunds on one payment are allowed, as long as the total doesn't go over the captured amount. Go over and you get an error saying the refund amount is more than the amount captured. That error is your last line of defence, not your first. Track refunded totals yourself.
Two limits from the docs that catch people out. Normal refunds aren't possible on payments more than 6 months old. And refunds need enough balance in your Razorpay account, which matters for businesses whose settlements leave the account quickly.
Instant vs normal: which to use in a razorpay refund automation API
Razorpay's refunds page puts it plainly: normal refunds reach the customer in 5 to 7 working days, instant refunds almost immediately. Instant refunds can carry a fee depending on your plan, so check your pricing and agreement before turning them on everywhere.
Our default: optimum for anything customer-facing where the customer is already annoyed (a failed order, a cancelled delivery, a duplicate charge), and normal for batch adjustments and goodwill credits nobody is staring at their bank app for. Store the choice on your refund record so support can tell a customer what to expect.
Don't promise instant in your UI just because you asked for it. The response has two fields that matter here: speed_requested (what you asked for) and speed_processed (instant or normal, what Razorpay actually did). Base your customer message on the second one. If the speed changes after creation, the refund.speed_changed webhook fires. Razorpay documents this for the case where you requested optimum and it fell back from instant to normal.
Webhooks, statuses and the state machine
A refund's status is pending, processed or failed. processed is final. failed happens on old payments or bank-side problems. The matching webhooks are:
refund.createdrefund.processedrefund.failedrefund.speed_changed
Treat your own refund table as the source of truth for intent, and Razorpay as the source of truth for outcome. A minimal shape:
refund_requests
id -- your ID, also sent as receipt
order_id
razorpay_payment_id
amount_paise
reason
requested_by -- user ID or "system"
speed_requested
razorpay_refund_id -- null until the API responds
status -- requested | pending | processed | failed
speed_processed
created_at, updated_at
The flow then becomes boring, which is the goal:
- Write the
refund_requestsrow first, in the same database transaction that checks the remaining refundable amount for the order. - Call the refund API with
receiptset to your row ID. - Save the returned refund ID and status.
- Update the row from webhooks. Verify
X-Razorpay-Signatureagainst the raw body, and ignore events that move a refund backwards (a laterefund.createdarriving afterrefund.processed, for example). - Run a nightly job that fetches refunds still
pendingpast your expected window and flags anything odd.
Stopping double refunds
Double refunds almost always come from retries. A request times out on your side after Razorpay already created the refund, your code retries, and now there are two. Avoid it by never retrying blind. If the API call times out, mark the row as unknown, then look up the refunds on that payment (Razorpay lets you fetch refunds for a payment) and match on your receipt before deciding to call again.
The same goes for the support panel. Disable the refund button once a request exists, and make the backend check, not just the button.
Partial refunds and tax
If you issue GST invoices, a partial refund usually means a credit note, and the line items it covers need to be clear. Decide this with your accountant before you write code. In the ed-tech payment portal we built, refunds, EMI plans and GST-compliant invoicing all lived in one system so the books matched the gateway. Splitting those across tools is how month-end turns into a reconciliation exercise.
When to automate, and when not to
Automate the refunds where the rule is mechanical: an order that failed after capture, a cancelled booking inside the free window, a duplicate payment on the same order. Keep a human in the loop for anything involving judgment (partial service delivered, a dispute already open, a payment older than a few months). A good pattern is an approval queue, where the system creates the refund request and a person clicks approve, which then triggers the same API path.
Also log who triggered every refund. Six months later, when a payment shows two refunds, "system" vs a named staff account is the first thing anyone will ask.
If your refunds are still a spreadsheet and a Dashboard tab, we can help you move them into code that finance and support can both trust. At orithLabs we build payment flows as part of our e-commerce development work, priced as fixed milestones before any code is written. A first call costs nothing.