> ## Documentation Index
> Fetch the complete documentation index at: https://docs.awokenlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> Server events Awoken Banking fires so your other scripts can react to money, loans, cards, and more.

Awoken Banking fires a **server event** whenever something important happens - money moves, a loan defaults, a card is frozen, tax is collected. These are one-way notifications: you listen, you don't reply. Every name is prefixed with `awoken_banking:` and fires on the **server**, so register your handlers in a server script.

```lua server.lua theme={"dark"}
AddEventHandler('awoken_banking:onLoanPayment', function(p)
    -- p = { loanId, citizenid, amount, outstanding, kind }
    print(('%s paid %s off their loan - %s left'):format(p.citizenid, p.amount, p.outstanding))
end)
```

## Money and accounts

| Event              | When it fires                                                       | Payload (short shape)                                       |
| ------------------ | ------------------------------------------------------------------- | ----------------------------------------------------------- |
| `onTransaction`    | Any money movement is written to history.                           | the transaction row                                         |
| `onMoneyAdded`     | Money is added to an account (fires alongside `onTransaction`).     | the transaction row                                         |
| `onMoneyRemoved`   | Money is removed from an account (fires alongside `onTransaction`). | the transaction row                                         |
| `onTransfer`       | A transfer between two accounts completes.                          | `{ fromAccount, toAccount, amount, fee, issuer, receiver }` |
| `onAccountCreated` | A new account is opened (personal, job, gang, or shared).           | `{ id, account_number, type, owner, label }`                |
| `onAccountFrozen`  | An account is frozen or unfrozen (legal hold).                      | `{ id, account_number, frozen, reason }`                    |
| `onAccountSeized`  | Funds are seized from an account (civil forfeiture).                | `{ id, account_number, amount, to, reason, by }`            |

## Cards

| Event              | When it fires                 | Payload (short shape)    |
| ------------------ | ----------------------------- | ------------------------ |
| `onCardCreated`    | A bank card is issued.        | the public card (no PIN) |
| `onCardFrozen`     | A card is frozen or unfrozen. | `{ cardId, frozen }`     |
| `onCardPinChanged` | A card's PIN is changed.      | `{ cardId }`             |
| `onCardDeleted`    | A card is deleted.            | `{ cardId }`             |

## Loans and credit

| Event              | When it fires                                                                                                                                | Payload (short shape)                               |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| `onLoanCreated`    | A loan or financed purchase is booked.                                                                                                       | the public loan (`label`, `apr`, …) + `citizenid`   |
| `onLoanPayment`    | Every loan payment, manual or automatic.                                                                                                     | `{ loanId, citizenid, amount, outstanding, kind }`  |
| `financeDefaulted` | A `notify` loan defaults - **repossess here**, the debt is then written off. The `metadata` from the finance deal comes back on the payload. | `{ loanId, citizenid, source, amount, metadata }`   |
| `financePaidOff`   | A loan is fully paid or settled early.                                                                                                       | `{ loanId, citizenid, source, metadata, settled? }` |
| `onCreditChanged`  | A player's credit score changes.                                                                                                             | `{ citizenid, score, delta, reason }`               |

## Savings, tax, and scheduled payments

| Event                 | When it fires                                     | Payload (short shape)                            |
| --------------------- | ------------------------------------------------- | ------------------------------------------------ |
| `onInterest`          | Savings interest is paid into an account.         | `{ accountId, amount, tier, owner }`             |
| `onTierUpgraded`      | A savings account moves up an interest tier.      | `{ accountId, tier, citizenid }`                 |
| `onSlotUpgraded`      | A player buys an extra account slot.              | `{ citizenid, type, slots }`                     |
| `onTax`               | Tax is collected on a transaction.                | `{ accountId, amount, txType, citizenid }`       |
| `onScheduledExecuted` | A scheduled / standing payment runs successfully. | `{ id, owner, kind, amount, to, label }`         |
| `onScheduledFailed`   | A scheduled payment can't run.                    | `{ id, owner, kind, amount, to, label, reason }` |

## Bills and requests

| Event               | When it fires                                                               | Payload (short shape)                              |
| ------------------- | --------------------------------------------------------------------------- | -------------------------------------------------- |
| `onInvoiceCreated`  | A one-off request is raised against a player.                               | `{ id, from, to, amount, reason }`                 |
| `onInvoicePaid`     | A player pays a request.                                                    | `{ id, from, to, amount, source }`                 |
| `onInvoiceDeclined` | A player declines a request, or the issuer cancels it (`cancelled = true`). | `{ id, to, amount, source, cancelled? }`           |
| `onBillCreated`     | A bill is pushed to a player.                                               | `{ id, owner, amount, category, source }`          |
| `onBillPaid`        | A player pays a bill.                                                       | `{ id, owner, amount, category, source, to }`      |
| `onBillOverdue`     | A bill passes its due date (late fee already applied).                      | `{ id, owner, amount, lateFee, category, source }` |
| `onBillCancelled`   | An issuer cancels a bill.                                                   | `{ id, owner, amount, source }`                    |

## Stocks and investing

| Event               | When it fires                                                       | Payload (short shape)                                                            |
| ------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `onStockRegistered` | A ticker is registered.                                             | `{ symbol, kind, price }`                                                        |
| `onStockTraded`     | Any trade fills - float buy, market sell, or a peer ask / bid fill. | `{ symbol, side, shares, price, ... }` (`citizenid` or `buyer`/`seller` by side) |
| `onStockOrder`      | A player posts an ask or bid to the order book.                     | `{ id, symbol, side, shares, price, owner }`                                     |
| `onDividendPaid`    | A business pays a dividend.                                         | `{ symbol, perShare, total, holders }`                                           |
| `onStockDelisted`   | A ticker is delisted (holders cashed out).                          | `{ symbol, price, holdersPaid }`                                                 |

<Warning>
  These events are notifications, not requests. Don't run heavy or blocking work inside a handler - read what you need off the payload and hand off to your own logic.
</Warning>
