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

# Banking - Exports - Server

> All exports available on the server

Accounts are addressed by id: a job or gang name for society accounts, the account number for shared accounts, and a player identifier for personal accounts.

<Note>
  A personal account is your framework's own bank balance. Reading it and moving money work whether or not that player is connected.
</Note>

## Accounts

### **GetAccount**

Returns an account, or `nil` when there is no such account.

```lua theme={null}
local account = exports.lation_banking:GetAccount('police')
```

<ParamField path="id" type="string" required>
  A job or gang name, an account number, or a player identifier.
</ParamField>

```lua theme={null}
{
  id      = 'police',
  type    = 'society',   -- personal, savings, society or shared
  name    = 'Los Santos Police',
  number  = 'LS88001000',
  balance = 1250000,
  owner   = nil,
  frozen  = false,
  members = {},
}
```

### **GetAccountBalance**

Returns the balance, or `nil` when there is no such account.

```lua theme={null}
local balance = exports.lation_banking:GetAccountBalance('ballas')
```

<ParamField path="id" type="string" required>
  The account to read.
</ParamField>

### **GetPlayerAccounts**

Returns every savings, society and shared account this player may use, each with their `role` and `permissions`.

```lua theme={null}
local accounts = exports.lation_banking:GetPlayerAccounts(identifier)
```

<Note>
  A society the player holds through their job or gang only appears while they are connected.
</Note>

<ParamField path="identifier" type="string" required>
  The player's identifier.
</ParamField>

### **GetPlayerAccountNumber**

Returns a player's personal account number.

```lua theme={null}
local number = exports.lation_banking:GetPlayerAccountNumber(identifier)
```

<ParamField path="identifier" type="string" required>
  The player's identifier.
</ParamField>

### **GetIdentifierByAccountNumber**

The reverse: the identifier behind a personal account number, or `nil`.

```lua theme={null}
local identifier = exports.lation_banking:GetIdentifierByAccountNumber('LS48219930')
```

<ParamField path="number" type="string" required>
  A personal account number, with or without spacing.
</ParamField>

### **CreateAccount**

Opens a society or shared account. Returns the account, or `nil` and a reason.

```lua theme={null}
local account, err = exports.lation_banking:CreateAccount({
  type = 'shared', name = 'Crew Fund', owner = identifier, balance = 0
})
```

<ParamField path="data.name" type="string" required>
  What the account is called.
</ParamField>

<ParamField path="data.type" type="string">
  `"society"` or `"shared"`. Defaults to `"shared"`.
</ParamField>

<ParamField path="data.id" type="string">
  Required for a society account: the job or gang name. Shared accounts are given a number.
</ParamField>

<ParamField path="data.owner" type="string">
  The identifier of the player who owns it.
</ParamField>

<ParamField path="data.balance" type="number">
  What it opens with. Defaults to `0`.
</ParamField>

### **DeleteAccount**

Closes an account. The balance is not returned to anyone: move it first.

```lua theme={null}
exports.lation_banking:DeleteAccount('LS12345678')
```

<ParamField path="id" type="string" required>
  The account to close.
</ParamField>

### **RenameAccount**

```lua theme={null}
exports.lation_banking:RenameAccount('police', 'Los Santos Sheriff')
```

<ParamField path="id" type="string" required>
  The account to rename.
</ParamField>

<ParamField path="name" type="string" required>
  The new name.
</ParamField>

### **SetAccountFrozen**

A frozen account can be seen but not used.

```lua theme={null}
exports.lation_banking:SetAccountFrozen('ballas', true)
```

<ParamField path="id" type="string" required>
  The account to freeze or unfreeze.
</ParamField>

<ParamField path="frozen" type="boolean" required>
  `true` to freeze it.
</ParamField>

## Money

### **AddAccountMoney**

Pays into an account and records the move with your reason.

```lua theme={null}
exports.lation_banking:AddAccountMoney('police', 2500, 'Impound fee')
```

<ParamField path="id" type="string" required>
  The account to credit.
</ParamField>

<ParamField path="amount" type="number" required>
  A positive whole amount.
</ParamField>

