# Save cards and charge later
Source: https://docs.zahlo.eu/guides/save-cards

Save a card when the customer pays, or without a charge, then charge it off-session: for orders placed by phone, top-ups, or usage billed after the fact. Subscriptions save their card on their own; you don't need this for them.

<Warning>
Before you save a card, show the customer your terms for later charges: when you'll charge, what for, and how much or how it's calculated. Asking Zahlo to save the card is your statement that the customer agreed. Zahlo records the checkout session and time as the consent record.
</Warning>

## Save a card at checkout

Create the customer first, then pass `customerId` and `setupFutureUsage: "off_session"` on a `payment` session. Cards only: send `paymentMethodTypes: ["card"]` or leave it out.

```javascript
const session = await fetch("https://merchant.zahlo.eu/api/v1/checkout-sessions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.ZAHLO_API_KEY,
    "Idempotency-Key": "order-1001-checkout",
  },
  body: JSON.stringify({
    amountMinor: 4990,
    currency: "EUR",
    customerId: "cus_0a1b2c3d4e5f60718293a4b5",
    setupFutureUsage: "off_session",
    successUrl: "https://shop.example.com/thanks?session={CHECKOUT_SESSION_ID}",
  }),
}).then((r) => r.json());
```

To save a card without charging, create a session with `type: "setup"` and `customerId`, and no `lineItems` or `amountMinor`. The customer confirms their card for a zero amount, and the session completes with `paymentStatus: "no_payment_required"`.

When the session completes, the card becomes the customer's payment method. Within a few minutes you receive `payment_method.attached` with the brand, last four digits and expiry; its `checkoutSessionId` names the session that saved it. List a customer's cards with `GET /api/v1/customers/{id}/payment-methods`.

## Charge a saved card

```javascript
const response = await fetch("https://merchant.zahlo.eu/api/v1/payments", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.ZAHLO_API_KEY,
    "Idempotency-Key": "order-1002-charge",
  },
  body: JSON.stringify({
    customerId: "cus_0a1b2c3d4e5f60718293a4b5",
    paymentMethodId: "pm_0a1b2c3d4e5f60718293a4b5",
    amountMinor: 1990,
    currency: "EUR",
    reference: "Order 1002",
    offSession: true,
  }),
});
```

`Idempotency-Key` is required: retry with the same key and you get the same payment, never a second charge.

| Response | Meaning | What to do |
| --- | --- | --- |
| `201` Payment, `status: "succeeded"` | Charged | Fulfil the order; `payment.confirmed` follows |
| `202` Payment, `status: "pending"` | The outcome isn't known yet | Wait for `payment.confirmed` or `payment.failed` |
| `402` `card_declined` | The issuer refused | Ask the customer for another card in a checkout session |
| `402` `authentication_required` | The issuer wants the customer present | Bring the customer back to a checkout session |
| `404` `resource_missing` | The card isn't this customer's, or was detached | Don't retry |
| `429` `rate_limited` | More than 10 off-session charges for this customer in an hour | Retry later |

Off-session charges run your [fraud rules](/guides/fraud) like any other payment.

## Detach a card

`DELETE /api/v1/customers/{id}/payment-methods/{paymentMethodId}` detaches the card: it disappears from the list and can no longer be charged. You receive `payment_method.detached`. Detach a card when the customer removes it or withdraws consent.
