> 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/guides/api.md).

# Exports, Events & NUI API

## Client exports

```lua
exports.vip_shop:Open()     -- open the shop
exports.vip_shop:Close()    -- close it
exports.vip_shop:IsOpen()   -- boolean
```

You can also trigger the net event from anywhere client side: `TriggerEvent('vipshop:client:openShop')`.

## Server exports

```lua
exports.vip_shop:GetCoins(source)            -- number (0 if unresolved)
exports.vip_shop:AddCoins(source, amount)    -- credit or debit; pushes a live UI update; returns boolean
exports.vip_shop:GetMembershipTier(source)   -- 'deputy' | 'marshal' | 'legend' | 'founder' | nil
```

## Server events

| Event                 | Direction          | Payload                                                                        |
| --------------------- | ------------------ | ------------------------------------------------------------------------------ |
| `vipshop:orderPlaced` | fired by vip\_shop | `(src, { id, order, product })`. Hook your queue, pet or shop automation here. |

## NUI protocol

Useful if you fork the UI or need to drive it from custom logic.

From Lua to the NUI (`SendNUIMessage`):

| `action`        | `data`                                                   |
| --------------- | -------------------------------------------------------- |
| `open`          | `{ balance, playerName, tebexToken, membership }`        |
| `setBalance`    | `number`                                                 |
| `setMembership` | `{ tier, label, discount, renewsAt, lifetime }` or `nil` |
| `close`         | none                                                     |

From the NUI to Lua (`RegisterNUICallback`, all proxied to the server RPC):

| Callback                | Body                                   | Server response                          |
| ----------------------- | -------------------------------------- | ---------------------------------------- |
| `close`                 | none                                   | `{ ok }`                                 |
| `getCatalog`            | none                                   | `Product[]` with delivery specs stripped |
| `purchase`              | `{ productId, quantity }`              | `{ ok, balance?, message?, discount? }`  |
| `redeem`                | `{ code }`                             | `{ ok, coins?, balance?, message? }`     |
| `tebex:paymentComplete` | `{ basketIdent, packageId, quantity }` | `{ ok }`, logging only                   |

## RPC transport

Client and server communicate over a small request and response bridge:

```
NUI callback -> TriggerServerEvent('vipshop:server:rpc', name, reqId, data)
             <- TriggerClientEvent('vipshop:client:rpcResponse', src, reqId, result)
```

Handlers are pcall wrapped on the server; a thrown error returns a localized failure instead of hanging the UI.
