> ## Documentation Index
> Fetch the complete documentation index at: https://razorpay.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Test UPI Autopay

> Test your UPI Autopay integration in test mode. Register mandates, run auto-debits, simulate failures and manage tokens without moving real money.

Available in
🇮🇳 India

Use test mode to check your UPI Autopay integration before you go live. Test mode simulates the responses from NPCI and the customer's bank, so you can register mandates, run auto-debits and handle failures without moving real money or using a UPI app.

## Test Mode Coverage

Test mode covers mandate registration, auto-debits and token management. A few live mode behaviours depend on real time windows or on actions the customer takes in their UPI app, and test mode does not simulate these. Read this section first so you know which parts of your integration you need to verify in live mode.

> [!WARNING]
>
> **Available in Live Mode Only**
>
> Some live mode behaviours are not available in test mode:
>
> * Razorpay does not automatically retry failed auto-debits in test mode, so a failed debit stays failed.
> * Test mode does not reproduce the 24-hour gap that NPCI requires between the pre-debit notification and the debit, or the debit execution windows, so debits are not held in the `created` state.
> * Actions that a customer takes in their UPI app, such as pausing, resuming or revoking a mandate, or approving a change to a mandate, are not generated. You can still cancel a token yourself through the API.
> * Pre-debit notifications always succeed.
> * Test mode does not provide shared test tokens. Register a mandate to create a token for your account.
>
> Verify these behaviours in live mode before you rely on them.

The following can be tested in test mode:

| Area | What you can test |
| - | - |
| Mandate registration | Successful registration through UPI intent. Failure scenarios triggered by the payment amount. |
| Auto-debits | Pre-debit notification and debit in both the coupled and decoupled flows. Successful debits, failure scenarios triggered by the payment amount, and rejections when the debit is above the mandate's maximum amount, after the mandate expires, or on a cancelled token. |
| Duplicate requests | A repeated debit request for the same payment is rejected. |
| Token management | Fetch a token, fetch all tokens for a customer, and cancel a token. |
| Webhooks | Payment, order and token webhooks for each of the above, delivered to the URL configured in your test mode Dashboard. |

## Before You Begin

