# API & Exports

The Billing System provides several exports that allow other resources to interact with the system programmatically.

## Client-Side Exports

### Open Tablet

Opens the billing tablet for the player.

```lua
exports['src-billing']:OpenBilling()
```

### Close Tablet

Closes the billing tablet if it is currently open.

```lua
exports['src-billing']:CloseBilling()
```

### Check if Open

Returns `true` if the tablet is currently open, `false` otherwise.

```lua
local isOpen = exports['src-billing']:IsBillingOpen()
```

***

## Server-Side Exports

### Create Invoice

Programmatically create an invoice without using the UI.

```lua
local data = {
    creatorId = "CITIZEN_ID_HERE",
    creatorName = "John Doe",
    creatorJob = "police",
    targetId = "TARGET_CITIZEN_ID",
    targetServerId = 1, -- Optional: trigger notification for online player
    customerName = "Jane Doe",
    amount = 500,
    reason = "Speeding Fine", -- Can be simple string or JSON metadata
    recurring = {
        enabled = true,
        intervalDays = 7,
        totalPayments = 4
    }
}

exports['src-billing']:CreateInvoice(data)
```

### Get Invoice Details

Retrieve data for a specific invoice ID.

```lua
local invoice = exports['src-billing']:GetInvoice("INV-123456")
```

### Get Player Invoices

Retrieve all invoices where the player is either the creator or the target.

```lua
local identifier = "CITIZEN_ID_HERE"
local invoices = exports['src-billing']:GetPlayerInvoices(identifier)
```

### Get Job Settings

Retrieve configuration settings for a specific job.

```lua
local settings = exports['src-billing']:GetJobSettings("police")
```

***

## Events

### Client Events

#### `src-billing:client:receiveInvoice`

Triggered when a player receives a new invoice.

```lua
AddEventHandler('src-billing:client:receiveInvoice', function(invoice)
    -- invoice = { id, amount, creatorName, ... }
end)
```

#### `src-billing:client:invoicePaid`

Triggered when a player successfully pays an invoice.

```lua
AddEventHandler('src-billing:client:invoicePaid', function(invoiceId)
    -- handle payment completion
end)
```

### Server Events

#### `src-billing:server:createInvoice`

Triggered to create a new invoice (Internal use recommended).

***

{% hint style="info" %}
**Note:** When using `CreateInvoice` via export, the system automatically handles database insertion and cache updates.
{% endhint %}


---

# 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://docs.sourcedev.pro/developer-api/api-exports.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.
