# Tokenize credentials You can use [Flow](https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website.md) and [Flow for mobile](https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-mobile-app.md) to securely collect and tokenize card details without going through the complete payment flow. You receive a single-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. --- ## Before you start Make sure you have a Checkout.com [test account](https://www.checkout.com/get-test-account). Create a [public key and a secret key](https://www.checkout.com/docs/resources/api-authentication/api-keys.md) in the [Dashboard](https://dashboard.checkout.com), with the following key scopes: - Public key – `payment-sessions:pay` and `vault-tokenization` - Secret key – `payment-sessions` --- ## How it works 1. Create a Payment Session. 2. Initialize and mount Flow. 3. Tokenize the card details. --- ## Create a Payment Session `Server side` **Web** Send a server-side request to securely create a `PaymentSession` object. The `PaymentSession` contains the information required to handle the card tokenization. Call the [Request a Payment Session](https://api-reference.checkout.com/tag/Flow/#operation/CreatePaymentSession) endpoint with your secret key: > **Information** > > Your base URL's `{prefix}` value is unique to your account and environment. To learn how to retrieve your base URLs for the sandbox and production environments, see [API endpoints](https://www.checkout.com/docs/developer-resources/api/api-endpoints.md). **Production** `POST` `https://{prefix}.api.checkout.com/payment-sessions` **Sandbox** `POST` `https://{prefix}.api.sandbox.checkout.com/payment-sessions` ### Request example ```json { "amount": 1000, "currency": "GBP", "reference": "ORD-123A", "display_name": "Online shop", "billing": { "address": { "country": "GB" } }, "customer": { "name": "Jia Tsang", "email": "jia.tsang@example.com" }, "success_url": "https://example.com/payments/success", "failure_url": "https://example.com/payments/failure" } ``` ### Response example ```json { "id": "ps_2Un6I6lRpIAiIEwQIyxWVnV9CqQ", "payment_session_secret": "pss_9823241e-2cec-4c98-b23d-7b29ow4e2e34", "payment_session_token": "YmFzZTY0:eyJpZCI6InBzXzJVbjZJNmxScElBaUlFd1FJeXhXVm5WOUNxUSIsImFtb3VudCI6MTAwMCwibG9jYWxlIjoiZW4tR0IiLCJjdXJyZW5jeSI6IkdCUCIsInBheW1lbnRfbWV0aG9kcyI6W3sidHlwZSI6ImNhcmQiLCJjYXJkX3NjaGVtZXMiOlsiVmlzYSIsIk1hc3RlcmNhcmQiLCJBbWV4Il19XSwicmlzayI6eyJlbmFibGVkIjp0cnVlfSwiX2xpbmtzIjp7InNlbGYiOnsiaHJlZiI6Imh0dHBzOi8vYXBpLnNhbmRib3guY2hlY2tvdXQuY29tL3BheW1lbnQtc2Vzc2lvbnMvcHNfMlVuNkk2bFJwSUFpSUV3UUl5eFdWblY5Q3FRIn19fQ==", "_links": { "self": { "href": "https://{prefix}.api.sandbox.checkout.com/payment-sessions/ps_2Un6I6lRpIAiIEwQIyxWVnV9CqQ" } } } ``` **Android** Send a server-side request to securely create a `PaymentSession` object. The `PaymentSession` contains the information required to handle the card tokenization. ```javascript const createPaymentSession = async (req, res) => { const response = await fetch("https://{prefix}.api.checkout.com/payment-sessions", { method: "POST", headers: { Authorization: `Bearer ${secretKey}`, "Content-Type": "application/json", }, body: JSON.stringify({ amount: 1000, currency: "GBP", reference: "ORD-123A", display_name: "Online Shop", billing: { address: { country: "GB" }, }, customer: { name: "Jia Tsang", email: "jia.tsang@example.com", }, success_url: "https://example.com/payments/success", failure_url: "https://example.com/payments/failure", }), }); const paymentSession = await response.json(); res.json(paymentSession); }; ``` **iOS** Send a server-side request to securely create a `PaymentSession` object. The `PaymentSession` contains the information required to handle the card tokenization. ```javascript const createPaymentSession = async (req, res) => { const response = await fetch("https://{prefix}.api.checkout.com/payment-sessions", { method: "POST", headers: { Authorization: `Bearer ${secretKey}`, "Content-Type": "application/json", }, body: JSON.stringify({ amount: 1000, currency: "GBP", reference: "ORD-123A", display_name: "Online Shop", billing: { address: { country: "GB" }, }, customer: { name: "Jia Tsang", email: "jia.tsang@example.com", }, success_url: "https://example.com/payments/success", failure_url: "https://example.com/payments/failure", }), }); const paymentSession = await response.json(); res.json(paymentSession); }; ``` --- ## Initialize and mount Flow `Client side` **Web** Install the `@checkout.com/checkout-web-components` package via npm: ```bash npm install @checkout.com/checkout-web-components --save ``` Alternatively, load the package directly using a script: ```html