2. Fetch and Manage Tokens

Retrieve tokens using Razorpay APIs to create subsequent payments.


Once you capture a payment, Razorpay returns a razorpay_payment_id that can be used to fetch the token_id. This is a manual process and can be done using either APIs or Webhooks. This token_id is used to create and charge subsequent payments.

Note

You can also search for the Token on your Dashboard.

.

Token Sharing for Partner Auth Model

If you are a Razorpay Partner, who wants to use this API via Partner Auth, you must ensure the following:

  • Add the basic auth with partner credentials (client_id and client_secret).
  • Add the account_id of the sub-merchant using X-Razorpay-Account in the header. For example, -H "X-Razorpay-Account: acc_KBrJAIEqre5ucn"
curl -X POST https://api.razorpay.com/v1/customers \
-u [YOUR_PARTNER_KEY_ID]:[YOUR_PARTNER_KEY_SECRET]\
-H "X-Razorpay-Account: acc_KBrJAIEqre5ucn" \

The following endpoint fetches a token id using the Payment id.

GET
/payments/:id
curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
-X GET https://api.razorpay.com/v1/payments/pay_1Aa00000000001

Handy Tips

You can also retrieve the token_id from 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 fetches tokens linked to a customer.

Watch Out!

This endpoint will not fetch the details of expired, rejected and unused tokens.

GET
/customers/:id/tokens
curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
-X GET https://api.razorpay.com/v1/customers/cust_1Aa00000000002/tokens

id

mandatory

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

The following endpoint deletes a token.

DELETE
/customers/:customer_id/tokens/:token_id

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.


Is this integration guide useful?