Tokenize credentials
Last updated: March 12, 2025
You can use Flow and Flow for mobile to securely collect and tokenize card details without going through the complete payment flow.
You receive a single, one-time use token that you can use to:
- Forward to a third-party payment service provider (PSP)
- Request 3D Secure (3DS) authentication in a standalone session
Make sure you have a test account with Checkout.com.
Create a public key and a secret key from the Dashboard, with the following key scopes:
- Public key –
payment-sessions:pay
andvault-tokenization
- Secret key –
payment-sessions
Send a server-side request to securely create a PaymentSession
object. The PaymentSession
contains the information required to handle the card tokenization.
Call the following endpoint with your secret key:
post
https://api.checkout.com/payment-sessions
For the full API specification, see the API reference.
1{2"amount": 1000,3"currency": "GBP",4"reference": "ORD-123A",5"display_name": "Online shop",6"billing": {7"address": {8"country": "GB"9}10},11"customer": {12"name": "Jia Tsang",13"email": "[email protected]"14},15"success_url": "https://example.com/payments/success",16"failure_url": "https://example.com/payments/failure"17}
1{2"id": "ps_2Un6I6lRpIAiIEwQIyxWVnV9CqQ",3"payment_session_secret": "pss_9823241e-2cec-4c98-b23d-7b29ow4e2e34",4"payment_session_token": "YmFzZTY0:eyJpZCI6InBzXzJVbjZJNmxScElBaUlFd1FJeXhXVm5WOUNxUSIsImFtb3VudCI6MTAwMCwibG9jYWxlIjoiZW4tR0IiLCJjdXJyZW5jeSI6IkdCUCIsInBheW1lbnRfbWV0aG9kcyI6W3sidHlwZSI6ImNhcmQiLCJjYXJkX3NjaGVtZXMiOlsiVmlzYSIsIk1hc3RlcmNhcmQiLCJBbWV4Il19XSwicmlzayI6eyJlbmFibGVkIjp0cnVlfSwiX2xpbmtzIjp7InNlbGYiOnsiaHJlZiI6Imh0dHBzOi8vYXBpLnNhbmRib3guY2hlY2tvdXQuY29tL3BheW1lbnQtc2Vzc2lvbnMvcHNfMlVuNkk2bFJwSUFpSUV3UUl5eFdWblY5Q3FRIn19fQ==",5"_links": {6"self": {7"href": "https://api.sandbox.checkout.com/payment-sessions/ps_2Un6I6lRpIAiIEwQIyxWVnV9CqQ"8}9}10}
Install the @checkout.com/checkout-web-components
package via npm:
1npm install @checkout.com/checkout-web-components --save
Alternatively, load the package directly via a script:
1<script src="https://checkout-web-components.checkout.com/index.js" />
Note
To remain PCI compliant, you should only ever load the script directly from https://checkout-web-components.checkout.com
. Do not download or host the script yourself, or include it in a bundle.
Use CheckoutWebComponents
to create a card
object:
1const cardComponent = checkout.create('card', {2showPayButton: false,3});
Check that the card
component is available and mount it:
1if (await cardComponent.isAvailable()) {2cardComponent.mount('#card-container');3}
Note
Embedding Flow within an iframe or onto a Shadow DOM is not supported.
Display a submit button that will trigger the card tokenization:
1<div id="card-container"></div>2<button id="card-pay-button" type="button">Pay</button>
Use the tokenize()
method to trigger card tokenization.
The tokenization response is returned as the data
object. You can access the generated card token within the data.token
property.
1const cardPayButton = document.getElementbyId('card-pay-button');23cardPayButton.addEventListener('click', async () => {4const { data } = await cardComponent.tokenize();56await utilizeToken(data.token);7});