Skip to main content

tokenize Method

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

ScenarioBenefit
One-click checkoutNo re-entry of card details
Recurring billingStored methods for subscriptions
PCI complianceNo raw card storage

Request Fields

FieldTypeRequiredDescription
payment_methodPaymentMethodYesCard or wallet details
customer_idstrNoAssociate with existing customer
metadatadictNoAdditional data

Response Fields

FieldTypeDescription
payment_method_idstrToken ID (e.g., pm_xxx)
payment_method_typestrcard, wallet, etc.
statusstrACTIVE
status_codeintHTTP status code

Example

SDK Setup

from orchestratorx_prism import PaymentMethodClient

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

Request

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

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

Using Tokenized Payment Methods

# 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