<ParamField path="note" type="string">
  What it was for. This is what shows in the history.
</ParamField>

### **RemoveAccountMoney**

Takes money out. Returns `false` when the balance cannot cover it; the balance can never go negative.

```lua theme={null}
exports.lation_banking:RemoveAccountMoney('police', 900, 'Ammunition')
```

<ParamField path="id" type="string" required>
  The account to debit.
</ParamField>

<ParamField path="amount" type="number" required>
  A positive whole amount.
</ParamField>

<ParamField path="note" type="string">
  What it was for.
</ParamField>

### **TransferMoney**

Moves money between any two accounts and writes both halves of the transfer. Returns `false` and a message when it cannot.

```lua theme={null}
local ok, message = exports.lation_banking:TransferMoney('police', 'LS12345678', 1000, 'Consulting')
```

<ParamField path="fromId" type="string" required>
  The account paying.
</ParamField>

<ParamField path="toId" type="string" required>
  The account being paid.
</ParamField>

<ParamField path="amount" type="number" required>
  A positive whole amount.
</ParamField>

<ParamField path="note" type="string">
  What it was for.
</ParamField>

## Members

### **AddAccountMember**

Gives a player access to a shared account.

```lua theme={null}
exports.lation_banking:AddAccountMember('LS12345678', identifier, {
  deposit = true, withdraw = false, transfer = false, manage = false
})
```

<ParamField path="id" type="string" required>
  The account.
</ParamField>

<ParamField path="identifier" type="string" required>
  The player being added.
</ParamField>

<ParamField path="permissions" type="table">
  Any of `deposit`, `withdraw`, `transfer` and `manage`. Deposit only by default.
</ParamField>

### **UpdateAccountMember**

Changes what an existing member may do.

```lua theme={null}
exports.lation_banking:UpdateAccountMember('LS12345678', identifier, { withdraw = true })
```

<ParamField path="id" type="string" required>
  The account.
</ParamField>

<ParamField path="identifier" type="string" required>
  The member.
</ParamField>

<ParamField path="permissions" type="table" required>
  The permissions to set.
</ParamField>

### **RemoveAccountMember**

```lua theme={null}
exports.lation_banking:RemoveAccountMember('LS12345678', identifier)
```

<ParamField path="id" type="string" required>
  The account.
</ParamField>

<ParamField path="identifier" type="string" required>
  The member to remove.
</ParamField>

### **GetAccountMembers**

Returns everyone with access, with their names and permissions.

```lua theme={null}
local members = exports.lation_banking:GetAccountMembers('LS12345678')
```

<ParamField path="id" type="string" required>
  The account to read.
</ParamField>

## Transactions

### **AddTransaction**

Writes a line in the history without moving money, for scripts that move it themselves and want it labelled properly. When tracking already caught that move on a personal account, this names that line instead of adding a second one.

```lua theme={null}
exports.lation_banking:AddTransaction(identifier, {
  type = 'income', amount = 1200, note = 'Weekly rent', counterparty = 'Vinewood Rentals'
})
```

<ParamField path="id" type="string" required>
  The account the line belongs to.
</ParamField>

<ParamField path="data.type" type="string" required>
  `deposit`, `withdraw`, `transfer_in`, `transfer_out`, `income` or `expense`.
</ParamField>

<ParamField path="data.amount" type="number" required>
  A positive whole amount.
</ParamField>

<ParamField path="data.note" type="string">
  What it was for.
</ParamField>

<ParamField path="data.counterparty" type="string">
  Who was on the other side.
</ParamField>

### **GetTransactions**

Returns a page of the history with its totals.

```lua theme={null}
local page = exports.lation_banking:GetTransactions('police', { page = 1, perPage = 25 })
```

<ParamField path="id" type="string" required>
  The account to read.
</ParamField>

<ParamField path="options.page" type="number">
  Which page. Defaults to `1`.
</ParamField>

<ParamField path="options.perPage" type="number">
  Rows per page, up to `500`. Defaults to `25`.
</ParamField>

<ParamField path="options.filters" type="table">
  Any of `types`, `search`, `dateFrom` and `dateTo`.