* Generate your [test mode API keys](https://razorpay.com/docs/payments/dashboard/account-settings/api-keys.md) from the Dashboard. Keys that start with `rzp_test_` send all requests to test mode. You do not need to enable any separate flag.
* Use the same APIs and request formats you use in live mode. Only the API keys change.
* Pass every amount in paise, as you do in live mode. For example, send `201` for ₹2.01 and `100` for ₹1.
* Configure a [webhook](https://razorpay.com/docs/webhooks) URL in your test mode Dashboard to receive test events.

Specific amounts are reserved to trigger failures. Any amount listed in [Simulate Failures](#simulate-failures) returns that failure. Use `100` (₹1) for a successful payment.

## Test Mandate Registration

Registration creates the mandate and the token that you use for later debits. In test mode, the simulator approves or declines the registration on its own, so you do not need to open a UPI app or enter a UPI PIN.

### Register a Mandate Successfully

1. [Create a customer](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-authorization-transaction.md#1-1-1-create-a-customer), or use an existing customer ID.
2. [Create an order](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-authorization-transaction.md#1-1-2-create-an-order) with `method` set to `upi` and the `token` details: `max_amount`, `expire_at` and `frequency`. Set `amount` to `100`.
3. [Create the registration payment](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-authorization-transaction.md#1-1-3-create-an-authorisation-payment) with `recurring` set to `1` using the UPI intent flow.
4. Check that the payment moves to `captured` and that a token is created in the `confirmed` state. Save the token ID for auto-debits.

The following is a sample request to create the registration order in test mode. It is the same request you send in live mode.

```bash Curl theme={null}
curl -u <YOUR_TEST_KEY_ID>:<YOUR_TEST_KEY_SECRET> \
-X POST https://api.razorpay.com/v1/orders \
-H "Content-Type: application/json" \
-d '{
  "amount": 100,
  "currency": "INR",
  "customer_id": "cust_4xbQrmEoA5WJ01",
  "method": "upi",
  "token": {
    "max_amount": 200000,
    "expire_at": 2709971120,
    "frequency": "monthly",
    "recurring_value": 25,
    "recurring_type": "on"
  },
  "receipt": "Receipt No. 1",
  "description": "Monthly Pro subscription",
  "notes": {
    "notes_key_1": "Tea, Earl Grey, Hot",
    "notes_key_2": "Tea, Earl Grey… decaf."
  }
}'
```

### How the Intent Flow Behaves in Test Mode

The response contains an intent link, as it does in live mode. You do not need to open it. The simulator completes the registration and sends the callback and webhooks.

To test a failed registration, use one of the amounts in [Registration Failures](#registration-failures).

## Test Auto-Debits

After a mandate is registered, you can charge the customer using the saved token. Before every debit, the customer must receive a pre-debit notification. Razorpay supports two ways of handling this.

### Coupled and Decoupled Flows

| Flow | Who sends the pre-debit notification | What you do |
| - | - | - |
| Coupled | Razorpay sends it when you create the recurring payment. | Create the order without the `notification` object, then create the recurring payment. Razorpay sends the notification and then runs the debit. |
| Decoupled | You trigger it with a separate request. | Create the order with the `notification` object to send the pre-debit notification first. Trigger the debit in a second request. |

Both flows are available in test mode. Use the flow your account is configured for in live mode. Know more about the `notification` object in the [Create an Order to Charge the Customer](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-subsequent-payments.md#3-1-create-an-order-to-charge-the-customer) API.

### Run a Successful Debit

1. [Create an order](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-subsequent-payments.md#3-1-create-an-order-to-charge-the-customer) for the debit amount. Use `100`, or any amount below the mandate's `max_amount` that is not reserved for a failure.
2. In the decoupled flow, pass the `notification` object with the `token_id` in this order to send the pre-debit notification.
3. [Create the recurring payment](https://razorpay.com/docs/api/payments/recurring-payments/upi/create-subsequent-payments.md#3-2-create-a-recurring-payment) with the `token` ID and `recurring` set to `1`.
4. Check that the payment moves to `captured` and that you receive the `payment.captured` and `order.paid` webhooks.

### Debit Rejections

These rejections come from the same checks that run in live mode.

| How to trigger | Result |
| - | - |
| Create a debit for more than the mandate's `max_amount`. | The request is rejected before the debit is attempted. |
| Create a debit after the mandate's `expire_at` time. Register a mandate with an expiry a few minutes ahead, then wait for it to pass. | The request is rejected because the mandate has expired. |
| Cancel the token, then create a debit with it. | The request is rejected because the token is cancelled. |
| Send the same debit request again while the first is being processed. | The repeated request is rejected and only one debit is made. |

### Debit Failures

To test a failed debit, use one of the amounts in [Auto-Debit Failures](#auto-debit-failures). Make sure the mandate's `max_amount` is higher than the amount you choose.

## Simulate Failures

Set the payment amount to one of the amounts below to trigger a failure. The same amounts trigger failures for [one-time UPI payments](https://razorpay.com/docs/payments/payments/test-upi-details.md) in test mode. The error details returned for an amount depend on whether the payment is a mandate registration or an auto-debit, so each has its own table.

Amounts are in paise. For example, `201` is ₹2.01. For auto-debits, make sure the mandate's `max_amount` is higher than the amount you choose.

### Registration Failures

Use these amounts for the registration order and payment. The payment moves to `failed` and no token is created.

| Amount (paise) | Scenario | `error.code` | `error.reason` | `error.source` | `error.step` | `error.description` | NPCI code |
| - | - | - | - | - | - | - | - |
| **Bank and network issues** | | | | | | | |
| 101 | Customer's bank system error | `GATEWAY_ERROR` | `bank_technical_error` | `remitter_bank` | `payment_debit_response` | UPI Autopay setup couldn't be completed due to a temporary issue. Any debited amount will be refunded in 4-5 business days. | IR |
| 102 | Customer's bank is offline | `GATEWAY_ERROR` | `bank_technical_error` | `remitter_bank` | `payment_response` | Your bank is temporarily unavailable. Please try again later or use a different account. | XY |
| 103 | Duplicate request at the customer's UPI app | `GATEWAY_ERROR` | `duplicate_request` | `customer_psp` | `payment_response` | A mandate setup is already in progress. Please wait for it to complete or try again in a few moments. | QN |
| 104 | Customer's bank took too long to respond | `GATEWAY_ERROR` | `timeout_at_remitter_bank` | `remitter_bank` | `payment_response` | Your bank took too long to respond. Please try again. | U90 |
| 107 | Customer's bank or UPI app is unavailable | `GATEWAY_ERROR` | `bank_technical_error` | `remitter_bank` | `payment_authentication` | UPI Autopay setup couldn't be completed due to a temporary issue. Any debited amount will be refunded in 4-5 business days. | U28 |
| **Customer account and limits** | | | | | | | |
| 201 | Insufficient balance in the customer's account | `GATEWAY_ERROR` | `insufficient_funds` | `remitter_bank` | `payment_response` | Insufficient balance in your account. Please add funds and try again. | Z9 |
| 202 | Mobile number changed or removed from the account | `GATEWAY_ERROR` | `customer_invalid_mobile_number` | `remitter_bank` | `payment_debit_response` | Your mobile number has been changed or removed from this account. Please update your details or use a different account. | B1 |
| 203 | Transaction not permitted on the customer's account | `GATEWAY_ERROR` | `account_state_forbidden` | `remitter_bank` | `payment_authentication` | UPI Autopay setup is not allowed for this account. Please contact your bank or try a different account. | B3 |
| 204 | Incorrect UPI PIN | `GATEWAY_ERROR` | `incorrect_pin_entered` | `customer` | `payment_initiation` | Payment authorisation failed due to incorrect MPIN. Please retry with the correct MPIN. | ZM |
| 205 | UPI PIN not set | `GATEWAY_ERROR` | `customer_mpin_not_set` | `customer` | `payment_debit_response` | UPI PIN is not set for this account. Please set up your UPI PIN and try again. | AM |
| 206 | UPI PIN attempts exceeded | `GATEWAY_ERROR` | `incorrect_pin_entered` | `customer` | `payment_response` | You've exceeded the number of PIN attempts. Please wait and try again later, or contact your bank if you've forgotten your PIN. | Z6 |
| 208 | Transaction amount limit exceeded | `GATEWAY_ERROR` | `transaction_amount_limit_exceeded` | `remitter_bank` | `payment_initiation` | This amount is above your transaction limit. Please try a lower amount or contact your bank for assistance. | Z8 |
| 209 | Total UPI spending limit exceeded | `GATEWAY_ERROR` | `transaction_amount_limit_exceeded` | `remitter_bank` | `payment_authentication` | This amount is above your transaction limit. Please try a lower amount or contact your bank for assistance. | U03 |
| 210 | Transaction frequency limit exceeded | `GATEWAY_ERROR` | `transaction_frequency_limit_exceeded` | `remitter_bank` | `payment_response` | You've exceeded the number of allowed transactions on this account. Please try again later or contact your bank. | Z7 |
| 212 | Customer's account is blocked or frozen | `GATEWAY_ERROR` | `account_state_blocked` | `remitter_bank` | `payment_status_request` | Your account is blocked or frozen. Please contact your bank to resolve this. | YE |
| 213 | Beneficiary account does not exist | `BAD_REQUEST_ERROR` | `beneficiary_account_not_found` | `business` | `payment_response` | Payment authorisation failed due to a technical issue. Please try again or contact your bank if this continues. | XI |
| **Customer action** | | | | | | | |
| 301 | Request expired before the customer approved it | `GATEWAY_ERROR` | `mandate_collect_request_expired` | `customer` | `payment_authentication` | You didn't approve the request in your UPI app. Please try again and approve within 10 minutes. | U69 |
| 302 | Customer cancelled the request | `BAD_REQUEST_ERROR` | `mandate_cancelled_by_user` | `internal` | `payment_response` | You cancelled the payment setup. Please try again. | – |
| 304 | Customer declined the request | `GATEWAY_ERROR` | `mandate_cancelled_by_user` | `customer` | `payment_authentication` | You cancelled the UPI payment. Set it up again to complete your order. | ZA |
| **Validation and risk** | | | | | | | |
| 401 | Invalid UPI ID | `GATEWAY_ERROR` | `invalid_vpa` | `customer` | `payment_debit_request` | Invalid UPI ID entered. Please enter a valid UPI ID and retry. | U29 |
| 404 | Declined by the bank's risk checks | `GATEWAY_ERROR` | `risk_declined_by_remitter_bank` | `remitter_bank` | `payment_response` | Autopay setup was blocked for security reasons. Please contact your bank or use a different account. | U16 |
| 405 | Customer's bank declined due to risk | `GATEWAY_ERROR` | `risk_declined_by_remitter_bank` | `remitter_bank` | `payment_initiation` | Autopay setup was declined for security reasons. Please contact your bank for assistance. | K1 |
| 406 | Duplicate request | `BAD_REQUEST_ERROR` | `request_validation_failed` | `internal` | `payment_response` | UPI Autopay setup failed due to a technical issue. Please try again. | U01 |
| 407 | Device check failed | `GATEWAY_ERROR` | `customer_psp_fingerprint_mismatch` | `customer` | `payment_response` | Payment was declined for security reasons. Please contact your bank for more details. | U66 |

### Auto-Debit Failures

Use these amounts for the debit order and the recurring payment. The payment moves to `failed` and the token stays active.

| Amount (paise) | Scenario | `error.code` | `error.reason` | `error.source` | `error.step` | `error.description` | NPCI code |
| - | - | - | - | - | - | - | - |
| **Bank and network issues** | | | | | | | |
| 101 | Customer's bank system error | `GATEWAY_ERROR` | `remitter_bank_error` | `remitter_bank` | `payment_response` | Your bank is experiencing technical issues. Please try again later. | IR |
| 102 | Customer's bank is offline | `GATEWAY_ERROR` | `remitter_bank_unavailable` | `remitter_bank` | `payment_debit_request` | Your bank is temporarily unavailable. Please try again in a few moments. | XY |
| 103 | Duplicate request at the customer's UPI app | `GATEWAY_ERROR` | `duplicate_request` | `customer_psp` | `payment_initiation` | A duplicate payment request was detected. If the earlier payment was successful, no action is needed. Otherwise, please retry. | QN |
| 104 | Customer's bank took too long to respond | `GATEWAY_ERROR` | `timeout_at_remitter_bank` | `remitter_bank` | `payment_debit_response` | Your bank took too long to respond. Please try again. | U90 |
| 107 | Customer's bank or UPI app is unavailable | `GATEWAY_ERROR` | `remitter_bank_unavailable` | `remitter_bank` | `payment_request` | Your bank is temporarily unavailable. Please try again in a few moments. | U28 |
| **Customer account and limits** | | | | | | | |
| 201 | Insufficient balance in the customer's account | `GATEWAY_ERROR` | `insufficient_funds` | `customer` | `payment_debit_request` | Insufficient balance in your account. Please add funds and try again. | Z9 |
| 202 | Mobile number changed or removed from the account | `GATEWAY_ERROR` | `customer_mobile_changed` | `remitter_bank` | `payment_request` | Your registered mobile number has been updated. Please update your UPI profile or contact your bank. | B1 |
| 203 | Transaction not permitted on the customer's account | `GATEWAY_ERROR` | `declined_by_remitter_bank` | `remitter_bank` | `payment_authorization` | Your bank declined the payment. Please contact your bank. | B3 |
| 205 | UPI PIN not set | `GATEWAY_ERROR` | `customer_mpin_not_set` | `customer` | `payment_authentication` | UPI PIN is not set for this account. Please set up your UPI PIN and try again. | AM |
| 206 | UPI PIN attempts exceeded | `GATEWAY_ERROR` | `incorrect_pin_entered` | `customer` | `payment_authentication` | You've exceeded the number of PIN attempts. Please wait and try again later, or contact your bank if you've forgotten your PIN. | Z6 |
| 208 | Transaction amount limit exceeded | `GATEWAY_ERROR` | `transaction_limit_exceeded` | `remitter_bank` | `payment_debit_response` | Payment amount exceeds your bank's limit. Please try with a lower amount or contact your bank to increase the limit. | Z8 |
| 209 | Total UPI spending limit exceeded | `GATEWAY_ERROR` | `spending_limit_exceeded` | `remitter_bank` | `payment_debit_response` | You've exceeded your total UPI spending limit. Please try again later or contact your bank to increase the limit. | U03 |
| 210 | Transaction frequency limit exceeded | `GATEWAY_ERROR` | `frequency_limit_exceeded` | `remitter_bank` | `payment_initiation` | You've exceeded the number of allowed transactions. Please try again later or contact your bank. | Z7 |
| 212 | Customer's account is blocked or frozen | `GATEWAY_ERROR` | `account_blocked` | `remitter_bank` | `payment_debit_request` | Your account is blocked or frozen. Please contact your bank to resolve this. | YE |
| **Customer action** | | | | | | | |
| 301 | Request expired before the customer approved it | `GATEWAY_ERROR` | `mandate_collect_request_expired` | `customer` | `payment_authentication` | You didn't approve the request in your UPI app. Please try again and approve within 10 minutes. | U69 |
| 304 | Customer declined the request | `GATEWAY_ERROR` | `mandate_cancelled_by_user` | `customer` | `payment_debit_request` | This payment was declined. Please approve the payment request on your UPI app or try again. | ZA |
| **Validation and risk** | | | | | | | |
| 404 | Declined by the bank's risk checks | `BAD_REQUEST_ERROR` | `risk_declined` | `business` | `payment_debit_response` | Payment was declined for security reasons. Please contact your bank for assistance. | U16 |
| 405 | Customer's bank declined due to risk | `GATEWAY_ERROR` | `risk_declined` | `remitter_bank` | `payment_debit_response` | Payment was declined for security reasons. Please contact your bank for assistance. | K1 |

## Test Token Management

Tokens created in test mode behave the same way as live tokens for the actions below.

| Action | What to check |
| - | - |
| [Fetch a token](https://razorpay.com/docs/api/payments/recurring-payments/upi/tokens.md) | The token returns its status, `max_amount`, `expire_at` and frequency as set at registration. |
| [Fetch all tokens for a customer](https://razorpay.com/docs/api/payments/recurring-payments/upi/tokens.md) | Every token registered for the customer in test mode is listed. |
| [Cancel a token](https://razorpay.com/docs/api/payments/recurring-payments/upi/tokens.md) | The token status changes to `cancelled` and you receive the `token.cancelled` webhook. Later debits with this token are rejected. |

### Cancel a Token

You can cancel a token in test mode when its `recurring_details.status` is `confirmed`.

1. Send a `PUT` request to `/v1/customers/:customer_id/tokens/:token_id/cancel`. The request does not need a body.
2. Check that the API returns HTTP `200` with the status `cancellation_initiated`.
3. [Fetch the token](https://razorpay.com/docs/api/payments/recurring-payments/upi/tokens.md). The cancellation is not instant. Within about 45 seconds, `recurring_details.status` changes to `cancelled`.

```bash Curl theme={null}
curl -u <YOUR_TEST_KEY_ID>:<YOUR_TEST_KEY_SECRET> \
-X PUT https://api.razorpay.com/v1/customers/cust_4xbQrmEoA5WJ01/tokens/token_4zwefDSCC829ma/cancel
```

```json Response theme={null}
{
  "status": "cancellation_initiated"
}
```

Pausing and resuming a mandate are customer actions in live mode and are not available in test mode.

## Webhooks in Test Mode

Test mode sends the same [webhooks](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/recurring-payments/upi/webhooks.md) as live mode, to the URL in your test mode Dashboard.

| Event | Webhooks |
| - | - |
| Registration succeeds | `payment.authorized`, `payment.captured`, `order.paid`, `token.confirmed` |
| Registration fails | `payment.failed`, `token.rejected` |
| Debit succeeds | `payment.authorized`, `payment.captured`, `order.paid` |
| Debit fails | `payment.failed` |
| Token cancelled | `token.cancelled` |

> [!NOTE]
>
> **Handy Tips**
>
> A webhook can be delivered more than once. Use the event ID to process each event only once. This applies in live mode as well.

## Move to Live Mode

Before you switch to live keys, check the following:

* Registration succeeds through every flow you offer, and your system stores the token ID.
* Your system handles each failure scenario you expect, including failed registrations and failed debits.
* Your debit amount checks match the mandate's `max_amount` and `expire_at`.
* Your webhook handler processes each event once, even when it is delivered more than once.
* You have planned for the behaviours listed under [Available in Live Mode Only](#test-mode-coverage), in particular the 24-hour gap before a debit, the `created` state, automatic retries and customer actions such as pause and revoke.

## Related Information

* [About UPI Autopay](https://razorpay.com/docs/payments/recurring-payments/upi.md): How mandates, tokens and debits work.
* [Integrate Recurring Payments Using UPI](https://razorpay.com/docs/payments/recurring-payments/upi/integrate.md): The live mode integration steps.
* [Test UPI ID Details](https://razorpay.com/docs/payments/payments/test-upi-details.md): Test amounts for one-time payments.
