Skip to navigation

PCI Compliant Card Tokenization

This recipe uses the Card Form Components. The legacy CoinflowCardNumberInput, CoinflowCvvInput, and CoinflowCvvOnlyInput components were removed in @coinflowlabs/react 6.0.0.

Install Coinflow
npm install @coinflowlabs/react
Tokenize New Card
import React, { useRef, useState } from 'react';
import { CoinflowCardForm, CardFormRef } from '@coinflowlabs/react';
function TokenizeNewCard() {
const cardFormRef = useRef<CardFormRef>(null);
const [token, setToken] = useState('');
const handleTokenize = async () => {
try {
const result = await cardFormRef.current?.tokenize();
if (!result) return;
// Pass result.token, result.expMonth and result.expYear to Card Checkout
setToken(result.token);
} catch (err) {
console.error('Tokenization failed:', err);
}
};
return (
<div>
<CoinflowCardForm
ref={cardFormRef}
merchantId="your-merchant-id" // Replace with your merchant id
env="sandbox" // Change to 'prod' for production
/>
<button onClick={handleTokenize}>Get Token</button>
</div>
);
}
export default TokenizeNewCard;
Card Checkout
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'x-coinflow-auth-session-key': process.env.SESSION_KEY, // Replace with payer session key
Authorization: process.env.YOUR_API_KEY // Replace with your API key
},
body: JSON.stringify({
"subtotal": {
"cents": 100
},
"transactionData": {
"type": "safeMint"
},
"authentication3DS": {
"concludeChallenge": true,
"deviceInfo": {
"completionIndicator": 1
}
},
"card": {
"expYear": "2030",
"expMonth": "05",
"email": "test@test.com",
"firstName": "test",
"lastName": "test",
"address1": "6175 Muller Isle",
"city": "Port Alejandroland",
"zip": "37475",
"state": "MO",
"country": "US",
"cardToken": "411111YJM5TX1111"
})
};
fetch('https://api-sandbox.coinflow.cash/api/checkout/card/test-merchant', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Refresh Token w/ CVV
import React, { useRef, useState } from 'react';
import { CoinflowCvvForm, CardFormRef } from '@coinflowlabs/react';
function RefreshCardToken({ savedCardToken }: { savedCardToken: string }) {
const cvvFormRef = useRef<CardFormRef>(null);
const [token, setToken] = useState('');
const handleTokenize = async () => {
try {
const result = await cvvFormRef.current?.tokenize();
if (!result) return;
setToken(result.token);
} catch (err) {
console.error('CVV tokenization failed:', err);
}
};
return (
<div>
<CoinflowCvvForm
ref={cvvFormRef}
merchantId="your-merchant-id" // Replace with your merchant id
env="sandbox" // Change to 'prod' for production
token={savedCardToken} // From Get Customer, eg: customer.cards[0].token
/>
<button onClick={handleTokenize}>Get Token</button>
</div>
);
}
export default RefreshCardToken;
Saved Card Checkout
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
'x-coinflow-auth-session-key': process.env.SESSION_KEY, // Replace with payer session key
Authorization: process.env.YOUR_API_KEY // Replace with your API key
},
body: JSON.stringify({
"subtotal": {
"cents": 100
},
"transactionData": {
"type": "safeMint"
},
"authentication3DS": {
"concludeChallenge": true,
"deviceInfo": {
"completionIndicator": 1
}
},
"token": "411111YJM5TX1111"
})
};
fetch('https://api-sandbox.coinflow.cash/api/checkout/token/test-merchant', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Response Example
{"success":true}

Install Coinflow

npm i @coinflowlabs/react

Tokenize New Card

Collect card information from customers in a PCI-compliant way. CoinflowCardForm collects the card number, expiration, and CVV, and tokenize() returns a token along with expMonth and expYear for their payment method.

Card Checkout

Pass the token retrieved from ‘Tokenize New Card’ to the Card Checkout API endpoint

Refresh a Saved Token

Refresh a saved token using the card’s CVV in a PCI-compliant way. Pass the saved card’s token from the Get Customer endpoint to CoinflowCvvForm. The refreshed card token will be valid for 5 minutes after initial use, or used within 7 days.

Saved Card Checkout

Pass the card token retrieved from ‘Refresh Token With CVV’ to Saved Card Checkout endpoint.