> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/vip-shop/tebex-integration/checkout-flow.md).

# How In-Game Checkout Works

## The flow

1. When the shop opens, the UI calls the Tebex Headless API with your public token and pulls every package from the recognized categories (`Coins`, `Passes` and so on). Live prices, images, discounts and your store currency all come from Tebex.
2. When the player presses "Buy Now, Tebex Checkout":
   * a basket is created (`POST /accounts/{token}/baskets`),
   * the package is added (`POST /baskets/{ident}/packages`),
   * Tebex's checkout opens as a themed window inside the game's NUI. No browser, no alt tabbing. Card entry, 3D Secure and PayPal all run inside that frame.
3. On `payment:complete` the UI shows a success toast and notifies the server (`tebex:paymentComplete`), which is used only for logging.
4. Tebex then executes the package's delivery commands on your server through the game server integration (`sv_tebexSecret`). This is what actually credits coins or memberships.

## The golden rule

{% hint style="danger" %}
Never deliver goods from the UI payment event. The `payment:complete` callback is a UX signal. The authoritative delivery channel is Tebex's server side package commands, optionally verified further with Tebex webhooks. This resource follows that rule out of the box.
{% endhint %}

## Failure and edge handling

| Case                                 | Behavior                                                                                                                                                                                                                       |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Store unreachable or bad token       | A "TEBEX UNREACHABLE" toast appears and the shop falls back to the built in demo catalog                                                                                                                                       |
| Empty store                          | Toast, demo catalog remains                                                                                                                                                                                                    |
| Payment declined                     | The Tebex window shows the error and the shop confirms that no money was taken                                                                                                                                                 |
| Player closes the checkout window    | Basket abandoned, nothing charged                                                                                                                                                                                              |
| ESC while checkout is open           | Handled by Tebex; the shop stays open underneath                                                                                                                                                                               |
| CFX type store detected (login wall) | In a browser preview the Cfx.re sign in opens in a tab and checkout resumes automatically. In game you should be running a Universal store; see [Store Setup](/script-documentation/vip-shop/tebex-integration/store-setup.md) |

## Coin purchases (no Tebex involved)

Everything priced in coins, such as weapons, horses and packages, is a pure server transaction:

1. The UI sends `purchase { productId, quantity }`.
2. The server looks the product up in its own config (client prices are ignored), checks inventory capacity, applies the membership discount, deducts the balance atomically, delivers, logs, and returns the new balance.
3. If anything fails before delivery, no coins are taken.
