# Yolfi Checkout Session API (https://talivia.com/docs/revenue-guides/yolfi/checkout-session)



Complete the [Yolfi connection setup](https://talivia.com/docs/revenue-guides/yolfi#connect-yolfi) before
continuing.

Use this guide only when your backend creates a Checkout Session. If you created a reusable link
in the Yolfi dashboard, follow the [Payment Links guide](https://talivia.com/docs/revenue-guides/yolfi/payment-link-on-your-site).

## Create the Yolfi Checkout Session [#create-the-yolfi-checkout-session]

Keep your Yolfi API key on the backend. Set `successUrl` with the literal
`{CHECKOUT_SESSION_ID}` placeholder:

```javascript title="Create a Yolfi Checkout Session"
const checkout = await fetch('https://app.yolfi.com/api/checkout-sessions', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.YOLFI_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    paylinkId: process.env.YOLFI_PAYLINK_ID,
    successUrl: 'https://your-site.com/thanks?session_id={CHECKOUT_SESSION_ID}',
  }),
}).then(response => response.json());

return Response.json({ url: checkout.data.url });
```

Send the customer to `checkout.data.url`. After payment, Talivia reads `session_id` from the
return page and matches the payment automatically. No Talivia metadata is required.

For subscriptions, use the same `successUrl` for the first checkout. Renewals are connected to
the original payment automatically.

See [Yolfi Checkout Sessions](https://docs.yolfi.com/en/paylinks/checkout-sessions) for the full
request and response schema.
