Charging a Player
ChargePlayer takes a payment in cash or from the bank and returns a receipt. If what was paid for then fails, RefundPlayer gives the money back the way it came. WHIP's fuel pumps, shops, ATMs and whip_autos all charge this way.
Charging
local receipt, err = exports.whip_core:ChargePlayer(source, 500, {
method = 'auto', -- 'cash' | 'bank' | 'auto': cash if they carry enough, else the bank
reason = 'Car wash', -- on their bank statement and the activity log
})
if not receipt then
return exports.whip_core:NotifyPlayer(source, err, 'error') -- 'Not enough cash (have $20, need $500)'
end
if not washTheCar() then
exports.whip_core:RefundPlayer(receipt) -- all of it; RefundPlayer(receipt, 200) for part
endBank payments come from their default account unless you pass accountId; the player's own withdraw permission is checked, so a job account they can only view can't pay. currency charges another item as money: a black market taking gold bars refunds the very bars it took. The card lists every option.
An amount of 0 takes nothing and still returns a receipt, so a free item needs no special case.
Refunding
The receipt remembers how they paid, and RefundPlayer sends the money back the same way with no permission check. A refused bank refund comes back as cash; cash for a player who has left goes to their bank. A refund that can't be delivered returns false and is printed as CRITICAL.
Inside a SecureEvent
The payment is taken at once, so it can't be spent twice, but written in the same transaction as your next WHIP write: the car CreateOwnedVehicle makes, the data SetVehicleData sets, the parts SetVehicleAppearance fits, or the end of your handler. A crash or whip_core restart between paying and delivering keeps neither.
If that write fails, nothing was taken, and your RefundPlayer lets the payment go. Outside a SecureEvent, in a thread of yours, the payment is written at once.
Metered services
For fuel, a taxi fare or anything measured as it runs, don't charge and refund the change: the change is lost if your resource or the server stops in between. Use Money holds instead.
Paying a player
PayPlayer goes the other way: a wage, a reward, a sale. Pass a server id, or { charId = n } for a character who may be offline (paid into the bank). Cash that doesn't fit their pockets lands at their feet.
exports.whip_core:PayPlayer(source, 250, { reason = 'Courier job' })
exports.whip_core:PayPlayer({ charId = 12 }, 250, { method = 'bank', reason = 'Wages' })