Account types & accounts
Creating account types
Section titled “Creating account types”Wallet::accounts()->createAccountType([ 'name' => 'Savings', 'internal_name' => 'savings', // unique; used everywhere in code 'kind' => 'user', // 'user' | 'system' (or AccountKind enum) 'description' => 'Member savings', // optional 'currency' => 'USD', // optional, defaults to config('wallet.currency') 'generate_account_number' => true, // optional 'account_number_prefix' => '20', // optional, unique, requires generate_account_number 'system_limit_type' => 'limited', // system types only: 'limited' | 'unlimited']);Returns the AccountType model. Throws MissingParameterException, InvalidAccountTypeException (bad kind),
InvalidParameterException, or DuplicateRecordException (duplicate internal_name or prefix).
System account types automatically get their single system account (and balance row). You never create system accounts yourself. Fetch one with:
$treasury = Wallet::accounts()->systemAccount('treasury'); // Account; accepts model, id or internal_namesystem_limit_type:
unlimited: the account may go arbitrarily negative (treasury, mint).limited(or null): behaves like any account: it needs funds, up to itscredit_limit.
Opening accounts
Section titled “Opening accounts”$account = $user->openAccount('savings'); // via HasWallet$account = $user->openAccount('savings', ['credit_limit' => 500]);$account = $user->openAccount('savings', ['waive_fees' => true]); // exempt from account fees
// or without the trait$account = Wallet::accounts()->createAccount($user, 'savings', ['credit_limit' => 500]);- One account per owner and account type (
DuplicateRecordExceptionotherwise). - System types cannot be opened for owners (
InvalidAccountTypeException). credit_limitis a positive overdraft allowance: withcredit_limit = 500the account may reach −500.- A number like
20000001is generated when the type hasgenerate_account_number(prefix + zero-padded sequence, width fromconfig('wallet.account_number_length')).
Finding accounts
Section titled “Finding accounts”$user->walletAccount('savings'); // ?AccountWallet::accounts()->findFor($user, 'savings'); // ?Account$user->walletAccounts; // all accounts (MorphMany)Wallet::accounts()->resolveType('savings'); // AccountType from model|id|internal_nameDeactivating an account
Section titled “Deactivating an account”Set active to false ($account->update(['active' => false])). Payments to or from an inactive account throw
InvalidAccountException. Existing history and balances are untouched.
Account fields
Section titled “Account fields”| Field | Notes |
|---|---|
account_type_id |
|
owner_type, owner_id |
Morph; both null for system accounts |
number |
Generated number or null |
credit_limit |
Overdraft allowance, default 0 |
fees_waived |
Exempt from every account fee (waive_fees when opening) |
negative_since |
Set when the balance goes below zero, cleared when it recovers |
active |
Relations: accountType, accountBalance, owner, outgoingTransfers, incomingTransfers.