> For the complete documentation index, see [llms.txt](https://sbscripts.gitbook.io/sb-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sbscripts.gitbook.io/sb-scripts/sb-vip/tebex-setup.md).

# Tebex Setup

### Step 1: Get your secret key

1. Log in to your Tebex creator panel.
2. Go to **Integrations > Game Servers**.
3. Copy the **secret key** for your FiveM server.
4. Paste it into `server.cfg`:

```cfg
set sv_tebexSecret "your-tebex-secret-key"
```

5. Restart the server. It should now show as connected in Tebex.

### Step 2: Create your packages

Create a Tebex package for each token bundle you want to sell, for example Lead ($5), Iron ($15), Gold ($35) and Diamond ($80). The names can be anything, but you'll need the **exact same names** in game.

### Step 3: Add the game server command

For **every** package:

1. Open the package and go to **Game Server Commands**.
2. Add a command that runs **when the package is purchased**.
3. Select your server.
4. Turn off "require player to be online", so it runs even if the player is offline.
5. Paste this command exactly:

```
sbvip_purchase {transaction}|{packageName}|{price}|{email}|{time}|{date}|{packageId}|{packagePrice}
```

> 💡 The admin panel shows this command with a **Copy command** button.

Every purchase is now saved to your database, waiting to be redeemed.

### Adding packages in game

1. Type `/vipadmin` and open the **Tebex packages** tab.
2. Click **New package**.
3. Enter the exact Tebex package name (capitals don't matter) and the number of VIP tokens it gives.
4. Save.

* You can't add the same package name twice.
* If someone buys a package you haven't set up, it appears under **Bought on Tebex but not set up**. Click **Set up** to fill in the name. The buyer still gets their tokens when they redeem.
* Changing a package's token amount only affects new purchases.
* Buying several packages in one checkout adds them together.
* Each payment is checked against Tebex. If Tebex sends the same package twice, or it arrives after the ID was already redeemed, the extra copy is ignored and logged.

### How players redeem tokens

1. The player buys a package on your Tebex store.
2. Tebex emails them a receipt with a transaction ID starting with `tbx-`.
3. In game, they open the shop and paste the ID into **Redeem A Tebex Purchase**.
4. They press **Enter** or the check button, and the tokens are added straight away.

Each transaction ID can only be redeemed once. If the purchase hasn't reached the server yet, the script looks it up on Tebex using `sv_tebexSecret`. Players can try once every 2 seconds, and after 5 wrong codes in a minute they must wait 60 seconds. Token balances are stored per FiveM licence, so they carry over between characters.
