Skip to content

Exports ​

All exports are called as exports.np_payments:<name>(...). For a walkthrough with examples, see Charging from your resource.

Server ​

server

Export Returns Description
Request(src, opts) result Open the checkout sheet and yield until it settles. Options and result
RequestAsync(src, opts, cb) ok, id | reason Same, without yielding. cb(result) runs when it settles
QuickPay(src, opts, cb?) result The quick pill. opts.stepper = { unit, value, min, max, step, pricePer }. Yields without cb; with cb it returns { ok = true, pending, id }
Charge(src, method, amount, opts?) true, ref | false, err | false, 'reconciliation_required', ref, payment Charge without UI. method: 'cash', 'bank', 'bank:<id>', 'card:<slot>'. Grant a service only for true, ref; reconcile the reference before retrying an unresolved payment. opts = { merchant?, payee?, category?, reason?, metadata?, receipt? }
GetPicker(src, opts?) Picker | nil Methods for the picker in your own UI: { methods, defaultMethod, currency, thousands, hideBalances }. opts = { amount?, category?, methods?, preferred? }
Pay(src, method, opts) result Charge the method the player picked in your UI. Opens the sheet (yields) when it needs a PIN or approval, or method is nil. Details
GetMethods(src, opts?) Method[] The methods the sheet would show. opts = { amount?, category?, methods? }
CanAfford(src, amount, method?) boolean At least one usable method (or that method; 'bank' = the personal account) covers the amount
Invoice(target, opts) id | nil, err Create an invoice. See below
Refund(ref, amount?) ok, err Refund a payment, all of it or amount. See Refund
GetPayment(ref) Payment | nil The ledger row
FindPaymentByCorrelation(correlation) Payment | nil, found Returns (payment, true) when found, (nil, true) when the lookup succeeded but found no row, and (nil, false) when the lookup failed. The caller scope comes from GetInvokingResource() and cannot be supplied by the caller. Do not retry a charge after a false lookup result.
Cancel(src) boolean Close the player's open checkout. The caller gets cancelled
IsBusy(src) boolean The player has an open checkout
RegisterTerminal(job, def) boolean Add or replace a terminal business
RegisterProvider(name, impl) boolean Plug in a banking resource. See Bridges → Custom provider
lua
-- don't open your own UI over a checkout
if exports.np_payments:IsBusy(src) then return end

-- grey out "Buy" when nothing can pay
local canPay = exports.np_payments:CanAfford(src, 2500)

-- only cash may pay here
local cashOnly = exports.np_payments:CanAfford(src, 200, 'cash')

Invoice ​

Bill a player without opening a sheet. The invoice shows in the Pay app (and the np_phone Wallet), and the payee gets the money when it is paid.

lua
local id, err = exports.np_payments:Invoice(src, {
  merchant = { id = 'lspd:fines', label = 'LSPD', icon = 'gavel', tint = 'red' },
  amount = 850,
  payee = { type = 'society', id = 'police' },
  days = 7,             -- default Config.Later.invoice.days (3), 0..365
  lateFee = 10,         -- % added once after the due date, default Config.Later.invoice.lateFee
  category = 'fine',
  reason = 'Speeding 142 in an 80',
  idempotencyKey = 'ruling:abc:effect:1', -- optional; repeated calls return the original invoice
})

target is a server id or a cid (offline players work). Returns the invoice id, or nil, 'invalid'. Reusing an idempotencyKey is up to 128 bytes and unique within the calling resource; overlength keys are rejected instead of truncated. Reusing it returns the existing invoice only when the payer, merchant, amount, payee, category, reason, due interval and late fee match; any changed term returns nil, 'idempotency_conflict'. The caller scope is taken from GetInvokingResource(), not from caller-supplied options. When it is paid, np_payments:invoicePaid fires.

For compatibility, callers may continue to pass metadata.correlation as the idempotency key. The value is scoped to the calling resource and checked against the same invoice terms; new integrations should use idempotencyKey.

Method ​

lua
{
  id = 'bank:personal',        -- 'cash' | 'bank:<account id>' | 'card:<slot>'
  kind = 'personal',           -- 'cash' | 'personal' | 'savings' | 'shared' | 'business' | 'faction' | 'card'
  group = 'personal',          -- 'personal' | 'shared' | 'faction'
  label = 'Maze Bank Checking', sub = 'LS-48 1192', number = '4417', badge = nil,
  icon = 'credit-card', tint = 'blue',
  balance = 48215,             -- nil when hidden or unknown
  limit = { used = 90, max = 250 },   -- business / faction: today's spend
  needsPin = false, needsApproval = false,
  disabled = nil,              -- 'funds' | 'limit' | 'category' | 'offduty' | 'frozen' | 'role' | 'not_allowed'
  disabledText = nil,          -- localised reason
}

Payment ​

GetPayment(ref) and the np_payments:paid event return the ledger row:

Field Description
ref Reference, e.g. PX-20481
cid, name Payer character id and name
kind checkout, terminal, quick, direct (Charge) or split child intent
merchantId, merchantLabel The merchant
amount, tip, tax Whole units
method First method used, or split
category Request category
status processing (durable charge/split intent needs reconciliation), refunding (refund movement needs reconciliation), paid, failed (debit did not complete), partial (partly refunded) or refunded
refunded Amount refunded so far
parts { method, amount, src?, cid?, refunded? }[], one per account and player
payee, items As in the request
meta { reason, metadata, resource, from?, cashier?, commission?, tipTo? }
createdAt Unix time

Split child debits have their own processing intent written before money moves. On restart, each remaining processing or refunding row is logged and emitted as np_payments:reconciliation_required(ref, payment); no charge or refund is replayed automatically. Charge returns a successful reference only after the ledger status is paid.

Client ​

client

Export Returns Description
Request(opts) result Open a checkout for a merchant in Config.ClientMerchants. opts = { merchant = '<id>', amount, items?, quick? }. Yields. See From the client
IsOpen() boolean A checkout, the register or the quick pill is open
lua
-- client: don't open your menu over the sheet
if exports.np_payments:IsOpen() then return end