Skip to content

NUI contract ​

The contract between the Lua client and the web UI (web/), plus the server RPCs behind it. The wire types are mirrored in web/src/lib/types.ts. You only need this page to change the UI or write your own front end; resources that charge players use the exports.

The NUI is server-authoritative: it only sends intents ({ id, method }). The server re-checks request ownership, expiry, amount, method access, limits, categories and balance, then charges. A request settles once.

Messages ​

Every message is { action, data }. Messages are queued until the web posts ready (at most 128).

Lua → web ​

Action Data
boot { locale, strings, material, scale, currency, config: { holdKey, cancelKey, tipPresets? } }
checkout:open CheckoutRequest, plus keepFocus? and parent? (true on a split part sheet)
checkout:update Partial<CheckoutRequest> & { id }, e.g. fresh methods after a decline
checkout:state StateMsg
checkout:close { id, keepFocus? }
quick:show / quick:hide QuickPay / { id }
terminal:open { merchant, catalogue: { id, label, price, icon, tint }[], commission, custom, nearby, distance?, target? }
terminal:nearby { nearby: { src, label, sub, distance }[] }
terminal:close {}
pin:open { id, label, sub, amount, tries, length?, error? }. Sent again with fewer tries and error after a wrong PIN
pin:close { id }

The client relays server pushes (net event np_payments:push, { action, data }) into SendNUIMessage. The client:result push (answer to the client Request export) is handled by the client and never reaches the web.

Web → Lua ​

NUI callbacks answer { ok = true, … } or { ok = false, code, error }. A failed answer shows the declined state with error as text.

Callback Body
ready {}
close {} (ESC with nothing open)
checkout:cancel { id }
checkout:pay { id, method, tip?: { amount, to? }, split?: { method?, target?, amount }[], pin? }
checkout:later { id, kind }
quick:pay / quick:more / quick:cancel { id }
quick:step { id, value }
terminal:send { target, items: { id, qty }[], custom? }
terminal:refresh / terminal:close {}
pin:submit / pin:cancel { id, pin } / { id }

tip is only sent when the request allows tips and the tip is above 0. A split that ends with one own account is sent as a plain { id, method }.

Types ​

ts
type Tint = 'neutral'|'red'|'orange'|'rust'|'pink'|'olive'|'lilac'|'green'|'blue'|'aqua'|'brand'

interface Merchant { id: string; label: string; sub?: string; icon: string; tint: Tint }
interface LineItem { label: string; qty: number; price: number; icon?: string }

interface Method {
  id: string                 // 'cash' | 'bank:<accountId>' | 'card:<slot>'
  kind: 'cash'|'personal'|'savings'|'shared'|'business'|'faction'|'card'
  group: 'personal'|'shared'|'faction'
  label: string; sub?: string; number?: string; badge?: string
  icon: string; tint: Tint
  balance: number | null     // null = hidden or unknown
  limit?: { used: number; max: number }
  needsPin?: boolean; needsApproval?: boolean
  disabled?: string          // 'funds'|'limit'|'category'|'offduty'|'frozen'|'role'|'not_allowed'
  disabledText?: string
}

interface CheckoutRequest {
  id: string; kind: 'checkout'|'terminal'
  merchant: Merchant; amount: number; tax: number; items: LineItem[]
  category: string; currency: string
  methods: Method[]; defaultMethod: string | null
  allowSplit: boolean; allowTip: boolean; tipTargets?: { id: string; label: string; sub: string }[]
  later: { kind: 'invoice'|'instalments'|'qr'; label: string; sub: string; icon: string; tint: Tint }[]
  holdMs: number; expiresAt: number; hideBalances: boolean
  from?: string              // terminal: cashier name, '#42' for strangers
  nearby?: { src: number; label: string; sub?: string; distance?: number }[]   // split candidates
  tipPresets?: number[]
}

type PayState = 'hold'|'processing'|'accepted'|'declined'|'approval'|'waiting'
interface StateMsg {
  id: string; state: PayState; ref?: string; reason?: string; text?: string
  progress?: number; until?: number; amount?: number
}

interface QuickPay {
  id: string; merchant: Merchant; amount: number; method: Method | null
  stepper?: { unit: string; value: number; min: number; max: number; step: number; pricePer: number }
}
  • checkout:state declined always carries reason (code) and text (localised).
  • hold is sent after pin:cancel, so the sheet goes back to the hold button.
  • After pay later the server sends accepted with ref = the QR code or #<invoice id>, then closes.
  • accepted fades the sheet locally after 2.6 s if checkout:close never arrives.
  • Amounts are whole units ($48,215). A fractional value keeps two decimals.

Focus ​

While a checkout, the register or the PIN pad is open, the client calls SetNuiFocus(true, true), SetNuiFocusKeepInput(false) and SetNuiZindex(Config.ZIndex), locks np_inventory when it isn't open, and claims np_hud zones (all for the sheet, bottom-center for the pill). FiveM NUI focus is per resource, so releasing np_payments' focus never takes it from the caller's NUI.

The quick pill takes no focus. Lua reads E, TAB and ← → while it is shown and calls the quick:* RPCs itself.

Server RPCs ​

Net event np_payments:rpc (id, name, payload) → np_payments:rpc (id, result). Every RPC has a schema, a per-RPC rate limit, one call in flight per player and RPC, and the global token bucket (Config.RateLimit).

checkout:pay, checkout:cancel, checkout:later, quick:pay, quick:more, quick:step, quick:cancel, terminal:open, terminal:send, terminal:nearby, pin:submit, pin:cancel, cash:give { target }, client:request (client export).

Net events: the client sends np_payments:server:sync to ask for its register access again. The server pushes np_payments:client:terminal ({ job, label } or nil) on load and job change, and np_payments:client:cashAnim after a cash hand-over.

Phone app ​

The Pay app (web/dist/phone.html) calls these app RPCs through np_phone. Shapes are mirrored in web/src/phone/types.ts. The server pushes changed whenever something the app shows changes.

RPC Params Returns
defaults:get { categories: { id, label, icon, method, autopay }[], methods: Method[], fallback }
defaults:set { category, method | nil }
settings:get { hideBalances, autopay, autoMax, pinOver, forced }
settings:set { hideBalances?, autopay? }
open:list { invoices: Invoice[], approvals: Approval[], checkout? }
invoice:pay { id | code, method? }
receipts:list Receipt[]
faction:get { job, label, accounts: { id, label, kind, balance, tint, icon, rules, members, managed }[], approvals, categories, defaultLimit }
faction:setRule { account, subject, limit?, categories?, blocked?, onduty?, approvals?, view?, remove? } The server replaces the rule, so send the merged one
approval:decide { id, approve }
refund { ref, amount? } Boss of the payee business only

Locale ​

Web strings are ui.<key> in shared/locales/en.lua and de.lua (122 keys), with the same flat keys as the English fallback in web/src/lib/i18n.ts. boot.strings sends them without the prefix. Placeholders are {0} or %s. The phone app uses np_phone's locale and ships its own strings (web/src/phone/strings.ts, English and German).