Skip to navigation

Show card details

Display a card's number, expiration date and CVV on your page without the details reaching your servers.

The card viewer draws each card field in a secure frame on your page. Your backend requests a short-lived card token, and your page passes it to the viewer unchanged. The card number, expiration date and CVV never pass through your servers or your page’s DOM.

1

Request a card token

From your backend, read the card with extend=cardToken. The key needs cards:read, and the card must be ACTIVE. A platform key sends Account-Holder with the card’s account holder ID; a company key does not. Set API_HOST to the API domain assigned to your integration.

curl "https://$API_HOST/api/v2/cards/$CARD_ID?extend=cardToken" \
-H "Authorization: Bearer $TOKEN" \
-H "Account-Holder: $ACCOUNT_HOLDER_ID"

Send only the response’s cardToken object to your page, and only to a user who may see this card’s details. Treat it as opaque:

  • Pass it to the viewer exactly as the API returned it.
  • Request a new one each time you show the card. It stops working at expiresAt.
  • Do not store it, log it or put it in a URL.
2

Load the viewer

Load the viewer with the @outpave/outpave-js npm package or a script tag. Replace APP_HOST with the domain of the web app assigned to your integration. Both load it over HTTPS from this address rather than a copy, so your page receives fixes.

// npm install @outpave/outpave-js
import { loadEmbedded } from "@outpave/outpave-js";
const embedded = await loadEmbedded({
loaderUrl: "https://APP_HOST/embedded/v1/loader.js",
});

The package adds TypeScript types. loadEmbedded resolves null where there is no window, such as during server rendering, so call it in the browser.

3

Mount the viewer

Mount the viewer in an element on your page, such as <div id="card-details"></div>, with the card token from your backend.

async function showCard(cardId) {
// Your backend endpoint, which returns the cardToken from the API.
const response = await fetch(`/cards/${cardId}/card-token`);
const { cardToken } = await response.json();
return embedded.mount({
container: "#card-details",
cardToken,
style: { base: { color: "#1f2933", fontFamily: "system-ui, sans-serif", fontSize: "16px" } },
onReady: () => {
// Every field is showing.
},
onError: ({ code }) => {
// CARD_UNAVAILABLE: request a new card token and mount again.
},
});
}

Call unmount() on the returned object to remove the viewer. No callback fires after it.

Options

OptionTypeDescription
containerHTMLElement or stringRequired. The element the viewer is added to, or a CSS selector that matches one.
cardTokenobjectRequired. The cardToken of GET /cards/{cardId}?extend=cardToken, unchanged.
labelsobjectLabel text for cardNumber, expirationDate and cvv. Defaults: Card number, Expiration date and CVV.
styleobjectText style for the card fields. style.base accepts color, fontFamily, fontSize, fontWeight, lineHeight and letterSpacing, as CSS values.
onReady() => voidCalled once every field shows.
onError({ code }) => voidCalled with code CARD_UNAVAILABLE when the card cannot be shown, including after it was shown. Request a new card token and mount again.
onCopy({ field }) => voidCalled when the user copies a field. field is cardNumber, expirationDate or cvv.

Copying

Depending on the card’s program, the viewer adds a copy button beside the card number or copies a field when the user clicks it. onCopy reports the field either way.

Layout

The viewer adds this structure to container. Style the rows and labels with your own CSS through its attributes; style the card fields themselves with style.

<div data-embedded-card-viewer role="group" aria-busy="false">
<div data-field="cardNumber"><span>Card number</span><div><!-- secure frame --></div></div>
<div data-field="expirationDate"><span>Expiration date</span><div><!-- secure frame --></div></div>
<div data-field="cvv"><span>CVV</span><div><!-- secure frame --></div></div>
</div>

aria-busy is true until the fields show.

Errors

WhereErrorCause
API403 PERMISSION_DENIEDThe key does not hold cards:read.
API422 NOT_ELIGIBLEThe card is not ACTIVE, or it was added from an external account.
mountTypeErrorcontainer matches no element, or cardToken is missing or not the object the API returned.
onErrorCARD_UNAVAILABLEThe card token expired or was refused, or the card can no longer be shown.