# purchase

The script does not process payments directly. Instead, it collects and logs purchase intent so staff can handle the transaction manually via a Discord ticket.

## Player Flow

1. Player selects a vehicle and clicks **Purchase VIP**.
2. A popup appears inside the UI showing the vehicle name and a prompt to open a Discord ticket.
3. A notification is sent to the player (`Config.Notify.purchaseRequest`).
4. The server event `vipshowroom:purchaseRequest` fires with the car data.

## Server-Side Logging

When the server event fires, `server.lua` does two things:

### Console Log

If `Config.LogPurchases = true`, the following is printed:

```lua
[VIPShowroom] Purchase Request | Player: John Doe (ABC123) | Vehicle: Urus (1016urus) | Category: Super
```

### Discord Webhook

If `Config.DiscordWebhook` is set to a valid URL, an embed is posted to that channel containing:

* Player name
* CitizenID / identifier
* Steam ID
* Vehicle name, model, and category
* Timestamp

## Configuration

| Key                       | Description                                 |
| ------------------------- | ------------------------------------------- |
| `Config.DiscordLink`      | Shown in the in-game purchase popup         |
| `Config.DiscordTicketMsg` | Prefix text for the player notification     |
| `Config.LogPurchases`     | Enable/disable server console logging       |
| `Config.DiscordWebhook`   | Full Discord webhook URL (empty = disabled) |
| `Config.WebhookBotName`   | Name shown as the webhook bot in Discord    |
| `Config.WebhookColor`     | Embed accent color as a decimal integer     |

## Security

The server validates incoming `carData` before processing:

* Checks that the player exists on the server.
* Rejects the event if `carData` is not a table or if `name`/`model` fields are not strings.
* Does not trust client-provided data for any economy action — all financial logic must be implemented server-side by the developer.

## Extending with Real Payments

To add economy (e.g. QBCore money check), edit the `vipshowroom:purchaseRequest` handler in `server.lua`:

```lua
-- Example: check QBCore bank balance
local Player = CoreObject.Functions.GetPlayer(src)
local balance = Player.PlayerData.money['bank']
if balance < vehiclePrice then
    -- trigger a client notification back to the player
    return
end
Player.Functions.RemoveMoney('bank', vehiclePrice)
-- then spawn / give vehicle
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mohssins.gitbook.io/mohscriptsdocs/moh-vipshowroom/purchase.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
