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

# 2. Fetch and Manage Tokens

> Retrieve tokens using Razorpay APIs to create subsequent payments.

<div style={{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0.35rem 0.9rem",border:"1px solid rgba(128,128,128,0.28)",borderRadius:"0.5rem",padding:"0.45rem 0.75rem",margin:"0 0 1.25rem",fontSize:"0.875rem"}}>
  <span style={{fontWeight:600}}>Available in</span>
  <span>🇮🇳 India</span>
</div>

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](/docs/payments/recurring-payments/create#3-search-for-the-token) or the APIs given below.

## 2.1 Fetch Payment ID using Order ID.

After you send the registration link, You should wait for the customer to make the payment. You can check the status of the payment using our APIs. The following endpoint fetches the `payment_id` using an `order_id`.

`GET /orders/:id/payments`

<CodeGroup>
  ```bash Curl theme={null}
  curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET]
  -X GET https://api.razorpay.com/v1/orders/order_1Aa00000000003/payments
  ```

  ```java Java theme={null}
  RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  String orderId = "order_1Aa00000000003";

  Order order = razorpay.orders.fetchPayments(orderId);
  ```

  ```php PHP theme={null}
  $api = new Api($key_id, $secret);

  $api->order->fetch($orderId)->payments()
  ```

  ```javascript Node.js theme={null}
  var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })

  instance.orders.fetchPayments(orderId)
  ```

  ```python Python theme={null}
  client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET"))

  client.order.payment(orderId)
  ```

  ```ruby Ruby theme={null}
  require "razorpay"
  Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')

  orderId = "order_1Aa00000000003"

  Razorpay::Order.fetch("order_1Aa00000000003").payments
  ```

  ```go Go theme={null}
  import ( razorpay "github.com/razorpay/razorpay-go" )
  client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET")

  body, err := client.Order.Payments("<orderId>", nil, nil)
  ```

  ```csharp .NET theme={null}
  RazorpayClient client = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  string orderId = "order_Z6t7VFTb9xHeOs";

  List<Payment> order = client.Order.Fetch(orderId).Payments();
  ```

  ```json Response theme={null}
  {
    "entity":"collection",
    "count":1,
    "items":[
      {
        "id":"pay_1Aa00000000003",
        "entity":"payment",
        "amount":0,
        "currency":"INR",
        "status":"captured",
        "order_id":"order_1Aa00000000003",
        "invoice_id":"inv_1Aa00000000003",
        "international":false,
        "method":"nach",
        "amount_refunded":0,
        "refund_status":null,
        "captured":true,
        "description":"12 p.m. Meals",
        "card_id":null,
        "bank":"HDFC",
        "wallet":null,
        "vpa":null,
        "email":"gaurav.kumar@example.com",
        "contact":"99876543210",
        "customer_id":"cust_1Aa00000000002",
        "token_id":"token_1Aa00000000003",
        "notes":{
          "note_key 1":"Beam me up Scotty",
          "note_key 2":"Tea. Earl Gray. Hot."
        },
        "fee":0,
        "tax":0,
        "error_code":null,
        "error_description":null,
        "created_at":1580109147
      }
    ]
  }
  ```
</CodeGroup>

### Path Parameter

`id`
: `string` The unique identifier of the order. For example, `order_1Aa00000000001`.

## 2.2. Fetch Token by Payment ID

Use the below endpoint to fetch the `token_id` using a `payment_id`.

`GET /payments/:id`

<CodeGroup>
  ```bash Curl theme={null}
  curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
  -X GET https://api.razorpay.com/v1/payments/pay_1Aa00000000003
  ```

  ```java Java theme={null}
  RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_SECRET}"

  String paymentId = "pay_1Aa00000000003";

  Payment payment = razorpay.payments.fetch(paymentId);
  ```

  ```php PHP theme={null}
  $api = new Api($key_id, $secret);

  $api->payment->fetch($paymentId);
  ```

  ```javascript Node.js theme={null}
  var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })

  instance.payments.fetch(paymentId)
  ```

  ```python Python theme={null}
  client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET"))

  client.payment.fetch(paymentId)
  ```

  ```ruby Ruby theme={null}
  require "razorpay"
  Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')

  paymentId = "pay_1Aa00000000003"

  Razorpay::Payment.fetch(paymentId)
  ```

  ```go Go theme={null}
  import ( razorpay "github.com/razorpay/razorpay-go" )
  client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET")

  body, err := client.Payment.Fetch("<paymentId>", nil, nil)
  ```

  ```csharp .NET theme={null}
  RazorpayClient client = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  string paymentId = "pay_Z6t7VFTb9xHeOs";

  Payment payment = client.Payment.Fetch(paymentId);
  ```

  ```json Response theme={null}
  {
    "id": "pay_EnLNTjINiPkMEZ",
    "entity": "payment",
    "amount": 0,
    "currency": "INR",
    "status": "captured",
    "order_id": "order_EnLLfglmKksr4K",
    "invoice_id": "inv_EnLLfgCzRfcMuh",
    "international": false,
    "method": "nach",
    "amount_refunded": 0,
    "refund_status": null,
    "captured": true,
    "description": "Invoice #inv_EnLLfgCzRfcMuh",
    "card_id": null,
    "bank": "UTIB",
    "wallet": null,
    "vpa": null,
    "email": "gaurav.kumar@example.com",
    "contact": "+919876543210",
    "customer_id": "cust_DtHaBuooGHTuyZ",
    "token_id": "token_EnLNTnn7uyRg5V",
    "notes": {
      "note_key 1": "Beam me up Scotty",
      "note_key 2": "Tea. Earl Gray. Hot."
    },
    "fee": 0,
    "tax": 0,
    "error_code": null,
    "error_description": null,
    "error_source": null,
    "error_step": null,
    "error_reason": null,
    "acquirer_data": {},
    "created_at": 1588827564
  }
  ```
</CodeGroup>

<Info>
  **Handy Tips**

  You can also retrieve the `token_id` via the [payment.authorized webhook](/docs/api/payments/recurring-payments/webhooks#payment-authorized).
</Info>

### Path Parameter

`id` *mandatory*
: `string` The unique identifier of the payment to be retrieved. For example, `pay_1Aa00000000002`.

## 2.3. Fetch Tokens by Customer ID

Use the below endpoint to fetch tokens linked to a customer.

A customer can have multiple tokens tied to them. These tokens can be used to create subsequent payments for multiple products or services.

<Warning>
  **Watch Out!**

  This endpoint will not fetch the details of expired and unused tokens.
</Warning>

`GET /customers/:id/tokens`

<CodeGroup>
  ```bash Curl theme={null}
  curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
  -X GET https://api.razorpay.com/v1/customers/cust_1Aa00000000002/tokens
  ```

  ```java Java theme={null}
  RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  String customerId = "cust_1Aa00000000004";

  Customer customer = razorpay.customers.fetchTokens(customerId);
  ```

  ```php PHP theme={null}
  $api = new Api($key_id, $secret);

  $api->customer->fetch($customerId)->tokens()->all();
  ```

  ```javascript Node.js theme={null}
  var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })

  instance.customers.fetchTokens(customerId)
  ```

  ```python Python theme={null}
  client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET"))

  client.token.all(customerId)
  ```

  ```ruby Ruby theme={null}
  require "razorpay"
  Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')

  customerId = "cust_1Aa00000000004"

  Razorpay::Customer.fetchTokens(customerId)
  ```

  ```go Go theme={null}
  import ( razorpay "github.com/razorpay/razorpay-go" )
  client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET")

  body, err := client.Token.All("<customerId>", nil, nil)
  ```

  ```csharp .NET theme={null}
  RazorpayClient client = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  string customerId = "cust_1Aa00000000001";

  List<Token> token = client.Customer.Fetch(customerId).Tokens();
  ```

  ```json Response theme={null}
  {
    "entity": "collection",
    "count": 1,
    "items": [
      {
        "id": "token_EhYgIE3pOyMQpD",
        "entity": "token",
        "token": "3mQ5Czc6APNppI",
        "bank": "HDFC",
        "wallet": null,
        "method": "nach",
        "vpa": null,
        "recurring": true,
        "recurring_details": {
          "status": "confirmed",
          "failure_reason": null
        },
        "auth_type": "physical",
        "mrn": null,
        "used_at": 1587564373,
        "created_at": 1587564373,
        "dcc_enabled": false
      }
    ]
  }
  ```
</CodeGroup>

### Path Parameters

`id` *mandatory*
: `string` The unique identifier of the customer for whom tokens are to be retrieved. For example, `cust_1Aa00000000002`.

## 2.4. Delete Tokens

The following endpoint deletes a token.

`DELETE /customers/:customer_id/tokens/:token_id`

<CodeGroup>
  ```bash Curl theme={null}
  curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
  -X DELETE https://api.razorpay.com/v1/customers/cust_1Aa00000000002/tokens/token_1Aa00000000001
  ```

  ```java Java theme={null}
  RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  String customerId = "cust_1Aa00000000002";

  String tokenId = "token_1Aa00000000001";

  Customer customer = razorpay.customers.deleteToken(customerId, tokenId);
  ```

  ```php PHP theme={null}
  $api = new Api($key_id, $secret);

  $api->customer->fetch($customerId)->tokens()->delete($tokenId);
  ```

  ```javascript Node.js theme={null}
  var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })

  instance.customers.deleteToken(customerId, tokenId)
  ```

  ```python Python theme={null}
  client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET"))

  client.token.delete(customerId, tokenId)
  ```

  ```ruby Ruby theme={null}
  require "razorpay"
  Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')

  customerId = "cust_1Aa00000000004"

  tokenId = "token_Hxe0skTXLeg9pF"

  Razorpay::Customer.fetch(customerId).deleteToken(tokenId)
  ```

  ```go Go theme={null}
  import ( razorpay "github.com/razorpay/razorpay-go" )
  client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET")

  body, err := client.Token.Delete("<customerId>", "<tokenId>", nil, nil)
  ```

  ```ruby Ruby theme={null}
  require "razorpay"
  Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')

  customerId = "cust_1Aa00000000004"

  tokenId = "token_Hxe0skTXLeg9pF"

  Razorpay::fetch(customerId).deleteToken(tokenId)
  ```

  ```java Java theme={null}
  RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  String customerId = "cust_DtHaBuooGHTuyZ";

  String tokenId = "token_HouA2OQR5Z2jTL";

  Customer customer = instance.customers.deleteToken(customerId, tokenId);
  ```

  ```csharp .NET theme={null}
  RazorpayClient client = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");

  string customerId = "cust_Z6t7VFTb9xHeOs";

  string tokenId = "token_1Aa00000000001";

  Customer customer = client.Customer.Fetch(customerId).DeleteToken(tokenId);
  ```

  ```json Response theme={null}
  {
      "deleted": true
  }
  ```
</CodeGroup>

### Path Parameter

`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`.
