Payment methods

Details

This configuration is one of the core parts of the shops resource, it defines how payments are handled, including available payment methods and their configurations. With this, you can have different payment methods across different shops, or even different payment methods for buying and selling items within the same shop.

Configuration file

config/paymentMethods.lua
local framework = require 'bridge.framework'

return {
    --[[
        Payment method definitions.
        You can add your own payment methods here.
        The key is the identifier of the payment method.
        The value is a table with the following fields:
            - icon: string (FontAwesome icon class)
            - balance: function(source) -> number
            - remove: function(source, amount, reason) -> boolean
            - add: function(source, amount, reason) -> boolean

        For label, identifier will get `_sell` or `_buy` from locales.
    ]] --
    ---@type table<string, PaymentMethodDefinition>
    methods = {
        ['cash'] = {
            icon = 'fas fa-money-bill',
            balance = function(source)
                return framework.getMoney(source, 'cash')
            end,
            remove = function(source, amount, reason)
                return framework.removeMoney(source, 'cash', amount, reason)
            end,
            add = function(source, amount, reason)
                return framework.addMoney(source, 'cash', amount, reason)
            end,
        },
        ['bank'] = {
            icon = 'fas fa-bank',
            balance = function(source)
                return framework.getMoney(source, 'bank')
            end,
            remove = function(source, amount, reason)
                return framework.removeMoney(source, 'bank', amount, reason)
            end,
            add = function(source, amount, reason)
                return framework.addMoney(source, 'bank', amount, reason)
            end,
        }
    }
}