> For the complete documentation index, see [llms.txt](https://docs.sourcedev.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sourcedev.pro/developer-api/api-exports.md).

# 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 %}
