To simplify the payment process for returning customers, Xendit's card tokenization offers a secure and efficient solution by allowing you to safely store customer card details. This eliminates the need for customers to re-enter their information for every purchase, leading to a smoother checkout process. You can store multiple cards per customer with One-Click Payments with CVN or Merchant-Initiated Transactions.
Store card flow
How to integrate
Create a payment session
To begin the tokenization process, you need to create a payment session with Xendit. The
session_type
must beSAVE
, and theamount
must be0
.
Request - POST /sessions
| Request - POST /sessions
|
---|
Collect the card information
Implement card_session.js to collect card information.
Request - card_session.js
| Response - card_session.js
|
---|
Important: You must store the payment_token_id
returned in this response and send it to your server. This payment_token_id
is crucial for tracking the status of the card tokenization and for future transactions.
Redirect to the authentication page
After collecting card information, your customer will be redirected to a 3D Secure (3DS) authentication page hosted by the issuing bank. Upon successful authentication, the customer will be redirected back to your specified success page (e.g.
https://yourcompany.com/success
).Receive the webhook
Xendit sends a payment token webhook to your webhook endpoint providing updates on the activation progress of the payment token. Make sure to listen to the webhook to confirm the status of storing the card.
Example payment_token.activation
webhook
{
"created": "2024-12-18T03:57:21.601Z",
"business_id": "62440e322008e87fb29c1fd0",
"event": "payment_token.activation",
"data": {
"status": "ACTIVE",
"country": "ID",
"created": "2024-12-18T03:57:19.330Z",
"updated": "2024-12-18T03:57:21.215Z",
"currency": "IDR",
"business_id": "62440e322008e87fb29c1fd0",
"customer_id": "cust-9f02010d-1189-4f2c-95e9-fe7f52fdd29b",
"channel_code": "CARDS",
"reference_id": "efe51f0c-ea1f-45ec-96e4-5275db384d68_1b0d11cd-a",
"token_details": {
"authorization_data": {
"reconciliation_id": "7344942402526026003955",
"authorization_code": "831000",
"acquirer_merchant_id": "xendit_ctv_agg",
"network_response_code": "00",
"network_transaction_id": "016153570198200",
"cvn_verification_result": "M",
"retrieval_reference_number": "435203752181",
"address_verification_result": "M",
"network_response_code_descriptor": "Approved and completed sucessfully"
}
},
"payment_token_id": "pt-eda13864-5091-4bd2-b88d-ae640be90ee7",
"channel_properties": {
"card_details": {
"type": "CREDIT",
"issuer": "BRI",
"country": "ID",
"network": "VISA",
"expiry_year": "2040",
"fingerprint": "635a0be115cf90001ae83752",
"expiry_month": "12",
"cardholder_email": "test@yourdomain.com",
"masked_card_number": "400000XXXXXX1091",
"cardholder_last_name": "lastName",
"cardholder_first_name": "firstName",
"cardholder_phone_number": "+62812347290"
},
"skip_three_ds": true,
"card_on_file_type": "CUSTOMER_UNSCHEDULED",
"failure_return_url": "https://yourcompany.com/failure",
"success_return_url": "https://yourcompany.com/success"
}
},
"api_version": "v3"
}
Retrieving the stored card
After the card has been successfully tokenized (and you've received the
payment_token.activation
webhook), you can retrieve the token details by making a GET request topayment_tokens/YOUR_PAYMENT_TOKEN_ID
.
Response - /v3/payment_tokens
|
---|
Use payment token for future transactions
Once a payment token is generated, it acts as a secure reference to the end user's stored card details. You can use this token for future transactions, based on your consent agreement with the end user.
Common Use Cases for Payment Tokens:
Customer-Initiated Transactions (Returning Customers) - enables users to seamlessly use stored cards for their next purchase. To improve the success rate, we recommend prompting users to re-enter their CVN when completing the transaction. See our integration guide
Merchant-Initiated Transactions (Recurring Payments) - you can initiate the transaction without end-user interaction (e.g., for subscriptions or auto-debits). Ideal for subscription-based services, memberships, and automated billing. See our integration guide