Available in🇮🇳 India
Once you capture a payment, Razorpay Checkout returns a razorpay_payment_id. You can use this id to fetch the token_id, which is used to create and charge subsequent payments.
You can retrieve the token_id using the Dashboard or the APIs given below.
2.1 What is a Token?
A token is a unique identifier that represents a registered UPI Autopay mandate between a customer and your business. When a customer approves a mandate through their UPI app during the Initiate Mandate Registration step, Razorpay generates atoken_id and associates it with the customer’s customer_id.
The token stores the mandate’s configuration, including the maximum debit amount, frequency and expiry date. You use this token_id every time you want to charge the customer a subsequent payment. A single customer can have multiple tokens for different mandates, for example, one for a monthly subscription and another for a quarterly insurance premium.
Handy Tips
- Each token is tied to a specific payment method and customer. A token created via UPI cannot be used for card-based recurring payments and vice versa.
- Tokens have a lifecycle with defined states. Always check the token state before attempting a subsequent debit. Know more in the Token States section below.
2.2 Token States
A UPI Autopay token (mandate) transitions through the following states during its lifecycle. Ensure your integration handles all of these states to avoid unexpected failures.2.3. Fetch Token by Payment ID
The following endpoint fetches thetoken_id using a payment_id.
GET /payments/:id
Handy TipsYou can also retrieve the
token_id via the payment.authorized webhook.Path Parameter
id mandatory
: string The unique identifier of the payment to be retrieved. For example, pay_1Aa00000000002.
2.4. Fetch Tokens by Customer ID
A customer can have multiple tokens and these tokens can be used to create subsequent payments for multiple products or services. The following endpoint retrieves tokens linked to a customer.GET /customers/:id/tokens
Response
Handy TipsThe
recurring_details.status field in the response indicates the current token state. Use this to check if the token is confirmed (active), paused, cancelled or in any other state before attempting a subsequent debit.Path Parameter
id mandatory
: string The unique identifier of the customer for whom tokens are to be retrieved. For example, cust_1Aa00000000002.
2.5. Fetch Token by Token ID and Customer ID
Use this API to fetch token details usingtoken_id and customer_id as path parameters.
GET /v1/customers/:customer_id/tokens/:token_id
Request
Response
Path Parameters
Path Parameters
customer_id mandatory
: string The unique identifier of the customer with whom the token is linked. For example, cust_1Aa00000000002.token_id mandatory
: string The unique identifier of the token to be fetched. For example, token_1Aa00000000001.Response Parameters
Response Parameters
id
: string The unique identifier of the token. For example, token_FHfAzGzREc1ug6.entity
: string The name of the entity. Here, it is token.token
: string The token value used to identify the mandate.bank
: string The bank associated with the token. Returns null for UPI tokens.wallet
: string The wallet associated with the token. Returns null for UPI tokens.method
: string The payment method associated with the token. Here, it is upi.vpa
: json object Details of the customer’s UPI VPA linked to the token.username
: string The username part of the customer’s UPI ID.handle
: string The handle (bank or PSP) part of the customer’s UPI ID. For example, upi.name
: string The account holder’s name as registered with the bank. Returns null if not available.recurring
: boolean Indicates whether the token is enabled for recurring payments. Possible values: true, false.recurring_details
: json object Details of the recurring mandate associated with the token.status
: string The status of the recurring mandate. For example, confirmed.failure_reason
: string The reason for mandate failure, if applicable. Returns null if there is no failure.auth_type
: string The authentication type used. Returns null if not applicable.mrn
: string The mandate reference number. Returns null if not yet assigned.used_at
: integer Unix timestamp at which the token was last used. Returns null if unused.created_at
: integer Unix timestamp at which the token was created.start_time
: integer Unix timestamp at which the mandate validity begins.dcc_enabled
: boolean Indicates whether Dynamic Currency Conversion (DCC) is enabled.max_amount
: integer The maximum amount that can be debited per transaction, in currency subunits.expired_at
: integer Unix timestamp at which the token expires.2.6. Cancel Token
You can cancel tokens that are in theinitiated, confirmed or paused state. Razorpay does not perform any additional validation checks before forwarding the cancellation request to NPCI.
Cancellations can fail if NPCI returns a failure response. This typically happens due to an internal issue on the remitter’s side. Use the following endpoint to cancel a token. This initiates the cancellation of the mandate from NPCI.
PUT /customers/:customer_id/tokens/:token_id/cancel
Handy Tips
- Use the Cancel Token API when you want to permanently revoke the mandate from NPCI. This ensures the customer cannot be charged further against this mandate.
- The response status
cancellation_initiatedindicates that the cancellation request has been sent to NPCI. The token enters thecancellation_initiatedstate while Razorpay waits for NPCI and the customer’s bank to process the closure. Once confirmed, the token transitions tocancelled. - Do not attempt subsequent debits while the token is in the
cancellation_initiatedstate. The payment will fail.
Path Parameters
Path Parameters
customer_id mandatory
: string The unique identifier of the customer with whom the token is linked. For example, cust_1Aa00000000002.token_id mandatory
: string The unique identifier of the token that is to be cancelled. For example, token_1Aa00000000001.Error Response Parameters
Error Response Parameters
Given below is a list of possible errors you may face while cancelling a token.
token_not_recurring
token_not_recurring
- Description: The token provided is not a recurring/autopay token and is not eligible for cancellation via this API.
- Next Steps: Please ensure you are passing a valid UPI Autopay recurring token. Non-recurring tokens cannot be cancelled using this API.
invalid_mandate_state
invalid_mandate_state
- Description: The UPI mandate linked to this token is not in a cancellable state. The mandate may already be revoked or failed.
- Next Steps: Please check the current status of the mandate before attempting cancellation. Cancellation is only allowed when the mandate is in confirmed or active state.
token_customer_mismatch
token_customer_mismatch
- Description: The token provided does not belong to the authenticated customer. Cross-customer token access is not permitted.
- Next Steps: Please verify that the
token_idbelongs to the customer in context and retry with the correct token.
token_merchant_mismatch
token_merchant_mismatch
- Description: The token provided was not created under your merchant account. Cross-merchant token access is not permitted.
- Next Steps: Please ensure you are using tokens created under your own merchant account and retry with the correct
token_id.
concurrent_request_in_progress
concurrent_request_in_progress
- Description: A cancellation or update operation is already in progress for this token. Simultaneous requests on the same token are not allowed.
- Next Steps: Please wait at least 60 seconds before retrying the cancellation request. Avoid sending duplicate or parallel cancel requests for the same token.
2.7. Delete Tokens
Deleting a token removes it from Razorpay’s database. The deleted token will not appear on the Dashboard or when all tokens are fetched. However, it does not cancel the mandate. If you wish to delete the mandate with Razorpay, you must first cancel it using the Cancel Token API. The following endpoint deletes a token.DELETE /customers/:customer_id/tokens/:token_id
Response
Path Parameters
Path Parameters
customer_id mandatory
: string The unique identifier of the customer with whom the token is linked. For example, cust_1Aa00000000002.token_id mandatory
: string The unique identifier of the token that is to be deleted. For example, token_1Aa00000000001.Response Parameters
Response Parameters
deleted
: boolean Indicates whether the token is deleted. Possible values:true: The token is deleted successfully.false: The token was not deleted.