> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ionicfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Review a card before payment

> Collect a card, finish pricing the order, then confirm payment with the same card.

A **ConfirmationToken** lets you collect a card before you are ready to charge
it. Blocks returns a `ct_...` ID and basic card details. Your server can then
check the order, apply any price adjustments, and show the final total to the
customer. When they accept, use that token ID to confirm the payment.

**The token identifies the card. The PaymentIntent sets the amount.** Creating
a token does not charge the card or place a hold.

For example: a customer enters their card for a \$100 order. Your server applies
a \$10 discount and shows the new \$90 total. After acceptance, you create a
PaymentIntent for `9000` cents and confirm it with the card already collected.

```mermaid theme={null}
sequenceDiagram
    participant Page as Checkout
    participant Server as Your server
    participant Ionic as Ionic API
    Page->>Ionic: Collect card through secure Blocks fields
    Ionic-->>Page: ConfirmationToken ID and card details
    Page->>Server: Token ID
    Server->>Ionic: Retrieve token details
    Ionic-->>Server: Card summary and token status
    Server->>Server: Check order and calculate final price
    Server-->>Page: Show final total
    Page->>Server: Customer accepts total
    Server->>Ionic: Create PaymentIntent for that amount
    Ionic-->>Server: PaymentIntent ID
    Server->>Ionic: Confirm using the same token ID
    Ionic-->>Server: Payment result
```

