12 / 13Developers
Snippets
Copy-ready Lua examples that use Banking's exports, such as billing a customer for a mechanic repair.
Mechanic repair invoice#
lua
-- Called by your existing authorized server repair-completion workflow.
local function issueRepairInvoice(order)
local result = exports['stormix-banking']:createInvoice({
billFrom = order.society, -- Server-established shop group, e.g. mechanic.
groupType = order.groupType, -- job/gang/system/ox; may be omitted when unambiguous.
billTo = order.customerIdentifier,
amount = order.totalDollars,
label = ('Repair order %s - %s'):format(order.id, order.description),
operationId = ('repair:%s'):format(order.id),
})
if not result.ok then
print(('Repair invoice %s failed: %s'):format(order.id, result.error.code))
return nil, result.error.code
end
return result.data.id
endGovernment treasury integration#
lua
local treasuryName = 'government'
local treasuryType = 'system'
local function getTreasuryAccount()
local result = exports['stormix-banking']:getBusinessAccount(treasuryName, treasuryType)
if not result.ok then return nil, result.error.code end
return result.data -- id, iban, balanceCents, ownerType, ownerId, etc.
end
local function addTreasuryReceipt(dollars, receiptId)
return exports['stormix-banking']:addSocietyMoney(
treasuryName, dollars, treasuryType, ('gov-credit:%s'):format(receiptId)
)
end
local function payTreasuryExpense(dollars, expenseId)
return exports['stormix-banking']:removeSocietyMoney(
treasuryName, dollars, treasuryType, ('gov-debit:%s'):format(expenseId)
)
end