> For the complete documentation index, see [llms.txt](https://docs.hyperswitch.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyperswitch.io/integrations/prism/node/payment-method-service/tokenize.md).

# Tokenize

## Overview

The `tokenize` method stores a payment method securely at the payment processor. It replaces sensitive card data with a secure token, enabling one-click payments without PCI compliance exposure.

**Business Use Case:** A customer wants to save their card for faster checkout next time. Tokenize the card details to create a secure token for future use.

## Purpose

| Scenario           | Benefit                            |
| ------------------ | ---------------------------------- |
| One-click checkout | No re-entry of card details        |
| Recurring billing  | Stored methods for subscriptions   |
| PCI compliance     | No raw card storage in your system |
| Security           | Tokens are useless if compromised  |

## Request Fields

| Field           | Type          | Required | Description                        |
| --------------- | ------------- | -------- | ---------------------------------- |
| `paymentMethod` | PaymentMethod | Yes      | Card or wallet details to tokenize |
| `customerId`    | string        | No       | Associate with existing customer   |
| `metadata`      | object        | No       | Additional data (max 20 keys)      |

## Response Fields

| Field               | Type   | Description                             |
| ------------------- | ------ | --------------------------------------- |
| `paymentMethodId`   | string | Token ID for future use (e.g., pm\_xxx) |
| `paymentMethodType` | string | card, wallet, etc.                      |
| `status`            | string | ACTIVE                                  |
| `fingerprint`       | string | Unique identifier for this card         |
| `statusCode`        | number | HTTP status code                        |

## Example

### SDK Setup

```javascript
const { PaymentMethodClient } = require('hyperswitch-prism');

const paymentMethodClient = new PaymentMethodClient({
    connector: 'stripe',
    apiKey: 'YOUR_API_KEY',
    environment: 'SANDBOX'
});
```

### Request

```javascript
const request = {
    paymentMethod: {
        card: {
            cardNumber: { value: "4242424242424242" },
            cardExpMonth: { value: "12" },
            cardExpYear: { value: "2027" },
            cardCvc: { value: "123" },
            cardHolderName: { value: "John Doe" }
        }
    },
    customerId: "cus_xxx"
};

const response = await paymentMethodClient.tokenize(request);
```

### Response

```javascript
{
    paymentMethodId: "pm_3Oxxx...",
    paymentMethodType: "card",
    status: "ACTIVE",
    fingerprint: "abc123...",
    statusCode: 200
}
```

## Using Tokenized Payment Methods

```javascript
// Use the token in authorize
const authResponse = await paymentClient.authorize({
    merchantTransactionId: "txn_001",
    amount: { minorAmount: 1000, currency: "USD" },
    paymentMethod: {
        paymentMethodId: "pm_3Oxxx..."  // Use token instead of raw card
    },
    authType: "NO_THREE_DS"
});
```

## Next Steps

* [Payment Service](/integrations/prism/node/payment-service.md) - Use tokenized payment methods
* [Recurring Payment Service](/integrations/prism/node/recurring-payment-service.md) - Set up subscriptions with stored cards


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hyperswitch.io/integrations/prism/node/payment-method-service/tokenize.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