</ParamField>

## Bills & loans

### **CreateBill**

Sends a bill to a player. Returns its id, or `nil` and a reason.

```lua theme={null}
local id = exports.lation_banking:CreateBill({
  target = identifier, amount = 1500, note = 'Speeding', account = 'police'
})
```

<ParamField path="data.target" type="string" required>
  Who pays: an identifier or an account number.
</ParamField>

<ParamField path="data.amount" type="number" required>
  A positive whole amount.
</ParamField>

<ParamField path="data.account" type="string">
  Where the money lands when it is paid. Leave it out for a fine that leaves the economy.
</ParamField>

<ParamField path="data.note" type="string">
  What the bill is for.
</ParamField>

<ParamField path="data.issuer" type="string">
  The name on the bill. Defaults to the account's name, or your resource.
</ParamField>

<ParamField path="data.due" type="number">
  Unix time. Defaults to the days set in `/bankadmin`.
</ParamField>

### **PayBill**

Pays a bill on the player's behalf. The only export that needs them connected, because paying takes their transaction lock. Returns `false` and a message when it cannot.

```lua theme={null}
local ok, message = exports.lation_banking:PayBill(id)
```

<ParamField path="id" type="number" required>
  The bill id.
</ParamField>

<ParamField path="accountId" type="string">
  Which of their accounts pays. Defaults to their personal one.
</ParamField>

### **CancelBill**

Withdraws an unpaid bill.

```lua theme={null}
exports.lation_banking:CancelBill(id)
```

<ParamField path="id" type="number" required>
  The bill id.
</ParamField>

### **GetBills**

Returns the bills sent to a player, newest first.

```lua theme={null}
local unpaid = exports.lation_banking:GetBills(identifier, 'unpaid')
```

<ParamField path="identifier" type="string" required>
  The player.
</ParamField>

<ParamField path="status" type="string">
  `unpaid`, `paid`, `declined`, `cancelled` or `expired`. All of them when left out.
</ParamField>

### **GetLoan**

Returns the loan a player is paying off, or `nil`.

```lua theme={null}
local loan = exports.lation_banking:GetLoan(identifier)
```

<ParamField path="identifier" type="string" required>
  The player.
</ParamField>

## Other

### **OpenBank**

Opens the bank for a player from the server.

```lua theme={null}
exports.lation_banking:OpenBank(source, 'atm')
```

<ParamField path="source" type="number" required>
  The player.
</ParamField>

<ParamField path="kind" type="string">
  `"bank"`, `"atm"` or `"admin"`. Defaults to `"bank"`; `"admin"` is refused without the ACE permission.
</ParamField>

### **GetConfig**

Returns the live configuration as `/bankadmin` last saved it. Logging is not included.

```lua theme={null}
local loans = exports.lation_banking:GetConfig('loans')
```

<ParamField path="section" type="string">
  One of `general`, `currency`, `banks`, `blip`, `atm`, `accounts`, `transfers`, `transactions`, `bills`, `requests`, `savings` or `loans`. Every section when left out.
</ParamField>

## Hooks

Server hooks live in `server/utils/hooks.lua`, which ships open under escrow. Edit the functions in place to add your own rules and reactions.

| Function                                    | Purpose                                                                                          |
| :------------------------------------------ | :----------------------------------------------------------------------------------------------- |
| `Hooks.canOpen(source, kind)`               | Return `false`, optionally with a message, to refuse the bank, an ATM or the bill card.          |
| `Hooks.canTransact(data)`                   | Return `false` to refuse a deposit, withdrawal, transfer or bill payment. Nothing has moved yet. |
| `Hooks.onTransaction(transaction)`          | Runs after every recorded transaction, from the UI, the exports and other scripts' money moves.  |
| `Hooks.onAccountChange(data)`               | Runs when a shared account is opened or closed, or a member is added, changed or removed.        |
| `Hooks.ongoingPayments(source, identifier)` | What the player owes other resources, listed under their bills. Ships wired to jg-dealerships.   |

<Note>
  Looking for an export we don't have listed here? Contact us and we'll do what we can!
</Note>
