> 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/python/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.

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

## Purpose

| Scenario           | Benefit                          |
| ------------------ | -------------------------------- |
| One-click checkout | No re-entry of card details      |
| Recurring billing  | Stored methods for subscriptions |
| PCI compliance     | No raw card storage              |

## Request Fields

| Field            | Type          | Required | Description                      |
| ---------------- | ------------- | -------- | -------------------------------- |
| `payment_method` | PaymentMethod | Yes      | Card or wallet details           |
| `customer_id`    | str           | No       | Associate with existing customer |
| `metadata`       | dict          | No       | Additional data                  |

## Response Fields

| Field                 | Type | Description              |
| --------------------- | ---- | ------------------------ |
| `payment_method_id`   | str  | Token ID (e.g., pm\_xxx) |
| `payment_method_type` | str  | card, wallet, etc.       |
| `status`              | str  | ACTIVE                   |
| `status_code`         | int  | HTTP status code         |

## Example

### SDK Setup

```python
from hyperswitch_prism import PaymentMethodClient

payment_method_client = PaymentMethodClient(
    connector='stripe',
    api_key='YOUR_API_KEY',
    environment='SANDBOX'
)
```

### Request

```python
request = {
    "payment_method": {
        "card": {
            "card_number": {"value": "4242424242424242"},
            "card_exp_month": {"value": "12"},
            "card_exp_year": {"value": "2027"},
            "card_cvc": {"value": "123"},
            "card_holder_name": {"value": "John Doe"}
        }
    },
    "customer_id": "cus_xxx"
}

response = await payment_method_client.tokenize(request)
```

### Response

```python
{
    "payment_method_id": "pm_3Oxxx...",
    "payment_method_type": "card",
    "status": "ACTIVE",
    "status_code": 200
}
```

## Using Tokenized Payment Methods

```python
# Use the token in authorize
auth_response = await payment_client.authorize({
    "merchant_transaction_id": "txn_001",
    "amount": {"minor_amount": 1000, "currency": "USD"},
    "payment_method": {
        "payment_method_id": "pm_3Oxxx..."
    },
    "auth_type": "NO_THREE_DS"
})
```

## Next Steps

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


---

# 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/python/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.
