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, 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​

ScenarioBenefit
One-click checkoutNo re-entry of card details
Recurring billingStored methods for subscriptions
PCI complianceNo raw card storage in your system
SecurityTokens are useless if compromised

Request Fields​

FieldTypeRequiredDescription
paymentMethodPaymentMethodYesCard or wallet details to tokenize
customerIdstringNoAssociate with existing customer
metadataobjectNoAdditional data (max 20 keys)

Response Fields​

FieldTypeDescription
paymentMethodIdstringToken ID for future use (e.g., pm_xxx)
paymentMethodTypestringcard, wallet, etc.
statusstringACTIVE
fingerprintstringUnique identifier for this card
statusCodenumberHTTP status code

Example​

SDK Setup​

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

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

Request​

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​

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

Using Tokenized Payment Methods​

// 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​