2. Fetch and Manage Tokens

Retrieve tokens using Razorpay APIs to create subsequent payments.


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 in the following ways:

The following endpoint fetches the token_id using a payment_id.

GET
/payments/:id

Handy Tips

You can also retrieve the token_id via the

.

id

mandatory

string The unique identifier of the payment to be retrieved. For example, pay_1Aa00000000002.

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.

Watch Out!

  • This endpoint will not fetch the details of expired and unused tokens.
  • The UPI tokens are not populated in the API response if the save_vpa feature is not enabled in your account. Please raise a request with our to get this activated.
GET
/customers/:id/tokens

id

mandatory

string The unique identifier of the customer for whom tokens are to be retrieved. For example, cust_1Aa00000000002.

Watch Out!

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 cancel the mandate from NPCI, use the

.

The following endpoint deletes a token.

DELETE
/customers/:customer_id/tokens/:token_id

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.

The following endpoint initiates cancellation of the mandate from NPCI.

PUT
/customers/:customer_id/tokens/:token_id/cancel
curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X PUT https://api.razorpay.com/v1/customers/cust_1Aa00000000002/tokens/token_1Aa00000000001/cancel

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.


Is this integration guide useful?