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

# Card-on-file Charges

> Charge a customer's saved card again for top-ups, any amount you choose, without sending them back to checkout.

## What are Card-on-file Charges?

Card-on-file charges let you charge a customer again on the card they already paid with. The customer buys once through a normal Creem checkout, their card is saved, and from then on your app can charge it with one API call.

You decide when to charge and how much. Use it to top up a credit balance when it runs low, to sell an extra pack from inside your app, or to charge for a one-off add-on.

> [card] [Auto top-ups](https://docs.creem.io/features/customer-credits/auto-refill.md#auto-top-ups)
>
> Refill a customer's credits when their balance drops below a threshold you set in the dashboard,
> or trigger each top-up from your app.

> [card] One-click purchases
>
> Let a customer buy more credits or an add-on with one click, without typing their card details
> again.

Every charge is a full Creem order. Tax, invoices, receipts, fraud checks, payouts and refunds work exactly as they do for a checkout payment.

## When can you charge a customer?

A charge works only when all of these are true:

1. **Card-on-file charges are enabled for your store.** The feature is available on request. Contact [support@creem.io](mailto:support@creem.io) to turn it on.
2. **The product has Auto top-ups switched on.** It must be a one-time product with a fixed price. Subscriptions, pay what you want and usage pricing can't use it.
3. **The customer has a card on file for that store.** They paid for an Auto top-ups product through a Creem checkout with a card, and saw the notice above the Pay button.
4. **The customer hasn't stopped it.** Charges stop when the customer asks Creem to stop them, when the card is replaced or can no longer be used, or when the customer's data is erased.

> [!WARNING]
>
> Cards saved by a subscription checkout can't be charged yet. Today, a card is on file only after
> the customer pays for a one-time product with Auto top-ups switched on.

## How it works

```mermaid theme={null}
sequenceDiagram
    participant Customer
    participant App as Your App
    participant Creem as Creem API

    Customer->>Creem: Pays for an Auto top-ups product at checkout
    Creem-->>Customer: Card saved behind the checkout notice
    App->>Creem: POST /v1/customers/{customer_id}/charge
    Creem-->>App: 201 charged (order paid, credits granted)
```

## Set it up

**1. Switch on Auto top-ups for a product**

In the dashboard, open **Products**, create or edit a one-time product with a fixed price, and
switch on **Auto top-ups** in the Pricing section.

![The Auto top-ups switch in the Pricing section of the product form](https://mintcdn.com/creem/tmX-7pI4DA2h3sC4/images/card-on-file-charges/dashboard-auto-top-ups-switch.png?fit=max\&auto=format\&n=tmX-7pI4DA2h3sC4\&q=85\&s=1e129c11ef626b8bf8cb20647adfe025)

Through the API, send `top_ups_enabled: true` when you create or update the product.

**2. Sell the product once through checkout**

Send the customer to a normal checkout for that product. Above the Pay button, Creem shows one
line with your store's name, for example:

> By paying, you allow Acme to save this card and charge it later for top-ups. To stop, contact [support@creem.io](mailto:support@creem.io).

When the customer pays by card, the card is saved for your store. Free orders save nothing.

**3. Charge the card from your app**

Call [Charge a customer](https://docs.creem.io/api-reference/charge-customer.md) with the customer ID, the product, the
currency and the amount. Creem adds tax, charges the saved card, and answers with the result.

## Charge a customer

Send the amount before tax, in the smallest currency unit. `2000` is \$20.00. Every request needs an `Idempotency-Key` header, so a retried request never charges twice.

```typescript TypeScript theme={null}
const response = await fetch(`https://api.creem.io/v1/customers/${customerId}/charge`, {
  method: "POST",
  headers: {
    "x-api-key": process.env.CREEM_API_KEY!,
    "Content-Type": "application/json",
    "Idempotency-Key": `topup_${customerId}_${Date.now()}`,
  },
  body: JSON.stringify({
    product_id: "prod_topups",
    currency: "USD",
    amount: 2000,
    credits: { amount: "2000" },
  }),
});

const charge = await response.json();
// 201: charged, 402: not charged, 202: still processing
```

```bash API theme={null}
curl -X POST https://api.creem.io/v1/customers/cust_123/charge \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: topup_cust_123_0001" \
  -d '{
    "product_id": "prod_topups",
    "currency": "USD",
    "amount": 2000,
    "credits": { "amount": "2000" }
  }'
```

* **The amount is yours to set.** Any amount from 100 (1.00 in the currency) upwards, within the limits below. The currency must be the currency of the product's price.
* **Tax is added on top.** Creem calculates it from the billing address of the checkout where the card was saved, the same way it taxes a checkout payment.
* **Credits follow the amount.** If the product delivers credits, pass `credits` to grant the number of credits this charge pays for. It replaces the product's fixed credit grant for this charge. It is required when you charge a credits product at an amount other than its price. Add `account_id` to grant into a specific credits account.

See the [API reference](https://docs.creem.io/api-reference/charge-customer.md) for every field, response and error.

## The result

| Status | State | What it means |
| - | - | - |
| `201` | `charged` | The card was charged. The order is paid and any credits are granted. |
| `402` | `declined` or `expired` | Nothing was charged. `decline_category` says why. |
| `202` | `reserved`, `charging` or `needs_attention` | The payment is still processing, for example while the bank confirms it. Creem settles it and sends a webhook. |

A `202` charge settles on its own. Follow it with [Get a card-on-file charge](https://docs.creem.io/api-reference/charge-customer.md#get-a-card-on-file-charge) or wait for the webhook.

## Webhooks

| Event | When |
| - | - |
| `checkout.completed` | The charge succeeded. Like any paid order, it carries the order and the customer. |
| `credits.granted` | The charge granted credits. |
| `saved_card_charge.failed` | A charge ended without money moving: the card declined it, or it could no longer go through. |
| `saved_card_consent.revoked` | You can no longer charge the customer's saved card: they stopped it, the card can no longer be used, their data was erased, or a newer card replaced it. |

## Limits and declines

Creem caps card-on-file charges to protect your customers and your store:

* **Per charge**, **per customer per calendar month (UTC)** and **per store in any 24 hours**, all including tax. A charge over a limit is refused before the card is touched. Contact [support@creem.io](mailto:support@creem.io) to learn your store's limits or to change them.
* **Repeated declines pause a card.** After 5 declines in 24 hours, or 15 in 30 days, new charges on that card are refused with `reattempt_limit` until the window passes.
* **Some declines end a card for good.** When the bank says the card must never be charged again (for example a lost, stolen or closed card), further charges are refused with `card_do_not_retry`. Send the customer a new checkout to save a new card.
* **Creem never retries a declined charge.** Your app decides whether and when to try again.

## Good to know

* **One card per customer per store.** When a customer pays for an Auto top-ups product again, the newer card replaces the old one for your store.
* **Refunds work as usual.** A charge is an order, so you refund it from the dashboard or the API. A full refund also takes back the credits it granted.
* **Customers can stop charges.** Today they do so by contacting [support@creem.io](mailto:support@creem.io), as the checkout notice says.

## Related

> [card] [Auto-refill](https://docs.creem.io/features/customer-credits/auto-refill.md)
>
> Refill a customer's credits automatically when their balance runs low

> [card] [Charge a customer](https://docs.creem.io/api-reference/charge-customer.md)
>
> Every field, response and error of the charge endpoint

> [card] [Customer Credits](https://docs.creem.io/features/customer-credits/introduction.md)
>
> Give customers a balance of credits to spend in your app

> [card] [One-time Payments](https://docs.creem.io/features/one-time-payment.md)
>
> The products and checkouts card-on-file charges start from


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