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

# Checkout

> Create a checkout session from your backend and let the customer buy on one page, with address, payment method and confirmation.

A checkout session is a buying opportunity with its own address. Your backend decides what is being bought and receives a finished URL. Everything else, so email, address, tax context, payment method and confirmation, is handled by the page.

For recurring offers maintained in your catalogue there are also [checkout links](https://docs.fynn.eu/en/guide/checkout/checkout-links.md). The difference: a checkout link is a named offer you hand out many times, a session covers a single purchase.

## Creating a session

```bash theme={null}
POST /api/checkout/sessions
```

```json theme={null}
{
  "mode": "subscription",
  "lineItems": [
    { "priceId": "01a05808-bf3a-7f58-8052-0dcdf87f9d37", "quantity": 2 }
  ],
  "successUrl": "https://demo-acme.example/thanks",
  "cancelUrl": "https://demo-acme.example/cancelled",
  "metadata": { "orderRef": "NIGHT-1" }
}
```

The response carries the URL of the page:

```json theme={null}
{
  "id": "01a0c19c-d33e-7be4-a64a-9682226692e3",
  "status": "open",
  "mode": "subscription",
  "url": "https://demo-acme.customerfront.app/checkout/01a0c19c-d33e-7be4-a64a-9682226692e3#secret=…",
  "expiresAt": "2026-09-22T01:37:55+00:00",
  "amountTotal": 4900,
  "currency": "EUR"
}
```

Instead of single prices you can sell a plan tier:

```json theme={null}
{ "lineItems": [ { "tierId": "01a05808-e014-71b1-8b6a-804788b6cdbe" } ] }
```

Quantities of individual items of the tier are overridden through `quantities`, and a quantity of `0` leaves the item out.

`mode` has two values: `subscription` for a contract and `payment` for a one-off purchase. If a customer should only store a payment method without buying anything, use the [payment link](https://docs.fynn.eu/en/guide/customer-portal/payment-methods.md#collecting-a-payment-method-by-link).

> [!TIP]
>
> `metadata` travels unchanged into the `checkout.session.completed` event. Put your own reference there and you will not have to look anything up when it arrives.

## The access to the page

The address in `url` carries the access to the cart behind the hash:

```
https://<your channel domain>/checkout/<id>#secret=<clientSecret>
```

Whatever stands behind the hash stays in the browser and is never sent to a server. That is exactly why the access sits there and not in the query: it lands in no server log and in no referrer.

The page takes it out of the address bar on the first render and keeps it for the reload and for the return from a payment provider. Every call to Fynn then carries it in the `X-Checkout-Client-Secret` header.

> [!WARNING]
>
> Pass on the address from `url` unchanged, including everything behind the hash. Without that access the cart of a session answers `404 CART__NOT_FOUND`, exactly as it does for an unknown id. A wrong access and a wrong id are indistinguishable from outside, and that is deliberate.

If you open the page from your own application in a new tab, you can append the value as `?client_secret=` when reading the session (`GET /public/checkout/sessions/{id}`) instead.

A cart from a [checkout link](https://docs.fynn.eu/en/guide/checkout/checkout-links.md) has no such access and is read without one, because the link itself is the offer.

## The page

![Checkout page with the summary on the left and the form for email, payment method and address on the right](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-start.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=759d9c18c58966bf77878ed951345f61)

Summary on the left, form on the right.

On the left are the package, the items, the term, the notice period, **Subtotal** and **Due today**. On the right the customer fills in email address, payment method and billing address and confirms with **Place binding order**. Whether the amounts read net with VAT stated separately or gross is decided by the setting of your sales channel.

A business buyer opens **Order as a company** for the company fields, the **VAT ID** and the **Cost centre**. For the address the page suggests matching entries, provided the address search is set up. Without it the same fields are there to be filled in.

Every change is recalculated on the server, the country as well as the quantity. The cost centre and the VAT id travel with the address into the customer record, even for a customer created by this purchase.

On offer are the payment methods this channel may complete a purchase with. Pay by invoice is among them where you allow it, and it appears exactly once. What can be stored on the customer permanently is a different question: pay by invoice is not stored, it applies to this purchase.

![Completed checkout page with address, IBAN and recognized bank](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-ausgefuellt.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=55d91ad24492a33de7a0afdd55544816)

A completed form with the bank recognized from the IBAN.

![Checkout page on a phone](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-mobil.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=9adc479911e5fdeec8d6c228c3deb341)

The checkout on a phone.

## VAT before the address is known

The cart is fully priced from the first second, even when nobody has said where the buyer sits. The country from your company data stands in for it, and the result is marked as estimated. The customer therefore never sees a total without tax and never experiences a jump while filling in the address that nobody explains.

Which country applies is decided by the first step of this order that yields something:

1. `?countryCode=` or `?vatId=` when reading the cart
2. the billing address on the cart
3. the country picked through `PUT .../change-country-code`
4. the country of a customer already known
5. the country of the VAT id given, when there is no address
6. the country from your company data

What is returned is one line per tax rate with net, tax amount and rate, plus net and gross per billing interval and the rate per item. The same cart, read three times:

| Input | Result |
| - | - |
| nothing given, no address | EUR 177.31 gross, shown as **VAT (estimated, DE)** with the note **Final once the address is known.** |
| country `DE` in the query | the same amounts, still marked as an estimate |
| a German billing address on the cart | the same amounts, without the marking |
| VAT ID `ATU12345678` | EUR 149.00 and **Reverse charge: the recipient owes the VAT.** |

### The tax country is only final from the billing address

The order above decides which figure the page shows. It does not decide which figure may be charged. A country is final only when somebody recorded it: the billing address on the cart, or the customer already known. Everything else, including a country the buyer types into the query themselves, stays an estimate.

> [!WARNING]
>
> That is why the card element mounts after the address step. While the cart carries no billing address, `PUT /public/checkout/cart/{id}/prepare-stripe` answers `422 CART__TAX_CONTEXT_REQUIRED`. Before this, a payment for the net amount was prepared in that case, while the invoice afterwards added the tax.

`prepare-stripe` does not read `?countryCode=` or `?vatId=`. The amount comes from the cart. What the buyer enters in the address step therefore has to land on the cart, not only on the payment preparation.

> [!NOTE]
>
> The estimate is a display aid and is never charged. What is charged is always the tax belonging to the address on the invoice.

## Delivery address

If you have enabled delivery addresses, the checkout also asks for a **Delivery address**, and a known customer picks from their stored addresses. A delivery address can equally be the place where a service is rendered, so it does not presuppose physical goods.

## Existing customers

If the customer enters an email address you already know, Fynn sends them a confirmation code. After entering it, their stored payment methods appear with the default preselected, and the address fields are dropped.

![Checkout for an existing customer with stored payment methods and billing address](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-bestehender-kunde.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=88a332ec7bba72934f9ec078bf000fce)

A known customer: stored payment methods instead of a form.

If the purchase should not run on that account after all, for instance because someone is ordering for another company, **Use a different account** releases the cart from the customer again:

```bash theme={null}
POST /public/checkout/cart/{id}/release-customer
```

The items stay, the customer and everything hanging off them is cleared: addresses and stored payment methods. The cart is a guest cart again afterwards. Once the order is placed this is no longer possible.

## B2B direct debit: sign first, then order

When a customer confirms the checkout with a SEPA B2B direct debit, no live order is created yet. The confirmation answers with a `nextAction` of type `sign_mandate` and the address of the signing page, and the cart sits in `awaiting_mandate`. Nothing is activated and nothing is collected. Signing happens on your page, under your brand.

> [!NOTE]
>
> Until the signature is in, there is a mandate but not yet a payment method. The answer to the confirmation therefore names the id of the mandate and its stage, not that of a payment method.

The customer goes straight into the signature and from there into the registration with their bank. Only once the mandate is signed and registered does the order proceed. What the customer meets on the way is described under [Payment methods and SEPA mandates](https://docs.fynn.eu/en/guide/customer-portal/payment-methods.md#core-or-b2b-mandate).

## After the purchase

![Confirmation page stating that the order has been received](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-abgeschlossen.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=3bbb8abe7d110423d35393b11c071257)

The confirmation after the purchase.

The customer lands on **Order received** with **Order number**, **Payment method** and **Next step**, and from there, through **To the customer area**, on your `successUrl`. On the server the customer, the payment method and the order are created. As soon as the subscription exists, the session carries its id.

Once the session is complete it also carries its outcome in `result`: order number, items, the totals of net, tax and gross, the payment method chosen, the customer's email address and the address of their portal. That is enough to build your own thank-you page without further calls. Before completion `result` is empty.

`result.nextStep` names what the customer can expect next:

| `nextStep` | Meaning |
| - | - |
| `sepa_first_debit` | The first SEPA direct debit collection is ahead. |
| `bank_transfer` | The customer transfers the money themselves. |
| `none` | Nothing is outstanding. |

> [!WARNING]
>
> The amounts in `result` are in the smallest currency unit, so in cents. The cart states its amounts as decimals. Do not compare the two without converting.

For your own processes, rely on the event rather than on the browser coming back. A customer closes a tab, a network drops, a webhook does not.

| Event | When |
| - | - |
| `checkout.session.completed` | The purchase is complete. |
| `checkout.session.expired` | The session was ended. |

## Discarding the cart

A customer who changes their mind picks **Discard basket**. The action is on the page when it was opened through the address from the session, because only then does the page hold the access for it. The session is expired afterwards and the page shows its expired state.

You can end a session just as well, for instance when the customer abandons in your application:

```bash theme={null}
POST /public/checkout/sessions/{id}/expire
```

Without activity a session expires by itself after 24 hours. Repeating the call does no harm. A purchase that is already complete cannot be declared expired afterwards.

![Checkout page stating that the session has expired](https://mintcdn.com/fynnsubscriptionbilling/tv50Rqhs2iBwmkcc/images/customer-portal/checkout-abgelaufen.png?fit=max\&auto=format\&n=tv50Rqhs2iBwmkcc\&q=85\&s=82ae12446b42810d793256a3b8e557d1)

An expired session.

## Coupons

The checkout offers a coupon field when the underlying cart allows it. That is the case for [checkout links](https://docs.fynn.eu/en/guide/checkout/checkout-links.md) today, whose setting you maintain per sales channel.

The full fields, the steps of the cart and the error codes are in the [API reference](https://docs.fynn.eu/v2-customer-api/checkout-sessions.md).
