Card widget
Show a card to your user inside your own website or mobile app: server step, the web script, React / Next.js, Vue, React Native, Android, iOS and Flutter components, events, styles and security.
The card widget shows a card (masked), its balance, and lets the user reveal the full number, expiry and CVC after entering their card PIN, and freeze or unfreeze the card. It loads directly in the section of your page or screen that you choose: no popup, no separate page, no WebView.
Card details travel from Tranzak to your user's screen only. They never pass through your server, and they are never returned by the API.
How it works
- Your server asks for a widget session for one card.
- Your website (or mobile app) shows the widget in the section you reserve for it.
- The user reveals the details with their PIN.
- First time (no PIN yet): the widget sends a confirmation link to the e-mail address Tranzak holds for the cardholder (never to an address you provide). The cardholder clicks it and confirms it is them, comes back to the page, and chooses their PIN. There is no code to type. Nobody else can create the first PIN: not you, not your servers, not your page. Only the cardholder's own session can, within 30 minutes after their click.
- Forgot the PIN: the widget offers "Code PIN oublié ?": a 6-digit code is sent to the same registered address and the user chooses a new PIN. Tranzak then e-mails them that the PIN was changed. You have nothing to build for this. The details hide again by themselves after 45 seconds.
A session is valid for 5 minutes and works once. Create a new one every time you display the card.
1. Declare your websites (web only)
In your dashboard (Cards → Widget domains) list every website where you will display the widget, one per line, for example https://shop.example.com. Only https:// addresses are accepted (plus http://localhost while you develop), and no wildcards. Native mobile apps do not need a domain.
2. Create a session on your server
Check on your server that the logged-in user owns the card before you create a session.
POST /api/cards/v1/cards/{card_id}/widget-sessions
| Field | Description |
|---|---|
origin |
Web. The website that will display the widget. It must be one of your declared domains. |
layout |
Web. inline (recommended): the card is drawn in your page, and only the sensitive parts are small Tranzak frames. framed: one frame contains the whole card. Default: framed. |
client |
Use native for a mobile app (see Mobile apps). No origin needed. |
permissions |
Optional. A list among reveal (show the details) and freeze (freeze and unfreeze). Default: both. |
style |
Optional. See Style. |
import { createWidgetSession } from '@tranzakpackage/cards-server';
const widget = await createWidgetSession({
apiKey: process.env.TRANZAK_API_KEY,
cardId,
origin: 'https://shop.example.com',
layout: 'inline',
});
// send `widget` to your page
curl https://api.tranzak.co/api/cards/v1/cards/card_vafgjlnlt8izadfhcrdo/widget-sessions \
-H "X-Api-Key: $TRANZAK_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "origin": "https://shop.example.com", "layout": "inline" }'
{
"success": true,
"widget": {
"layout": "inline",
"vault_url": "https://api.tranzak.co/widget/controls/…",
"field_urls": {
"number": "https://api.tranzak.co/widget/field/…",
"expiry": "https://api.tranzak.co/widget/field/…",
"cvc": "https://api.tranzak.co/widget/field/…"
},
"expires_at": "2026-11-19T20:24:02-05:00",
"origin": "https://shop.example.com"
}
}
With layout: "framed" the answer holds a single url instead. Pass the whole widget object to the component: it knows what to do with it.
Errors: 403 origin_not_allowed (the origin is not declared), 422 invalid_origin, 409 card_unavailable (the card is not active or frozen yet), 404 card_not_found.
3. Display it in a website
Why the card is drawn in your page, but the sensitive parts are not
With layout: "inline", the card (frame, balance, buttons, layout) is drawn inside your page, in the section you choose. Only four small areas are frames hosted by Tranzak: the number, the expiry, the CVC, and the PIN entry. Your users do not see a frame border: they see one card.
Browsers isolate a frame that comes from another domain: no script of your page (advertising, analytics, an injected script) can read what is inside it, listen to it, or capture what is typed in it. If the number were written straight into your page, any of those scripts could read it, and your site would fall inside PCI scope. Your page only ever receives non-sensitive information: last 4 digits, holder name, balance and status.
Script tag
<div id="card"></div>
<script src="https://api.tranzak.co/js/tranzak-cards.js"></script>
<script>
// `widget` is the object your server returned
var card = TranzakCards.mount({
container: '#card',
widget: widget,
onReady: function () {},
onFrozen: function () {},
onUnfrozen: function () {},
onError: function (e) { console.log(e.code); }
});
// card.destroy() removes it.
</script>
React and Next.js
npm install @tranzakpackage/cards-react @tranzakpackage/cards-server
// app/card/page.jsx (server component)
import { createWidgetSession } from '@tranzakpackage/cards-server';
import CardView from './CardView';
export default async function Page() {
const widget = await createWidgetSession({ apiKey: process.env.TRANZAK_API_KEY, cardId: 'card_…', origin: 'https://shop.example.com' });
return <CardView widget={widget} />;
}
// app/card/CardView.jsx
'use client';
import { TranzakCard } from '@tranzakpackage/cards-react';
export default function CardView({ widget }) {
return <TranzakCard widget={widget} onFrozen={() => console.log('frozen')} />;
}
The component only touches the browser after it is mounted, so server rendering is safe. It works the same in the Pages Router and in plain React.
Vue and Nuxt
npm install @tranzakpackage/cards-vue
<script setup>
import { TranzakCard } from '@tranzakpackage/cards-vue';
defineProps({ widget: Object }); // the object returned by your server
</script>
<template>
<TranzakCard :widget="widget" @frozen="onFrozen" @error="(e) => console.log(e.code)" />
</template>
In Nuxt, load the widget object with useFetch from your own server route, then render the component (it is safe on the server).
Events (web, React, Vue)
| Event | When |
|---|---|
ready |
The card is displayed. |
frozen / unfrozen |
The user froze or unfroze the card. |
error |
An action failed. code: session_expired, pin_locked, card_locked, frozen_by_tranzak, timeout… |
resize |
The height of the controls changed (height, in pixels). |
state-change |
Non-sensitive state: last4, brand, holder, status, balance, currency, revealed. |
Events never contain the card number, the CVC, the expiry date or the PIN.
If your site uses a Content Security Policy
Allow the widget host in frame-src and the script host in script-src. Keep third-party scripts off the page that shows the card when you can.
4. Display it in a mobile app (native, no WebView)
In a mobile app the card is drawn natively, directly in your own screen. Your app talks to the Tranzak widget API with a native session.
Create a native session on your server
Same endpoint, with "client": "native". There is no origin to declare.
import { createNativeSession } from '@tranzakpackage/cards-server';
const session = await createNativeSession({ apiKey: process.env.TRANZAK_API_KEY, cardId });
// → { mode: 'native', session_secret, expires_at, api_base }
{
"success": true,
"widget": {
"mode": "native",
"session_secret": "…",
"expires_at": "2026-11-19T20:24:02-05:00",
"api_base": "https://api.tranzak.co/widget/api"
}
}
Send session_secret and api_base to your app over your own authenticated connection. The secret is valid for 5 minutes, is shown once, and is never placed in a URL.
Note The JSON keys are
session_secretandapi_base. The samples below use the naming of each platform (sessionSecret,apiBasein Kotlin, Swift and Dart): map the keys when you decode the response. The API address must be HTTPS (plain HTTP is only accepted forlocalhost,127.0.0.1and the Android emulator address10.0.2.2).
React Native
npm install @tranzakpackage/cards-react-native
import { TranzakCardView } from '@tranzakpackage/cards-react-native';
<TranzakCardView
apiBase={session.api_base}
sessionSecret={session.session_secret}
onFrozen={refresh}
onError={(code) => console.log(code)}
/>
Android (Kotlin)
Add the co.tranzak.cards library module to your project (it has no dependencies), and declare the network permission in your app manifest:
<uses-permission android:name="android.permission.INTERNET" />
val card = TranzakCardView(context)
container.addView(card)
card.listener = object : TranzakCardView.Listener {
override fun onFrozen() { refresh() }
override fun onError(code: String) { Log.d("card", code) }
}
card.start(apiBase = session.apiBase, sessionSecret = session.sessionSecret)
The component turns on FLAG_SECURE for its window by default, so the screen cannot be captured while a card is displayed. Set preventScreenCapture = false to turn this off.
iOS (Swift and SwiftUI)
Add the TranzakCards Swift package (Xcode: File → Add Package Dependencies, iOS 13 or later), then import TranzakCards.
let card = TranzakCardView()
card.delegate = self
stack.addArrangedSubview(card)
card.start(apiBase: session.apiBase, sessionSecret: session.sessionSecret)
TranzakCard(apiBase: session.apiBase, sessionSecret: session.sessionSecret, onFrozen: { refresh() })
The details are hidden when the app goes to the background, when a screenshot is taken and when the screen is being recorded.
Flutter
Add the package to your pubspec.yaml (tranzak_cards), then import 'package:tranzak_cards/tranzak_cards.dart';.
TranzakCardView(
apiBase: session.apiBase,
sessionSecret: session.sessionSecret,
onFrozen: () => refresh(),
onError: (code) => debugPrint(code), // a code such as session_expired, never card data
)
What the native components do
They show a loading skeleton, the masked card in black and white, the balance, the PIN-protected reveal and the freeze button. They adapt to the width they are given, hide the details after reveal_seconds (45 by default) and as soon as the app leaves the foreground. The state also shows an honest status (ACTIVE, GELÉE, ANNULÉE…) and explains when a card was frozen by Tranzak.
Another platform: the native API
You can also call the widget API yourself and draw the card. Send the secret in the X-Widget-Session header.
| Request | Description |
|---|---|
GET {api_base}/state |
Masked card: last4, brand, holder, status, balance, currency, pin_set, pin_link (none, sent or confirmed: progress of the first-PIN confirmation), can_reveal, can_freeze, can_unfreeze, frozen_by_tranzak, reveal_seconds, style. |
POST {api_base}/pin-link/send |
Sends the first-PIN confirmation link to the cardholder's registered e-mail (only when the card has no PIN). Returns email_hint. Poll state until pin_link is confirmed. |
POST {api_base}/pin |
{ "pin": "4829" }. Creates the first PIN, only after the cardholder confirmed the link (confirmation_required otherwise). |
POST {api_base}/pin-reset/request and POST {api_base}/pin-reset/confirm |
Forgotten PIN: sends a 6-digit code to the registered e-mail, then { "code": "123456", "pin": "7391" } sets the new PIN. |
POST {api_base}/reveal |
{ "pin": "4829" }. Returns card.number, card.cvc, card.exp_month, card.exp_year. |
POST {api_base}/freeze and POST {api_base}/unfreeze |
Freeze or unfreeze the card. Return the updated state. |
Errors use { "success": false, "error": "<code>" }: session_expired (401), wrong_pin (with attempts_left), pin_locked (429, with retry_after in seconds), weak_pin, pin_already_set (a PIN already exists: read state again), confirmation_required (the cardholder has not confirmed the e-mail link yet), code_invalid (with attempts_left), code_expired, too_many_attempts, wait / too_many_requests (e-mails are rate limited), pin_not_set, not_permitted, card_unavailable, card_locked, frozen_by_tranzak, card_not_funded, service_unavailable.
Rules for your app:
- Keep the secret and the card details in memory only. Never store, log or send them to your own servers.
- Show the details for a short time only, and hide them when the app goes to the background.
- Turn on your platform's secure-screen flag on the screen that shows the card.
Style
The design is black and white (white card, black border and text) so it fits any website or app. Choose only from these options:
| Option | Values |
|---|---|
theme |
light (default) or dark, which inverts black and white for a dark background. |
radius |
none, sm, md (default), lg |
font |
system (default), serif, mono |
Anything else is ignored: custom CSS is not accepted.
The card PIN
The first time the user reveals the details, the widget asks them to create a 4-digit PIN for that card. The PIN is stored hashed and is asked every time the details are revealed. After 5 wrong attempts the card is locked for 15 minutes, whatever the session.
Security checklist
- Create the session from your server, after checking the user owns the card.
- One session per display: never cache or share a session.
- Declare only the websites you control.
- Prefer
layout: "inline": it gives the most integrated look while keeping the card details out of reach of your page's scripts. - Do not store, log or screenshot the card details.