> This page is for version v2.
> For other versions, use one of these documentation indexes:
> - v1 (default): https://developers.outpave.com/v1/llms.txt
> - v2: https://developers.outpave.com/v2/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.outpave.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.outpave.com/_mcp/server.

# Show card details

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.

#### 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.

```bash
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.

#### 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`**

```ts title="npm"
// npm install @outpave/outpave-js
import { loadEmbedded } from "@outpave/outpave-js";

const embedded = await loadEmbedded({
  loaderUrl: "https://APP_HOST/embedded/v1/loader.js",
});
```

**`Script tag`**

```html title="Script tag"
<script src="https://APP_HOST/embedded/v1/loader.js"></script>
<script>
  const embedded = window.OutpaveEmbedded.v1;
</script>
```

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

#### 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.

```js
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

| Option      | Type                      | Description                                                                                                                                            |
| ----------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `container` | `HTMLElement` or `string` | Required. The element the viewer is added to, or a CSS selector that matches one.                                                                      |
| `cardToken` | `object`                  | Required. The `cardToken` of `GET /cards/{cardId}?extend=cardToken`, unchanged.                                                                        |
| `labels`    | `object`                  | Label text for `cardNumber`, `expirationDate` and `cvv`. Defaults: `Card number`, `Expiration date` and `CVV`.                                         |
| `style`     | `object`                  | Text style for the card fields. `style.base` accepts `color`, `fontFamily`, `fontSize`, `fontWeight`, `lineHeight` and `letterSpacing`, as CSS values. |
| `onReady`   | `() => void`              | Called once every field shows.                                                                                                                         |
| `onError`   | `({ code }) => void`      | Called 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 }) => void`     | Called 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`.

```html
<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

| Where     | Error                                                                 | Cause                                                                                         |
| --------- | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| API       | `403` [`PERMISSION_DENIED`](/v2/docs/guides/errors#permission-denied) | The key does not hold `cards:read`.                                                           |
| API       | `422` [`NOT_ELIGIBLE`](/v2/docs/guides/errors#not-eligible)           | The card is not `ACTIVE`, or it was added from an external account.                           |
| `mount`   | `TypeError`                                                           | `container` matches no element, or `cardToken` is missing or not the object the API returned. |
| `onError` | `CARD_UNAVAILABLE`                                                    | The card token expired or was refused, or the card can no longer be shown.                    |