CodeIQ Bills Configuration
The CodeIQ Bills system is the centralized billing engine that allows you to manage invoices from multiple external resources. Follow this guide to configure and extend the system for your server.
Configuration
The config.lua file lets you configure external resources compatible with the billing engine. Each external source should be defined in the Config.ExternalResources table.
Adding External Billing Sources
To integrate an external resource, edit the config.lua file and include the necessary details as shown below:
Config.ExternalResources = {
{
resource = 'origen_masterjob', -- Name of the resource
tableName = 'origen_masterjob_bills', -- Table storing the resource's bills
ownerIdField = 'citizenid' -- Field identifying the owner of the bill
},
{
resource = 'origen_police',
tableName = 'origen_police_bills',
ownerIdField = 'citizenid'
}
}resource: Name of the external resource.tableName: SQL table containing the invoices.ownerIdField: Field identifying the owner of each invoice (e.g.,citizenid).
Example: This configuration integrates origen_masterjob and origen_police with their respective tables for invoices.
Using Core Functions
Registering Custom Handlers
Use the Bridge.registerHandler() function to create a custom handler for processing invoices from a specific resource.
Bridge.registerHandler(resourceName, handler)resourceName: Name of the external resource (e.g.,origen_police).handler: Function executed to process invoices for this resource.
Example:
Bridge.registerHandler('origen_police', function(billInfo, billId)
lib.db.query('UPDATE origen_police_bills SET payed = 1 WHERE id = @bill_id', {['@bill_id'] = billId})
if GetResourceState('qb-banking'):match('start') then
exports['qb-banking']:AddMoney(billInfo.job, billInfo.price, 'Bill Payment')
end
end)This handler updates the status of invoices in origen_police_bills and adds money via qb-banking if enabled.
Processing Invoices
The Bridge.handleExternalBill() function allows you to process invoices associated with a registered resource.
local success, message = Bridge.handleExternalBill(billInfo, billId)billInfo: Information about the bill (e.g.,data_source,price).billId: Unique identifier for the bill.
Return Values
true, "Bill paid successfully": The bill was processed successfully.false, "No handler found...": No handler was registered for this resource.
Querying Unpaid Invoices
Use the Bridge.fetchExternalBills() function to retrieve unpaid invoices from external resources.
Bridge.fetchExternalBills(resourceName, tableName, billFields, filterUnpaid)resourceName: Name of the external resource.tableName: SQL table containing the invoices.billFields: Table mapping key fields (id,price) to invoice fields.filterUnpaid: Boolean. Iftrue, fetches only unpaid invoices.
Example:
Bridge.fetchExternalBills( 'origen_police', 'origen_police_bills', { id = 'id', player_id = 'citizenid', title = 'title', description = 'description', price = 'price', job = 'job' }, true -- Fetch only unpaid invoices )Example Integration: origen_masterjob
Add origen_masterjob to the Config.ExternalResources table in config.lua:
{
resource = 'origen_masterjob',
tableName = 'origen_masterjob_bills',
ownerIdField = 'citizenid'
}The CodeIQ Bills engine can be extended easily by following these steps for any external resource.
Key Notes
- Ensure your tables include required fields (
id,citizenid,price). - Register a handler for each resource using
Bridge.registerHandler(). - Always specify
filterUnpaidwhen querying unpaid invoices.
With the CodeIQ Bills system, managing invoices across various resources has never been easier! 🚀