Charging from your resource ​
This page is for resource authors. All charging happens on the server: your server code says who pays, how much and to whom, and np_payments shows the sheet and moves the money. You don't register anything first; merchant ids are free strings.
Pick the right export ​
| You want | Use |
|---|---|
| A purchase confirmed in your own UI, with the payment methods shown there | GetPicker + Pay |
| A purchase the player confirms (shop, garage, hospital) | Request |
| The same, without blocking your code | RequestAsync |
| A small repeat payment (toll, parking, fuel, vending) | QuickPay |
| To take money without any UI (rent, fee on a timer, staff action) | Charge |
| To bill now, pay later (fine, repair bill) | Invoice |
| To give money back | Refund |
Payment methods in your own UI ​
The np_* resources show the player's payment methods inside their own screen, right above their Buy button, instead of opening the checkout sheet on top. np_payments ships the picker as one script your NUI loads from np_payments, so every resource shows the same rows and they follow the server theme.
1. Server: send the methods with your screen.
local picker = GetResourceState('np_payments') == 'started'
and exports.np_payments:GetPicker(src, { amount = total, category = 'shop' }) or nil
TriggerClientEvent('my_shop:client:open', src, { items = items, payPicker = picker })
GetPicker(src, opts) takes the same amount, category, methods and preferred as Request and returns
{ methods, defaultMethod, currency, thousands, hideBalances } (nil when the player has no character).
defaultMethod is the player's default for that category from the Pay app.
2. NUI: show the picker. React UIs copy
np_payments/embed/react/NpPayMethods.tsx into their web source unchanged:
const [method, setMethod] = useState<string | null>(null)
<NpPayMethods picker={data.payPicker} amount={total} onChange={setMethod} />
<button onClick={() => fetchNui('buy', { items: cart, method })}>Buy</button>
Other UIs load the script and mount it:
<script src="https://cfx-nui-np_payments/embed/np-pay.js"></script>
<div id="pay"></div>
<script>
const picker = NpPayEmbed.mount(document.getElementById('pay'), {
...data.payPicker, amount: 120, layout: 'list', // or 'tiles' (3 per row)
onChange: (id) => { method = id },
})
picker.update({ amount: 150 }) // re-checks "not enough" live
</script>
There is also a <np-pay-methods> element (el.data = { ...payPicker, amount }, change event). Without
np_payments the server sends no picker, the component renders nothing, and your own fallback stays.
3. Server: charge the picked method.
local result = exports.np_payments:Pay(src, method, {
merchant = { id = 'my_shop:24_7', label = '24/7', icon = 'store', tint = 'green' },
amount = total, category = 'shop', items = lines, payee = { type = 'society', id = 'shop' }, keepFocus = true,
})
if result.ok then giveItems(src) end
Pay takes the Request options. A method that needs nothing more is charged right away, with no sheet. If the method
needs a PIN or a boss approval, can no longer pay, or method is nil, the checkout sheet opens with that method
preselected and Pay yields like Request. The result is the same as Request's. The client only sends
the method id; the amount, merchant and payee come from your server code as always.
Request ​
Request opens the sheet and yields until the payment is settled, so call it from a thread, an RPC handler or a
net event handler (they run in a coroutine).
RegisterNetEvent('my_garage:server:buyCar', function(model)
local src = source
local car = Config.Cars[model]
if not car then return end
local result = exports.np_payments:Request(src, {
merchant = { id = 'my_garage:pdm', label = 'Premium Deluxe Motorsport', sub = 'Downtown', icon = 'car', tint = 'blue' },
amount = car.price,
tax = math.floor(car.price * 0.05),
category = 'shop',
items = { { label = car.label, qty = 1, price = car.price } },
payee = { type = 'society', id = 'cardealer' },
preferred = 'bank',
allowSplit = true,
reason = 'Vehicle purchase',
metadata = { model = model },
})
if not result.ok then
-- result.reason: 'cancelled' | 'declined' | 'timeout' | 'busy' | 'invalid' | 'dropped' | 'later'
return
end
-- result.ref ('PX-20481'), result.method, result.amount, result.tip, result.payment (ledger row)
if not giveVehicle(src, model) then
exports.np_payments:Refund(result.ref) -- give it back if your part fails
end
end)
Options ​
| Option | Type | Description |
|---|---|---|
merchant |
table | Required. { id, label, sub?, icon?, tint? }. label up to 48 characters, sub up to 80, icon a Font Awesome name without fa- (default store), tint a Nimbus tint (default neutral) |
amount |
integer | Required. What gets charged, 1..Config.MaxAmount |
items |
table | Display lines { label, qty, price, icon? }, at most 50. Negative prices for discounts. They don't have to add up to amount |
tax |
integer | Shown as "incl. $X tax". Part of amount, not added to it |
category |
string | A Config.Categories key (default other). Drives defaults, faction rules and auto-pay |
payee |
table | Who gets the money (below). Default { type = 'none' }: the money just leaves the player |
methods |
table | Allowed kinds: 'cash', 'bank' (personal + savings), 'personal', 'savings', 'shared', 'business', 'faction', 'card'. Default: all |
preferred |
string | Row to preselect if usable: 'cash', 'bank' or a method id |
allowSplit / allowTip |
boolean | Off unless true. See Split, tip & pay later |
tipTargets |
table | { id, label, sub?, src?, account? }[], at most 8 |
allowLater |
boolean | table | true or a list of 'invoice', 'instalments', 'qr' |
receipt |
boolean | Receipt item. Default on; false turns it off |
timeout |
integer | Seconds, clamped to 10..170. Default Config.Expiry (60) |
reason |
string | Bank statement text. Default: the merchant label |
metadata |
table | Stored on the ledger row and passed to np_payments:paid |
keepFocus |
boolean | Accepted for callers that hold NUI focus. FiveM focus is per resource, so your focus is never taken away either way |
Payee ​
| Payee | Money goes to |
|---|---|
{ type = 'society', id = 'mechanic' } |
The job's society account (same for 'business') |
{ type = 'account', id = '<account id>' } |
A banking account by id (np_banking: 'acc_1a2b3c4d', from GetAccountByNumber or GetSocietyAccount) |
{ type = 'player', id = src } |
A player's bank. id can be a server id or a cid; offline cids work with providers that support it |
{ type = 'player', id = src, account = 'cash' } |
A player's cash (online only) |
{ type = 'none' } |
Nobody (the default) |
If the payee can't be credited, the payment is rolled back and declines with payee.
Result ​
-- paid
{ ok = true, ref = 'PX-20481', method = 'bank:personal', amount = 95, tip = 0, split = nil, payment = { … } }
-- not paid
{ ok = false, reason = 'cancelled' }
-- put on an invoice: NOT paid yet
{ ok = false, reason = 'later', invoice = 42, kind = 'invoice', code = nil }
reason |
Meaning |
|---|---|
cancelled |
The player closed the sheet |
declined |
The payment failed and the player gave up |
timeout |
The request expired |
busy |
The player already has a checkout open |
invalid |
Bad options (missing merchant, amount out of range, bad payee) |
dropped |
The player left or switched character |
later |
The player chose pay later. invoice is the first invoice id, code the QR code |
Things to get right ​
- Re-check after the yield. The player can spend up to 170 s in the sheet. Stock, inventory space or the vehicle
may be gone by then. Check again after
Requestreturns, andRefund(result.ref)if you can't deliver. - Never trust the client. Take the price from your config on the server. The client should send what it wants, not what it costs.
- One checkout per player. Check
exports.np_payments:IsBusy(src)first if your flow can collide, or handlebusy. - Use a stable merchant id like
my_resource:shop:<id>. It is stored on every ledger row (merchant_id) and is what logs and refunds group by. - Give the right category. Faction accounts only pay in their categories, and auto-pay works per category.
RequestAsync ​
Same options, but it returns at once and calls you back:
local ok, idOrReason = exports.np_payments:RequestAsync(src, opts, function(result)
if result.ok then deliver(src) end
end)
It returns true, id, or false, reason (the callback still runs with { ok = false, reason }).
QuickPay ​
The pill for small payments. Same options as Request, plus an optional stepper. Yields without a callback.
exports.np_payments:QuickPay(src, {
merchant = { id = 'fuel:pump4', label = 'Ron · Pump 4', icon = 'gas-pump', tint = 'orange' },
amount = 42, category = 'fuel', payee = { type = 'society', id = 'ron' },
}, function(result)
if result.ok then TriggerClientEvent('my_fuel:client:fill', src) end
end)
See Quick pay for the stepper and auto-pay.
Charge ​
Takes money without any UI. Use it for things the player already agreed to elsewhere. It writes a ledger row, asks for no PIN (your server code is trusted) and can't ask for approval.
local ok, refOrErr, unresolvedRef = exports.np_payments:Charge(src, 'bank', 5000, {
merchant = { id = 'np_character:rename', label = 'City Hall', icon = 'id-card', tint = 'pink' },
category = 'service', reason = 'Name change',
payee = { type = 'society', id = 'government' },
})
if not ok then
if refOrErr == 'reconciliation_required' then
-- Balances moved, but the ledger did not confirm settlement. Do not grant the service.
print('payment needs reconciliation: ' .. tostring(unresolvedRef))
else
print('charge failed: ' .. refOrErr) -- 'funds', 'limit', 'frozen', 'invalid', …
end
end
Charge returns true, ref only when the ledger row is paid. If a banking provider returns an unknown debit or
credit result, or balance effects completed but the final ledger update could not be confirmed, it returns
false, 'reconciliation_required', ref, payment; the row remains processing. Do not grant the purchased service
or retry the charge from this result. Reconcile the exact reference and balance effects first. At startup, existing processing rows are logged and emitted through
np_payments:reconciliation_required; the resource never replays them automatically.
| Argument | Description |
|---|---|
method |
'cash', 'bank' (personal), 'bank:<account id>' or 'card:<slot>'. Default 'bank' |
amount |
Integer |
opts |
{ merchant?, payee?, category?, reason?, metadata?, receipt? }. Receipt is off unless receipt = true |
Refund ​
exports.np_payments:Refund('PX-20481') -- everything still refundable
exports.np_payments:Refund('PX-20481', 25) -- part of it
Only settled paid or partial charges are refundable. processing and failed intents return
false, 'not_refundable'; a split child row returns false, 'split_child_refund_via_parent' because its amount is included in the parent payment. Refund the parent reference once.
Refund returns false, 'payee_funds' only when a banking provider explicitly confirms insufficient funds before a debit.
An unavailable offline payee with no debit provider returns payee_debit_unavailable; the refund stays retryable in its prior
paid or partial state. An unconfirmed player bank or cash debit, including a framework removal failure, returns
payee_debit_ambiguous; do not retry those automatically.
The money comes back out of the payee and goes to each part of the original payment (split parts too), last part
first. Returns true, or false, err with not_found, invalid (amount too high or 0), not_refundable, database,
split_child_refund_via_parent, payee_funds (the payee can't cover it), payee_debit_unavailable,
payee_debit_ambiguous or failed.
An interrupted refund remains in refunding until an operator reconciles it; the payer toast and
np_payments:refunded event occur only after the ledger confirms settlement.
From the client ​
Client code can only open merchants listed in Config.ClientMerchants. Label, category, methods, payee and the
maximum amount come from that config; the client only sends the merchant id, amount and display items.
-- shared/config.lua
Config.ClientMerchants = {
vending = { label = 'Vending machine', icon = 'cookie-bite', tint = 'neutral', category = 'vending', maxAmount = 20,
methods = { 'cash', 'personal' }, payee = { type = 'none' } },
}
-- client
local result = exports.np_payments:Request({ merchant = 'vending', amount = 3, quick = true })
if result.ok then giveSnack() end
quick = true uses the pill. Prefer server calls wherever you can: anything the client does, a cheater can do too,
up to maxAmount.
Optional dependency pattern ​
The np_* resources make np_payments optional with one setting, Config.Payments = 'auto' | true | false, and fall
back to their own framework charge. The same pattern works for yours:
Config.Payments = 'auto' -- 'auto' = when np_payments runs, true = required, false = never
local function usePayments()
if Config.Payments == false then return false end
if GetResourceState('np_payments') == 'started' then return true end
if Config.Payments == true then return nil end -- required but not running: refuse
return false
end
local function charge(src, opts, account)
local use = usePayments()
if use == nil then return false, 'unavailable' end
if use then
local ok, res = pcall(function() return exports.np_payments:Request(src, opts) end)
if ok then return res.ok == true, res.reason, res.ref end
if Config.Payments == true then return false, 'failed' end
-- export error in 'auto': fall through to the old path
end
return Bridge.removeMoney(src, account, opts.amount), nil, nil
end
When np_payments took the money it also credits the payee, so skip your own addSocietyMoney in that case, and use
Refund(ref) instead of giving money back yourself.