This optional flow requires platform access enabled for your test or live mode.
It supports one-time card payments with automatic capture. For payment without
a separate review step, use the [standard Blocks integration](https://docs.ionicfi.com/guides/payment-fields.md).

## 1. Set up the card fields

On your server, create the Blocks review session. `Ionic-Account` is the
connected merchant that will receive the payment.
Register your checkout origin as a [platform payment domain](https://docs.ionicfi.com/guides/platform-payment-domains.md).

```ts theme={null}
import { Ionic } from "@ionicfi/sdk";

const server = new Ionic({ token: process.env.IONIC_PLATFORM_SECRET_KEY });
const session = await server.tokenizationSessions.create({
  "Ionic-Account": "mer_BBBBBBBBBBBBBB",
  purpose: "confirmation_token",
  currency: "usd",
  parent_origin: "https://shop.example.com",
});
```

Send the complete session response to your page. Add a mount target:

```html theme={null}
<div id="payment"></div>
```

Mount Blocks with your platform publishable key and the same connected account:

```ts theme={null}
import { loadIonic } from "@ionicfi/js";

const ionic = await loadIonic("pk_v1_test_...", {
  account: "mer_BBBBBBBBBBBBBB",
});
const blocks = ionic.blocks({ tokenizationSession: session });
await blocks.create("payment").mount("#payment");
```

You do not need a PaymentIntent yet. The session is for displaying the secure
fields; it contains no card.

## 2. Collect the card and get its token ID

When the customer selects **Review payment**, call this with their billing details:

```ts theme={null}
const result = await ionic.createConfirmationToken({
  blocks,
  billingDetails: {
    name: "Test Buyer",
    address: { postal_code: "12345", country: "US" },
  },
});
if (result.error) throw new Error(result.error.message);
if (!result.confirmationToken) throw new Error("Card preparation is unavailable.");
const confirmationToken = result.confirmationToken;
```

Send `confirmationToken.id` to your server. This is the Ionic `ct_...` ID you
will use for payment. The underlying card token stays private; the card number
and CVC are not returned to your page. No payment has happened yet.

The fields stay mounted and stop accepting edits during review. To let the
customer change the card, call `blocks.resumeCollection()`, then collect a new
token and repeat the review.

## 3. Check the card and finalize the price

Retrieve the token on your server using the same platform, account, and test/live mode:

```ts theme={null}
import { Ionic } from "@ionicfi/sdk";

async function retrievePreparedCard(id: string) {
  const server = new Ionic({ token: process.env.IONIC_PLATFORM_SECRET_KEY });
  return server.confirmationTokens.retrieve({
    id,
    "Ionic-Account": "mer_BBBBBBBBBBBBBB",
  });
}
```

The response includes `status`, `expires_at`, and `payment_method_preview.card`.
The card summary contains its brand, last four digits, funding type when known,
and how that information was obtained. See the [object reference](https://docs.ionicfi.com/api-reference/confirmation-tokens.md)
for the full response. `funding: "unknown"` means the card type is unavailable;
it does not mean the card was declined.

> [!NOTE]
>
> Server-verified funding is currently limited to supported test configurations.
> Live tokens may return unverified card-field data or unknown funding. This
> limitation concerns the funding information, not the token's role in payment.

Calculate the final total on your server, including any changes to discounts,
delivery, or other order items. In our example:

| Item | Amount |
| - | - |
| Order | \$100.00 |
| Discount | −\$10.00 |
| **Total to pay** | **\$90.00** |

Save the token ID, order version, final amount, currency, and expiry together on
your server. This is your application's review record, not an Ionic object.
Show the total and ask the customer to accept it. If it changes, show the new
total and get their acceptance again.

**Changing the price does not require a new token**, as long as the card,
billing details, account, currency, and mode are unchanged and the token is
still ready and unexpired. The token contains no amount.

## 4. Create the payment at the final amount

After acceptance, check that the order is still unpaid, the review is current,
and the token is ready and unexpired. Prevent concurrent payment attempts for
the same order, including double-clicks or a second browser tab.

Create a PaymentIntent for the accepted \$90 total. Amounts are in minor units,
so the request uses `9000`:

```bash theme={null}
curl https://api.ionicfi.com/v1/payment_intents \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Ionic-Account: mer_BBBBBBBBBBBBBB" \
  -H "Idempotency-Key: order-123-payment-1-create" \
  -H "Content-Type: application/json" \
  -d '{"amount":9000,"currency":"usd","capture_method":"automatic"}'
```

This creates the payment record; it does not charge the card. Save the returned
`pi_...` ID against the order before confirming. Reuse the creation key if you
need to retry this exact request. Do not include `confirmation_token` on creation.

Then confirm the intent with **the same `ct_...` ID you retrieved in step 3**:

```bash theme={null}
curl https://api.ionicfi.com/v1/payment_intents/pi_CCCCCCCCCCCCCC/confirm \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Ionic-Account: mer_BBBBBBBBBBBBBB" \
  -H "Idempotency-Key: order-123-payment-1-confirm" \
  -H "Content-Type: application/json" \
  -d '{"confirmation_token":"ct_AAAAAAAAAAAAAAAAAAAAAAAA"}'
```

The example IDs stand for the intent just created and the token from step 2.
**Confirmation attempts the \$90 charge.** Its response is a PaymentIntent;
`succeeded` means payment succeeded, and `processing` means the result is still
pending. See [Confirm a payment intent](https://docs.ionicfi.com/api-reference/payment-intents/confirm-a-payment-intent.md)
for response examples. Verify the outcome before fulfilling the order.

Keep the intent's client secret on your server when the price depends on the
reviewed card, so the browser cannot substitute another card at that price.
For retries after a lost response, reuse the same intent, token, and confirmation
key. See [Blocks reference](https://docs.ionicfi.com/guides/blocks-reference.md#deferred-card-preparation)
for the alternative browser confirmation call.

> [accordion] What if the price changes after I created the PaymentIntent?
>
> Confirm only an intent whose amount matches the newly accepted total. In this
> flow, create the intent after pricing is final. If an unused intent has the
> wrong amount, cancel or replace it under your order's payment guard and save
> the replacement ID. Use a new creation key for a new create request.
>
> If confirmation has already started, check that payment's outcome first.
> Do not create a replacement while the original result is unknown.

## Save the card for future payments

The customer can agree to save the card while they enter it. The same payment
then saves it to the customer, so you can charge it later, including when the
customer is not present.

Offer saving when you create the session:

```ts theme={null}
import { Ionic } from "@ionicfi/sdk";

const server = new Ionic({ token: process.env.IONIC_PLATFORM_SECRET_KEY });
const session = await server.tokenizationSessions.create({
  "Ionic-Account": "mer_BBBBBBBBBBBBBB",
  purpose: "confirmation_token",
  currency: "usd",
  parent_origin: "https://shop.example.com",
  setup_future_usage: "off_session",
});
```

Blocks then shows a save checkbox below the card fields. Creating the token
locks the customer's choice with the card; `blocks.resumeCollection()` unlocks
both. To draw your own checkbox, create the Block with
`saveConsent: "external"` and pass the customer's choice:

```ts theme={null}
await blocks.create("payment", { saveConsent: "external" }).mount("#payment");
const saved = await ionic.createConfirmationToken({
  blocks,
  billingDetails: { address: { postal_code: "12345", country: "US" } },
  savePaymentMethod: true,
});
```

When the customer agreed, the retrieved token has
`setup_future_usage: "off_session"`. Without their agreement the field is
absent and the payment does not save the card.

To save the card, create the PaymentIntent with the customer and the same
`setup_future_usage`, then confirm with the token as in step 4:

```bash theme={null}
curl https://api.ionicfi.com/v1/payment_intents \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Ionic-Account: mer_BBBBBBBBBBBBBB" \
  -H "Idempotency-Key: order-123-payment-1-create" \
  -H "Content-Type: application/json" \
  -d '{"amount":9000,"currency":"usd","capture_method":"automatic","customer":"cus_CCCCCCCCCCCCCC","setup_future_usage":"off_session"}'
```

The confirmation response adds `saved_payment_method`: the card the customer
paid with, now saved to the customer. It is `null` when the payment succeeded
but the card could not be saved.

```json theme={null}
{ "id": "pi_CCCCCCCCCCCCCC", "status": "succeeded", "saved_payment_method": "pm_DDDDDDDDDDDDDD" }
```

If the token carries the customer's agreement but the intent has no customer
or `setup_future_usage`, confirmation returns
`409 CONFIRMATION_TOKEN_SETUP_FUTURE_USAGE_MISMATCH` before charging. Create a
matching intent and confirm it with the same token. To charge the saved card
later, see [Save cards](https://docs.ionicfi.com/guides/save-cards.md).

## Token states and retries

```mermaid theme={null}
stateDiagram-v2
    [*] --> ready: Card collected
    ready --> consumed: Assigned to one payment attempt
    ready --> invalidated: Card editing resumes
    ready --> expired: Not used before expiry
    consumed --> consumed: Recover the same payment
    invalidated --> [*]
    expired --> [*]
```

A token lasts up to 10 minutes, capped by its field session's remaining lifetime.
The field session lasts 30 minutes. Once Ionic accepts the token for a payment
attempt, it becomes `consumed`. **Consumed means used, not paid.** It stays
consumed after a decline or an unknown result, and cannot start another attempt.

| What happened | What to do |
| - | - |
| Token creation returned `preparation_status_unknown` | Call `blocks.recoverConfirmationToken()` on the same fields to get that call's result. |
| The customer wants to edit an unused card | Call `blocks.resumeCollection()`. After success, discard the old review and collect a new token. |
| Resuming failed | Keep the fields locked and retry the resume call. |
| An unused token expired | Resume the fields if the session is usable; otherwise create a new session and ask for card entry again. |
| Payment timed out or is processing | Check the original PaymentIntent and Charge. Keep the same intent, token, and confirmation key for retries. |
| Payment definitively declined | Collect a new token and get a new accepted review before another attempt. |

Resuming preserves the fields while the session is usable; a page reload loses
the entered card. Store order and payment IDs on your server so a reload can
recover an existing payment. Access being turned off or a token expiring does
not prevent authorized recovery of a payment already started.

See the [error reference](https://docs.ionicfi.com/api-reference/confirmation-tokens.md#errors-and-retries)
for exact codes. This flow does not support wallets or merchant-initiated
payments, or complete authentication challenges.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.