# Money

> Linden dollar (L$) payments: receiving money, paying out and vendor patterns.

Objects can receive L$ from avatars and, with the owner's permission, pay L$ out. Vendors, tip jars, rentals and games are built from these few functions.

Receiving needs no permission: the [`money`](/events/money/) event fires when someone pays the object. Paying out needs [`PERMISSION_DEBIT`](/constants/PERMISSION_DEBIT/), granted by the owner. Handle it carefully, because a bug can spend the owner's money.

## Concepts

- Receiving payments
  - The [`money`](/events/money/) event fires when someone pays the object
  - The pay dialog shows a default amount and quick-pay buttons, which the script [controls](/functions/llSetPayPrice/)
  - Set the [click action](/functions/llSetClickAction/) to [pay](/constants/CLICK_ACTION_PAY/) to open it on click
- Paying out
  - The owner grants `PERMISSION_DEBIT` through [`llRequestPermissions`](/functions/llRequestPermissions/)
  - [`llTransferLindenDollars`](/functions/llTransferLindenDollars/) returns a transaction key, and reports success or failure in [`transaction_result`](/events/transaction_result/)
  - [`llGiveMoney`](/functions/llGiveMoney/) is the older call with no result
- Vendors
  - After payment, a vendor checks the amount and [gives the item](/functions/llGiveInventory/), refunding wrong amounts
  - Several items can be [given as a folder](/functions/llGiveAgentInventory/), and [agent data](/functions/llRequestAgentData/) can be looked up

## Functions and events

- `event` [`money`](/events/money/) `(key id, integer amount)`
- `void` [`llSetPayPrice`](/functions/llSetPayPrice/) `(integer price, list quick_pay_buttons)`
- `key` [`llTransferLindenDollars`](/functions/llTransferLindenDollars/) `(key destination, integer amount)`
- `event` [`transaction_result`](/events/transaction_result/) `(key id, integer success, string data)`
- `integer` [`llGiveMoney`](/functions/llGiveMoney/) `(key destination, integer amount)`
- `void` [`llGiveInventory`](/functions/llGiveInventory/) `(key target, string item)`

## [Money on the wiki](https://wiki.secondlife.com/wiki/Category:LSL_Money)

The wiki's category of money functions and events.

## Scripting Details

- `event` [`money`](/events/money/) `(key id, integer amount)`: Triggered when a resident specified by id pays an amount of Linden dollars (L$) to the prim.
- `void` [`llSetPayPrice`](/functions/llSetPayPrice/) `(integer price, list quick_pay_buttons)`: Suggests default amounts for the pay text input field price and the four payment dialog quick_pay_buttons when an avatar pays this object.
- `void` [`llSetClickAction`](/functions/llSetClickAction/) `(integer action)`: Sets the action (a CLICK_ACTION_* flag) performed when an avatar left-clicks the prim.
- `integer` [`CLICK_ACTION_PAY`](/constants/CLICK_ACTION_PAY/) `= 3`: Opens the pay dialog when the prim is clicked or touched.
- `void` [`llRequestPermissions`](/functions/llRequestPermissions/) `(key agent, integer permissions)`: Requests permissions (a bitfield specified by permissions) from the agent in the same region, calling run_time_permissions if granted. This call does not pause script execution.
- `integer` [`PERMISSION_DEBIT`](/constants/PERMISSION_DEBIT/) `= 0x00002`: Runtime permission that allows the script to successfully call llGiveMoney or llTransferLindenDollars to debit the owner's account.
- `key` [`llTransferLindenDollars`](/functions/llTransferLindenDollars/) `(key destination, integer amount)`: Transfers amount of L$ from the script owner to the destination avatar, requiring the PERMISSION_DEBIT permission. Returns a key query handle matching the resulting transaction_result event.
- `event` [`transaction_result`](/events/transaction_result/) `(key id, integer success, string data)`: Triggered when an asynchronous L$ transfer (such as llTransferLindenDollars) is completed. Passes transaction info id, success status, and CSV or error data.
- `integer` [`llGiveMoney`](/functions/llGiveMoney/) `(key destination, integer amount)`: Transfers the specified amount of L$ from the script owner to the destination avatar. Silently fails if the PERMISSION_DEBIT permission has not been granted. Returns 0 (use llTransferLindenDollars to match transactions to transaction_result events).
- `void` [`llGiveInventory`](/functions/llGiveInventory/) `(key target, string item)`: Gives the specified inventory item to the target, as permitted by the permissions system. The target can be any agent or an object located in the same region.
- `integer` [`llGiveAgentInventory`](/functions/llGiveAgentInventory/) `(key agent, string folder, list items, list options)`: Gives the specified inventory items to the agent as a new folder named folder, as permitted by the permissions system. Customizes the transfer using options.
- `key` [`llRequestAgentData`](/functions/llRequestAgentData/) `(key id, integer data)`: Asynchronously requests the specified data category (DATA_*) about the agent id. Triggers a dataserver event with the results and returns a key query handle.

## Additional

- [`llSetPayPrice`](/functions/llSetPayPrice/) — suggests the default amount and the four quick-pay buttons ([pay buttons](/constants/groups/PayButton/))
  - [`PAY_HIDE`](/constants/PAY_HIDE/) — hide the specified quick pay button completely
  - [`PAY_DEFAULT`](/constants/PAY_DEFAULT/) — use the default value for the specified quick pay button
- [`llSetClickAction`](/functions/llSetClickAction/)
  - [`CLICK_ACTION_PAY`](/constants/CLICK_ACTION_PAY/) — opens the pay dialog when the prim is clicked or touched
- [`transaction_result`](/events/transaction_result/) — on failure, reports a [transfer error](/constants/groups/TransferError/)

## Receiving payments

Constant groups: [PayButton](/constants/groups/PayButton/) (2)

## Paying out

Constant groups: [TransferError](/constants/groups/TransferError/) (8)

## Related

See also: [Money](/categories/money/), [LSL Money (Second Life Wiki)](https://wiki.secondlife.com/wiki/Category:LSL_Money), [Avatars](/features/avatar/), [Parcels & Regions](/features/land/), [Script library: money (Second Life Wiki)](https://wiki.secondlife.com/wiki/CatMoney)
   (planned: Recipe: vendor with refunds)

## Related features

- [Avatars](/features/avatar/)
- [Prims](/features/prims/)

## Categories

- [Money](/categories/money/)

---

From lsl.dev: https://lsl.dev/features/money/
