# Tebex VIP Tiers

> Set up VIP purchases, upgrades, paid renewal bonuses and payment removal in Coinsystem V2.

Use the subscription commands below to grant VIP benefits and protect coin rewards from upgrades.
**The first purchase and each paid renewal grant the configured monthlyCoins bonus once.
Upgrades grant VIP benefits without coins.**

Tebex runs purchase deliverables again when a customer upgrades, even though the upgrade payment
only covers the remaining billing period. Tiered categories also execute deliverables for lower
tiers. These are documented [Tebex tier behaviors](https://docs.tebex.io/creators/tebex-control-panel/how-to-create-packages/tiered-categories).
Coinsystem identifies a first purchase by the inherited purchase command for the lowest paid tier.
Upgrades only deliver newly added tiers, so they do not qualify for a coin reward.

## Prepare the server

1. Install the updated `sky_coinsystem` resource and its current Sky Base dependency. Keep your
existing configuration and database. Restart Coinsystem so its automatic database migration runs.
2. Use **oxmysql** as Sky Base's SQL provider. Subscription claims and removal use database
transactions; mysql-async is not supported for these commands.
3. Enable `Config.VIP.enabled`. Define the exact tier IDs and `monthlyCoins` in `config/config.lua`.
List tiers from lowest to highest. The label and displayed `price` are not payment verification.
4. Connect the intended game server using the [Tebex setup guide](/docs/scripts/coinsystem/tebex).

## Create the tiered category

In Tebex, open **Packages → Add New → Category** and enable **Tiers**. Add your Bronze, Silver and
Gold packages in ascending order. Use the same billing cycle for every tier and limit subscription
quantity to one. Match that order to `Config.VIP.tiers`.

![](/docs/coinsystem/tier-category.webp)

## Configure every tier package

Open the package's **Game Server Commands**, select your intended server, and add the following
commands. Replace `gold` with that package's configured tier ID. Keep `{transaction}` as written.

<table>
<thead>
  <tr>
    <th>
      Tebex execution event
    </th>
    
    <th>
      Command
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      When the package is purchased
    </td>
    
    <td>
      <code>
        savevipsubscriptioncode {transaction} gold 30
      </code>
    </td>
    
    <td>
      Records a first purchase with coins, or an upgrade without coins.
    </td>
  </tr>
  
  <tr>
    <td>
      When the subscription renews
    </td>
    
    <td>
      <code>
        saveviprenewalcode {transaction} gold 30
      </code>
    </td>
    
    <td>
      Records a paid renewal with the tier's coin bonus.
    </td>
  </tr>
  
  <tr>
    <td>
      When the package is removed / expires
    </td>
    
    <td>
      <code>
        removevipredeemcode {transaction}
      </code>
    </td>
    
    <td>
      Blocks that payment's code and removes the membership activated by it.
    </td>
  </tr>
  
  <tr>
    <td>
      Refund
    </td>
    
    <td>
      <code>
        removevipredeemcode {transaction}
      </code>
    </td>
    
    <td>
      Revokes that payment's pending or active VIP delivery.
    </td>
  </tr>
  
  <tr>
    <td>
      Chargeback
    </td>
    
    <td>
      <code>
        removevipredeemcode {transaction}
      </code>
    </td>
    
    <td>
      Revokes that payment's pending or active VIP delivery.
    </td>
  </tr>
</tbody>
</table>

Allow **all these commands to execute while the player is offline**, with no artificial delay.
They run in the server console; players cannot execute the delivery or removal commands in-game.
See [Tebex command types and variables](https://docs.tebex.io/creators/command-management/an-introduction-to-commands).

The purchase command must be configured on **every tier, including the lowest paid tier**. Its
inherited delivery is required to identify a first purchase, including a direct Gold purchase.

![](/docs/coinsystem/command-vip.webp)

The optional final number is the membership period in **days**, from 1 to 366; it defaults to 30.
Use the same period on every tier and on both delivery events. A day count is a fixed duration,
not a calendar-month calculation. Tebex's package-removal command is needed to end benefits at
the actual subscription expiry, including cancellation after an upgrade.

<warning>

Replace the old `savevipredeemcode` purchase and renewal commands on **every** tier. Remove any
`saveredeemcode` or `givecoins` commands that award coins on VIP purchases or upgrades, including
global commands. The protected subscription commands handle both first-purchase and renewal bonuses.
The original `savevipredeemcode` and manual `genvipcode` behavior remains available for existing
manual-code workflows; those commands do not apply this subscription policy.

</warning>

## What players receive

Players enter the payment ID in the shop's existing code field after a purchase or renewal.
The field must be enabled with `Config.Menu.showRedeemCode = true`.

- **First purchase:** VIP benefits until the recorded payment period ends and the highest delivered
tier's configured `monthlyCoins` bonus, once.
- **Upgrade:** the higher tier's benefits; zero coins. An active membership keeps its existing
expiry instead of starting another full period.
- **Paid renewal:** a fresh payment period and the configured `monthlyCoins` bonus, once per payment.
- **Cancellation without another renewal:** no new coin reward. Configure removal at the end of
the paid period; cancelling automatic renewal does not mean refunding the already paid period.

The period starts when the server records the Tebex delivery, rather than when the player claims
the code. Expired or removed payments cannot be claimed later to restart their membership.
Claim payments in billing order: an older payment cannot replace a newer active membership.
Wait for Tebex's tier commands to finish before claiming. An upgrade requires an active membership:
claim the original purchase first. Waiting for the old membership to expire does not turn an upgrade
into a first purchase.

Cumulative tier commands select the highest delivered tier for a payment. They do not add Bronze,
Silver and Gold bonuses together. If another tier command arrives after the code was claimed,
only the same character/account can claim the remaining tier change; a first purchase or renewal pays
only any missing bonus difference. An upgrade never pays a bonus difference. Repeated delivery commands
do not recreate an already claimed reward,
including after a resource restart.

Removal applies to the supplied payment ID. It also works after the player has claimed that code,
including while offline, and updates an open shop when the player is connected. An older payment's
removal does not remove VIP activated by a newer payment. Already awarded coins are not deducted.

## Update an existing store

Replace the commands before resuming sales. Existing manual VIP codes and memberships remain
available; the new command policy applies to payments recorded with the new commands. A membership
claimed through an old command has no payment-removal link and cannot be retrospectively matched
to its transaction. Audit any previously excessive rewards separately.

Keep the `coinsystem_vip_deliveries` table when updating or restoring the resource: it retains
claim and removal history. Deleting it loses replay protection. Do not resend old purchases with
the new commands to migrate them; that would create a new delivery record.

Receipts recorded before first-purchase bonuses were added do not retain the information needed to
distinguish a full first purchase from an upgrade. Review and compensate any missing first-purchase
coins separately; the update does not automatically credit already claimed payments.

## Test before accepting purchases

Use Tebex's **Payments → Create Payment** manual test feature, without spending real money.

1. Create a first-purchase test payment, including a direct Gold purchase. After its tier commands
finish, claim it: the expected tier appears and only that tier's configured bonus is added once.
2. Upgrade with only a few days remaining. Claim the upgrade: the tier changes, coins stay unchanged,
and the existing expiry stays the same.
3. Test a renewal event. Claim its payment ID: the highest tier's configured bonus is added once.
4. Resend the same commands and restart Coinsystem. Reclaiming the payment must not award coins again.
5. Test package removal before claiming, then after claiming and while the player is offline.
The old code must stay blocked and the matching membership must end.
6. Activate a newer paid membership, then remove an older payment. The newer membership must remain.

Tebex manual payments may not simulate every subscription lifecycle event. Verify the intended
purchase, renewal and removal event in the command history before interpreting each result.
