Send Resend emails when a new Razorpay refund is created
A Razorpay + Resend agent flow
A refund issued in Razorpay is money leaving, and finance often learns about it days later from a settlement report. A team that wants same-day visibility into refunds can have an agent email the moment it next checks. The agent reads the refund list with fetch_all_refunds, finds the ones created since the last run, and sends a summary to finance with Resend's send-email. Razorpay answers the agent's call rather than pushing, so the read runs on a cadence, hourly or a few times a day, and only refunds the agent hasn't reported become an email.
The flow
fetch_all_refundsFetches all refunds.
send-emailSends a single transactional email immediately or scheduled, with HTML/text, attachments, CC/BCC, and tags.
Step by step
- Decide who gets the email
Pick the finance address that should hear about refunds and the cadence the agent reads. Verify your sending domain in Resend so the email delivers.
- Read the refunds
The agent calls fetch_all_refunds, reading each refund's ID, amount, currency, the payment it refunds, its status, and the time it was created.
- Find new refunds
Track the refund IDs from the prior run. Email only the ones created since, so a refund already reported isn't sent again on the next read.
- Email the summary
For each new refund, or grouped into one digest, the agent calls send-email with the refund ID, amount, the payment it relates to, and a tag, so finance sees the outflow with enough to look it up.
Tell your agent
Every hour, fetch all Razorpay refunds. For any created since the last run, send a Resend email from finance@acme.com to ledger@acme.com with the refund ID, amount, currency, the related payment ID, and status, tagged 'razorpay-refund'. Group them into one email per run, and don't report a refund you've already sent.
Setup
This flow needs both servers connected to your agent. Follow each install guide:
Worth knowing
- fetch_all_refunds returns the full refund list, so the agent has to remember which IDs it already emailed and send only newer ones, or every run repeats the whole list.
- send-email needs a verified Resend domain with SPF and DKIM. Use a from address on that domain so the refund notice doesn't fail to deliver.
- Amounts come back in the smallest currency unit, paise for INR. Have the agent format them to a readable figure in the email so finance isn't reading raw integers.
Questions
- Does it include the customer's email?
- The refund record returns the payment it relates to and the amount, not necessarily the customer's email. If you need that, the agent can fetch the related payment and read its contact details before composing the message.
- Can it send one digest instead of an email per refund?
- Yes. The agent collects the new refunds for the run and calls send-email once with all of them in the body, which keeps a busy refund hour to a single message.