Generate Card Details Token
curl --request POST \
--url https://api.example.com/v1/card/details/token \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--header 'x-client-key: <x-client-key>' \
--data '
{
"customCss": {
"customCss.cardBackgroundColor": "<string>",
"customCss.cardTextColor": "<string>",
"customCss.panBackgroundColor": "<string>",
"customCss.panTextColor": "<string>"
}
}
'import requests
url = "https://api.example.com/v1/card/details/token"
payload = { "customCss": {
"customCss.cardBackgroundColor": "<string>",
"customCss.cardTextColor": "<string>",
"customCss.panBackgroundColor": "<string>",
"customCss.panTextColor": "<string>"
} }
headers = {
"x-client-key": "<x-client-key>",
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-client-key': '<x-client-key>',
Authorization: '<authorization>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customCss: {
'customCss.cardBackgroundColor': '<string>',
'customCss.cardTextColor': '<string>',
'customCss.panBackgroundColor': '<string>',
'customCss.panTextColor': '<string>'
}
})
};
fetch('https://api.example.com/v1/card/details/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/card/details/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customCss' => [
'customCss.cardBackgroundColor' => '<string>',
'customCss.cardTextColor' => '<string>',
'customCss.panBackgroundColor' => '<string>',
'customCss.panTextColor' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json",
"x-client-key: <x-client-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/card/details/token"
payload := strings.NewReader("{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-client-key", "<x-client-key>")
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/card/details/token")
.header("x-client-key", "<x-client-key>")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/card/details/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-client-key"] = '<x-client-key>'
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"token": "100a99cf-f4d3-4fa1-9be9-2e9828b20ebb",
"imageUrl": "https://cards.baanx.com/details-image?token=100a99cf-f4d3-4fa1-9be9-2e9828b20ebb"
}
Card
Generate Card Details Token
Generate a secure token for displaying sensitive card details through an image-based display
POST
/
v1
/
card
/
details
/
token
Generate Card Details Token
curl --request POST \
--url https://api.example.com/v1/card/details/token \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--header 'x-client-key: <x-client-key>' \
--data '
{
"customCss": {
"customCss.cardBackgroundColor": "<string>",
"customCss.cardTextColor": "<string>",
"customCss.panBackgroundColor": "<string>",
"customCss.panTextColor": "<string>"
}
}
'import requests
url = "https://api.example.com/v1/card/details/token"
payload = { "customCss": {
"customCss.cardBackgroundColor": "<string>",
"customCss.cardTextColor": "<string>",
"customCss.panBackgroundColor": "<string>",
"customCss.panTextColor": "<string>"
} }
headers = {
"x-client-key": "<x-client-key>",
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-client-key': '<x-client-key>',
Authorization: '<authorization>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customCss: {
'customCss.cardBackgroundColor': '<string>',
'customCss.cardTextColor': '<string>',
'customCss.panBackgroundColor': '<string>',
'customCss.panTextColor': '<string>'
}
})
};
fetch('https://api.example.com/v1/card/details/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/card/details/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customCss' => [
'customCss.cardBackgroundColor' => '<string>',
'customCss.cardTextColor' => '<string>',
'customCss.panBackgroundColor' => '<string>',
'customCss.panTextColor' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json",
"x-client-key: <x-client-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/card/details/token"
payload := strings.NewReader("{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-client-key", "<x-client-key>")
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/card/details/token")
.header("x-client-key", "<x-client-key>")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/card/details/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-client-key"] = '<x-client-key>'
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customCss\": {\n \"customCss.cardBackgroundColor\": \"<string>\",\n \"customCss.cardTextColor\": \"<string>\",\n \"customCss.panBackgroundColor\": \"<string>\",\n \"customCss.panTextColor\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"token": "100a99cf-f4d3-4fa1-9be9-2e9828b20ebb",
"imageUrl": "https://cards.baanx.com/details-image?token=100a99cf-f4d3-4fa1-9be9-2e9828b20ebb"
}
Overview
Generates a time-limited secure token that allows you to display sensitive card information (full PAN, CVV, expiry date) as an image without ever handling this data directly in your application. The token provides access to a secure image URL that renders card details in a PCI-compliant manner.PCI Compliance Made EasyThis endpoint eliminates PCI compliance burden by returning card details as a secure image. Your application never touches or stores the actual card details.
Authentication
This endpoint requires authentication via Bearer token:Authorization: Bearer YOUR_ACCESS_TOKEN
Request
Headers
string
required
Your public API client key
boolean
default:false
Set to
true to route requests to the US backend environmentstring
required
Bearer token for authentication
Body
The request body is optional. If omitted, default styling will be applied to the card image.
object
Customize the visual appearance of the card details image to match your brand
Show customCss properties
Show customCss properties
string
default:"#000000"
Background color of the card imageExample:
#1A1A1A, #2563EBstring
default:"#FFFFFF"
Text color for card informationImportant: Avoid using the same color as
cardBackgroundColor for readabilityExample: #FFFFFF, #F3F4F6string
default:"#EFEFEF"
Background color for the PAN number display areaExample:
#F9FAFB, #E5E7EBstring
default:"#000000"
Text color for PAN numberImportant: Avoid using the same color as
panBackgroundColor for readabilityExample: #000000, #111827Request Example
curl -X POST https://dev.api.baanx.com/v1/card/details/token \
-H "x-client-key: YOUR_CLIENT_KEY" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"customCss": {
"cardBackgroundColor": "#000000",
"cardTextColor": "#FFFFFF",
"panBackgroundColor": "#EFEFEF",
"panTextColor": "#000000"
}
}'
const response = await fetch('https://dev.api.baanx.com/v1/card/details/token', {
method: 'POST',
headers: {
'x-client-key': 'YOUR_CLIENT_KEY',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customCss: {
cardBackgroundColor: '#000000',
cardTextColor: '#FFFFFF',
panBackgroundColor: '#EFEFEF',
panTextColor: '#000000'
}
})
});
const data = await response.json();
console.log('Card image URL:', data.imageUrl);
import requests
url = "https://dev.api.baanx.com/v1/card/details/token"
headers = {
"x-client-key": "YOUR_CLIENT_KEY",
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json"
}
payload = {
"customCss": {
"cardBackgroundColor": "#000000",
"cardTextColor": "#FFFFFF",
"panBackgroundColor": "#EFEFEF",
"panTextColor": "#000000"
}
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
print(f"Card image URL: {data['imageUrl']}")
interface CardDetailsTokenRequest {
customCss?: {
cardBackgroundColor?: string;
cardTextColor?: string;
panBackgroundColor?: string;
panTextColor?: string;
};
}
interface CardDetailsTokenResponse {
token: string;
imageUrl: string;
}
const generateCardDetailsToken = async (
config?: CardDetailsTokenRequest
): Promise<CardDetailsTokenResponse> => {
const response = await fetch('https://dev.api.baanx.com/v1/card/details/token', {
method: 'POST',
headers: {
'x-client-key': 'YOUR_CLIENT_KEY',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: config ? JSON.stringify(config) : undefined
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
};
Response
Success Response
string
Secure, time-limited token (UUID format)Lifetime: ~10 minutesUsage: Single-use token that becomes invalid after the image is accessed
string
URL that renders card details as a secure imageUsage: Display card details by using this URL as the
src attribute of an <img> tagFormat: <HOST>/details-image?token={token}Security: Treat this URL as highly sensitive. Do not log or store it.{
"token": "100a99cf-f4d3-4fa1-9be9-2e9828b20ebb",
"imageUrl": "https://cards.baanx.com/details-image?token=100a99cf-f4d3-4fa1-9be9-2e9828b20ebb"
}
Error Responses
{
"message": "Not authenticated"
}
{
"message": "Not authorized"
}
{
"message": "Card not found"
}
{
"message": "Validation error",
"errors": [
{
"field": "customCss.cardBackgroundColor",
"message": "Invalid hex color format"
}
]
}
{
"message": "Invalid client key"
}
{
"message": "Missing client key"
}
{
"message": "Internal server error"
}
Integration Method
Display card details as a secure image without interactive elements.Basic Implementation
const { imageUrl } = await generateCardDetailsToken({
customCss: {
cardBackgroundColor: '#000000',
cardTextColor: '#FFFFFF',
panBackgroundColor: '#EFEFEF',
panTextColor: '#000000'
}
});
const img = document.createElement('img');
img.src = imageUrl;
img.alt = 'Card Details';
img.style.maxWidth = '100%';
img.style.borderRadius = '12px';
document.getElementById('card-image-container').appendChild(img);
React Component Example
import { useState } from 'react';
export function CardDetailsImage() {
const [imageUrl, setImageUrl] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleViewCard = async () => {
setLoading(true);
setError(null);
try {
const response = await fetch('https://dev.api.baanx.com/v1/card/details/token', {
method: 'POST',
headers: {
'x-client-key': 'YOUR_CLIENT_KEY',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customCss: {
cardBackgroundColor: '#000000',
cardTextColor: '#FFFFFF',
panBackgroundColor: '#EFEFEF',
panTextColor: '#000000'
}
})
});
if (!response.ok) {
throw new Error('Failed to generate card details token');
}
const data = await response.json();
setImageUrl(data.imageUrl);
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
} finally {
setLoading(false);
}
};
return (
<div>
<button onClick={handleViewCard} disabled={loading}>
{loading ? 'Loading...' : 'View Card Details'}
</button>
{error && <div className="error">{error}</div>}
{imageUrl && (
<div className="card-image-container">
<img
src={imageUrl}
alt="Card Details"
style={{ maxWidth: '100%', borderRadius: '12px' }}
/>
<button onClick={() => setImageUrl(null)}>Close</button>
</div>
)}
</div>
);
}
Security NoteImage URLs contain sensitive card information. Always:
- Use HTTPS only
- Never log or store the imageUrl
- Display in secure contexts only
- Clear the image from DOM when user is done viewing
Customization Examples
Dark Mode Theme
{
"customCss": {
"cardBackgroundColor": "#1F2937",
"cardTextColor": "#F9FAFB",
"panBackgroundColor": "#374151",
"panTextColor": "#F3F4F6"
}
}
Light Mode Theme
{
"customCss": {
"cardBackgroundColor": "#FFFFFF",
"cardTextColor": "#111827",
"panBackgroundColor": "#F3F4F6",
"panTextColor": "#1F2937"
}
}
Brand Colors
{
"customCss": {
"cardBackgroundColor": "#2563EB",
"cardTextColor": "#FFFFFF",
"panBackgroundColor": "#DBEAFE",
"panTextColor": "#1E40AF"
}
}
Security Considerations
Token Lifetime and Single-Use
- Tokens expire after ~10 minutes
- Tokens are single-use and become invalid after first access
- Generate a new token each time the user wants to view card details
- Never store or cache tokens
PCI ComplianceBy using this endpoint, you avoid PCI compliance requirements as sensitive card data is delivered as an image. Your servers and frontend code never handle the actual card details.
URL Security
- Treat
imageUrlas highly sensitive data - Don’t log or store these URLs
- Use HTTPS only
- Display only in authenticated, secure contexts
Best Practices
Error Handling
async function showCardDetails() {
try {
const { imageUrl } = await generateCardDetailsToken({
customCss: {
cardBackgroundColor: '#000000',
cardTextColor: '#FFFFFF',
panBackgroundColor: '#EFEFEF',
panTextColor: '#000000'
}
});
const img = document.createElement('img');
img.src = imageUrl;
img.alt = 'Card Details';
img.style.maxWidth = '100%';
document.getElementById('card-container').appendChild(img);
} catch (error) {
if (error.response?.status === 404) {
alert('No card found. Please order a card first.');
} else if (error.response?.status === 401) {
alert('Session expired. Please log in again.');
} else if (error.response?.status === 422) {
alert('Invalid styling parameters. Please check your customCss values.');
} else {
alert('Failed to load card details. Please try again.');
}
}
}
Cleanup After Viewing
function createCardViewer() {
let currentImage: HTMLImageElement | null = null;
async function showCard() {
const { imageUrl } = await generateCardDetailsToken();
currentImage = document.createElement('img');
currentImage.src = imageUrl;
currentImage.alt = 'Card Details';
document.getElementById('card-container').appendChild(currentImage);
}
function hideCard() {
if (currentImage) {
currentImage.remove();
currentImage = null;
}
}
return { showCard, hideCard };
}
const cardViewer = createCardViewer();
Common Issues and Solutions
Token Expired
Token Expired
Symptom: Image fails to load with “Invalid or expired token” errorCause: Token has expired (>10 minutes old) or was already usedSolution: Generate a new token. Never reuse or cache tokens.
Colors Not Readable
Colors Not Readable
Symptom: Text is difficult to read on the card imageCause: Text color and background color are too similarSolution: Ensure sufficient contrast between text and background colors. Avoid using the same hex value for both.
Image Not Displaying
Image Not Displaying
Symptom: Image element shows broken image iconCause: Token may be invalid, expired, or network issueSolution:
const img = document.createElement('img');
img.onerror = () => {
console.error('Failed to load card image');
alert('Unable to display card details. Please try again.');
};
img.src = imageUrl;
422 Validation Error
422 Validation Error
Symptom: Request fails with 422 status codeCause: Invalid customCss parameters (e.g., malformed hex colors)Solution: Ensure all color values are valid 6-digit hex codes starting with #. Example:
#1A1A1A, not 1A1A1A or #1A1ARelated Endpoints
GET /v1/card/status- Get basic card information before generating tokenPOST /v1/card/pin/token- Generate token to view card PINPOST /v1/card/set-pin/token- Generate token to set/change card PINPOST /v1/card/freeze- Temporarily disable cardPOST /v1/card/order- Order a new card
Was this page helpful?