sh.stellarium.money.Account is the resource a payable contract uses to read and spend its own balance. Every node serves it itself, with the operator keeping the balance, so there is no peer to find and no other node that could answer for it. Bind it like any resource:
Amounts are micro-USD (1 USD = 1,000,000). Pass
null as key for funding that was never earmarked.
Rules for every call
- Only a running contract has a balance. A call from a request script fails.
- Each call evaluates to
{ value, error }, like any resource call. Read results with.value. - A failed call fails the run, even if the contract ignores its
error. The run’s state changes are dropped and no money moves. Calls fail when they would spend more than the named funding, pay an organization that isn’t one of its payees, pay one that can’t receive payouts (except withtryPay), or use an amount that isn’t a whole number greater than0. - Nothing moves while the contract runs. Changes are staged, and apply only when the run that started everything succeeds. See When money moves.
- Reads include the run’s staged changes, so
balanceafter apayin the same run shows the payment. - Calls are free. The functions have no price. The operator takes the platform fee from
payitself.
balance
Returns the contract version’s balance, including what this run has received and spent so far.earmark
Labels the money attached to this call withkey, so it can be spent apart from the same funder’s other money. Call it at most once per call, and only when payment.amount is more than 0. A contract that holds several jobs for one buyer earmarks each payment with its job id, and then each job can spend only its own money.
fundingOf
Returns how much oforg’s funding under key is unspent, including this run’s changes. Read it instead of keeping your own record of what was paid in: the time limit can return money without running the contract.
canReceive
Returns whetherorg can be paid now: it has finished payout setup, and it isn’t frozen, banned or closed. Check it before you accept money for a payee.
pay
Paysamount to to out of from’s funding under key, and returns what’s left of that funding. to must be one of the funding’s payees. The amount, less the 1% platform fee (rounded up), goes to the payee’s payable balance and is paid out through Stripe Connect.
tryPay
Likepay, but when to can’t receive payouts, it pays nothing and returns false, so the run carries on. Use it when a contract pays several organizations in one run, so one payee that loses payout setup can’t block the others, and keep or refund what it couldn’t pay.
refund
Returnsamount of to’s funding under key, with no fee, and returns what’s left of that funding. The money goes one step back: to to’s prepaid balance if a request script sent it, or to the balance of the contract that sent it, under the same funder, key and payees. No code runs on the way back.
Sending money to another contract
Account has no function for it. Attach the money to a call instead, naming whose funding it comes from:
payment.from as buyer. payees can narrow the funding’s payees, never add to them. See Attaching money to a call.