Exports & Developer API

These functions are declared in fxmanifest.lua under server_exports and are meant to be called from other server-side resources (for example finals_banking when Config.UsingFinalsBankingInvoice is true).

Replace finals_billingsystem with your resource folder name if it differs.

Lua
local BILLING = 'finals_billingsystem'

Prerequisites

  • oxmysql must be running (GetResourceState('oxmysql') == 'started').
  • Pending rows must exist in finals_billing_invoices with status = 'pending' and remaining_amount > 0 (created by this resource’s pay-later flow or compatible inserts).

GetPendingInvoices(citizenid)

Returns all pending invoices for a single character, ordered by due date (soonest first).

Arguments

NameTypeDescription
citizenidstring | numberCharacter identifier used in the database. Must match how this resource stores citizenid for your framework (see below). If nil, returns {}.

Framework note (BillingFW.GetCharId):

  • QBCore / QBX: citizenid from player data
  • ESX: identifier
  • ox_core: charId as a string (e.g. "123")

Return value

A table (array) of invoice objects. Empty {} if none, invalid id, or database unavailable.

Each element:

FieldTypeDescription
idnumberInvoice row id (primary key)
entryIdnumberIndex into Config.Billing
labelstringEntry Lable or 'Invoice'
logostring | nilEntry logo URL if configured
originalnumberOriginal invoice amount
remainingnumberAmount still owed
reasonstringReason text
dueUnixnumberDue time (Unix seconds)
billerNamestring | nilStored biller display name

Example

Lua
local cid = '12345' -- must be the same id this resource uses for that character
local invoices = exports['finals_billingsystem']:GetPendingInvoices(cid)
for _, inv in ipairs(invoices) do
    print(inv.id, inv.label, inv.remaining, inv.dueUnix)
end

PayInvoice(source, invoiceId, amount, method)

The player at source pays toward a pending invoice. Money is deducted in this resource from bank or cash (using framework + BillingFW.RemoveMoneyForced rules for that billing entry).

Arguments

NameTypeDescription
sourcenumberPlayer server id
invoiceIdnumberid from GetPendingInvoices / database
amountnumberAmount to pay (integer dollars after floor; capped to remaining balance internally)
methodstring'bank' or 'cash' (anything other than 'cash' is treated as bank)

Return values

SuccessFailure
truefalse, err (string)

Possible err values

Code / messageMeaning
invalid_argsMissing/invalid source, invoiceId, or amount < 1
database_unavailableoxmysql not started
invalid_playerNo framework player for source
invoice_not_foundNo matching pending invoice for this player
Invalid invoice type.Config.Billing[entry_id] missing
Not your invoice.Character id does not match row
Invalid amount.After clamping, nothing to pay
Insufficient funds.Could not deduct the payment

Partial payments are supported: remaining balance is updated until fully paid (status → paid).

Example

Lua
local ok, err = exports['finals_billingsystem']:PayInvoice(src, invoiceId, 500, 'bank')
if not ok then
    print('Pay failed:', err)
end

ConfirmInvoicePayment(source, invoiceId, amount, method)

Same as PayInvoice, but does not remove money from the player. Use this when another resource has already taken the funds (e.g. a savings/extra account in finals_banking). This export only runs distribution (biller / society / receipts / webhook) and updates the invoice row.

Arguments

Same as PayInvoice: source, invoiceId, amount, method ('bank' or 'cash' — used for bookkeeping / metadata, not for a second deduction).

Return values

Same pattern as PayInvoice: true or false, err.

Typical errors overlap with PayInvoice, except you will not get Insufficient funds. from this path (no deduction step).

Example

Lua
-- After your banking script has already removed $500 from the player:
local ok, err = exports['finals_billingsystem']:ConfirmInvoicePayment(src, invoiceId, 500, 'bank')

Summary

ExportDeducts money?Use when
GetPendingInvoices—Building a UI or list of dues for a character id
PayInvoiceYesPlayer pays from cash/bank inside this resource
ConfirmInvoicePaymentNo (already done elsewhere)Integrating external banking after funds are taken

For configuration that disables the in-world invoice clerk and relies on another resource for the UI, see Config.UsingFinalsBankingInvoice in config.lua.