Available in🇮🇳 India
This page brings together the error-handling rules for Razorpay APIs: how to read a failure response, what to do for each class of error, what to show the customer, what to log and how to recover a request that timed out. It is for developers who call Razorpay APIs from their server or handle payment failures from Checkout. To look up a specific error reason, use the product error lists.
Read the error response
When a request fails, Razorpay returns a JSON error response with the relevant error parameters. The error response containscode, description, field, source, step, reason and metadata.
The
source parameter tells you where the error originated and who needs to act. The values and the action for each are listed in the List of Errors. The values of source and step for each payment method are in Payment Method Error Parameters.
See the sample error response and the full parameter descriptions in About Errors.
What to do for each error class
For payments APIs, readerror.code, reason, source and step before you decide what to do next. For RazorpayX payouts, see RazorpayX payouts.
Follow these rules when you build the handling:
- Do not retry a bad request as-is. The same
BAD_REQUEST_ERRORfails again and again. - For a
BAD_REQUEST_ERRORwith the reasoninput_validation_failed, check thedescriptionandfieldparameters to find what to correct in the request. - Branch your logic on
reasonandsource, not ondescription. If you match ondescription, a wording change breaks your handling.
What to show the customer
Show the customer thedescription, and give them a meaningful next step based on the payment step and the failure reason. For example, when the reason is invalid_otp, you can notify the customer and ask them to retry the payment with the correct OTP.
On Standard Checkout, the behaviour depends on how you integrated:
See Handle Payment Success and Failure in the Standard Checkout integration steps for the failure handling code.
What to log
Logreason, source and step for support and dashboards.
Group failures by reason to spot a bank or method that is failing. Without per-reason monitoring, a failing bank can go unnoticed for hours.
Recover a request that timed out
Every call you might retry must be safe to repeat.
To fetch the payments made against an order, use the Fetch Payments for an Order API.
Fetching the order’s payments before you retry a payment assumes that you retry on the same order. Check that this matches your integration if you create a new order for each attempt. See Retries and Idempotency for the scenarios to test.
RazorpayX payouts
When you retry a payout request after a 5XX error:- Use the same idempotency key as the original request.
- Send the same request body. A different request body for the same idempotency key is rejected.