Server side
PayInvoice
lua
---An export to pay invoice manually.
---@param source number
---@param invoiceId number
---@return boolean, number
local success, amountPaid = exports["tgg-billing"]:PayInvoice(source, invoiceId)CancelInvoice
lua
---An export to cancel invoice manually.
---@param source number
---@param invoiceId number
---@return boolean
local success = exports["tgg-billing"]:CancelInvoice(source, invoiceId)CreateInvoice
lua
---An export to create an invoice manually.
---@param invoiceData table
---@return table The created invoice
local invoice = exports["tgg-billing"]:CreateInvoice(invoiceData)Invoice Data Structure:
lua
local invoiceData = {
-- Required fields
total = 100, -- Total amount (before tax)
taxPercentage = 10, -- Tax percentage (from company config)
sender = 'police', -- Company identifier (must match config) or '__personal'
senderId = "Your sender Id", -- Usually this is the player's identifier
senderName = "Your sender name", -- Usually this is the player's name
recipientId = "The recipient Id", -- The recipient's identifier
recipientName = "The recipient name", -- Optional: The recipient's name
recipientType = 'player', -- 'player' or 'company' (defaults to 'player')
-- Invoice items
items = {
{
key = "speeding", -- Item key
label = "Speeding", -- Display label
price = 100, -- Item price
quantity = 1, -- Quantity
priceChange = false, -- Whether price can be changed (from config)
quantityChange = false -- Whether quantity can be changed (from config)
}
},
-- Optional fields
notes = "Your notes here", -- Optional notes
senderCompanyName = "Your society name", -- If sender is '__personal' might be nil
skipAcceptance = false -- Optional. If true, bypasses acceptance and sets status to 'unpaid' immediately
}lua
-- Example: Create a speed cam ticket invoice from police society to a player
-- Usage: Server-side export from tgg-billing resource
local invoiceData = {
-- Required fields
total = 100, -- Total amount (before tax)
taxPercentage = 10, -- Tax percentage (from police config)
sender = 'police', -- Company identifier (must match config)
senderName = 'Speed Camera System', -- Sender name (optional, but recommended)
-- senderCompanyName will be auto-filled from config as 'Law Enforcement' if not provided
-- Recipient information
recipientId = 'BP711N34', -- Player identifier
recipientName = 'Player Name', -- Optional: Player name (you can fetch this using Framework.GetPlayerFromIdentifier)
recipientType = 'player', -- 'player' or 'company' (defaults to 'player')
-- Invoice items
items = {
{
key = 'speeding', -- Item key
label = 'Speeding', -- Display label
price = 100, -- Item price
quantity = 1, -- Quantity
priceChange = false, -- Whether price can be changed (from config)
quantityChange = false -- Whether quantity can be changed (from config)
}
},
-- Optional fields
notes = 'Speed camera violation detected at Route 68. Speed: 85 mph in a 50 mph zone.', -- Optional notes
-- skipAcceptance = false -- Set to true to bypass acceptance requirement and set status to 'unpaid' immediately
}
-- Call the export
local invoice = exports['tgg-billing']:CreateInvoice(invoiceData)
if invoice then
print('Invoice created successfully!')
print('Invoice ID: ' .. invoice.id)
print('Invoice UUID: ' .. invoice.uuid)
print('Status: ' .. invoice.status)
else
print('Failed to create invoice. Check server console for errors.')
endlua
-- This example shows how to get the player name from their identifier before creating the invoice
local recipientIdentifier = 'BP711N34'
-- Get player name (example using Framework - adjust based on your framework)
local recipientPlayer = Framework.GetPlayerFromIdentifier(recipientIdentifier)
local recipientName = 'Unknown Player'
if recipientPlayer then
recipientName = recipientPlayer.getName()
else
-- Try offline player if not online
local offlinePlayer = GetOfflinePlayer(recipientIdentifier)
if offlinePlayer then
recipientName = offlinePlayer.getName()
end
end
local invoiceDataWithName = {
total = 100,
taxPercentage = 10,
sender = 'police',
senderName = 'Speed Camera System',
recipientId = recipientIdentifier,
recipientName = recipientName, -- Now includes actual player name
recipientType = 'player',
items = {
{
key = 'speeding',
label = 'Speeding',
price = 100,
quantity = 1,
priceChange = false,
quantityChange = false
}
},
notes = 'Speed camera violation detected at Route 68. Speed: 85 mph in a 50 mph zone.'
}
local invoice2 = exports['tgg-billing']:CreateInvoice(invoiceDataWithName)lua
-- Useful for automated systems like speed cameras
local invoiceDataAutoPay = {
total = 100,
taxPercentage = 10,
sender = 'police',
senderName = 'Speed Camera System',
recipientId = 'BP711N34',
recipientName = 'Player Name',
recipientType = 'player',
items = {
{
key = 'speeding',
label = 'Speeding',
price = 100,
quantity = 1,
priceChange = false,
quantityChange = false
}
},
notes = 'Speed camera violation detected at Route 68.',
skipAcceptance = true -- Bypasses acceptance requirement
}
local invoice3 = exports['tgg-billing']:CreateInvoice(invoiceDataAutoPay)