Download the PHP package byjg/wallets without Composer
On this page you can find all versions of the php package byjg/wallets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package wallets
Short Description A robust PHP library for managing digital wallets and financial transactions with full audit trails, transaction chain integrity, and support for reserved funds.
License MIT
Informations about the package wallets
sidebar_key: wallets tags: [php, finance]
Wallets
A robust PHP library for managing digital wallets and financial transactions with full audit trails, transaction chain integrity, and support for reserved funds.
Features
- Multiple wallets per user - Each user can have multiple wallets for different currencies
- Multiple currencies - Support for any currency type (fiat, crypto, points, etc.)
- Reserved funds - Pre-authorize and block funds for pending transactions
- Transaction chain integrity - Immutable transaction history with UUID linking and checksums
- Atomic operations - All balance updates are atomic and transactional
- Flexible scale - Support for different decimal places (cents, satoshis, whole units)
- Overdraft support - Optional negative balances with configurable minimum values
- Audit trail - Complete transaction history with balance snapshots
- Idempotent operations - UUID-based transaction deduplication
- Extensible - Easily extend wallets and transactions with custom fields
Installation
Quick Start
Documentation
- Getting Started - Installation, database setup, and quick start guide
- Wallet Management - Create, retrieve, and manage wallets
- Transaction Operations - Add, withdraw, and query transactions
- Reserved Funds - Pre-authorize and manage pending transactions
- Extending Entities - Add custom fields to wallets and transactions
- Database Schema - Complete database schema documentation
Full documentation is available at https://opensource.byjg.com/docs/php/wallets
Core Concepts
Integer Storage with Scale
All monetary amounts are stored as integers (BIGINT) representing the smallest currency unit:
Balance Components
Each wallet maintains three balance components:
- balance - Total funds (reserved + available)
- reserved - Funds held for pending transactions
- available - Funds available for immediate use
Transaction Types
| Type | Code | Description |
|---|---|---|
| Balance | B | Initial balance or reset |
| Deposit | D | Add funds immediately |
| Withdraw | W | Remove funds immediately |
| Deposit Blocked | DB | Reserve for incoming funds |
| Withdraw Blocked | WB | Reserve funds for withdrawal |
| Reject | R | Reverse a reserved transaction |
Transaction Chain Integrity
Every transaction links to the previous via uuid and previousuuid, creating an immutable audit trail:
Each transaction includes a SHA-256 checksum for data integrity verification.
Use Cases
E-commerce Platform
Multi-Currency Wallets
Gaming/Betting Platform
Testing
API Reference
WalletService
createWallet(string $walletTypeId, string $userId, int $balance, int $scale = 2, int $minValue = 0, ?string $extra = null): intgetById(int $walletId): WalletEntitygetByUserId(string $userId, string $walletType = ""): arraygetByWalletTypeId(string $walletTypeId): arrayoverrideBalance(int $walletId, int $newBalance, int $newScale = 2, int $newMinValue = 0, string $description = "Reset Balance"): ?intpartialBalance(int $walletId, int $balance, string $description = "Partial Balance"): TransactionEntitycloseWallet(int $walletId): ?inttransferFunds(int $walletSource, int $walletTarget, int $amount): array
TransactionService
addFunds(TransactionDTO $dto): TransactionEntitywithdrawFunds(TransactionDTO $dto): TransactionEntityreserveFundsForWithdraw(TransactionDTO $dto): TransactionEntityreserveFundsForDeposit(TransactionDTO $dto): TransactionEntityacceptFundsById(int $transactionId): intacceptFundsByUuid(string $uuid): intrejectFundsById(int $transactionId): intrejectFundsByUuid(string $uuid): intacceptPartialFundsById(int $transactionId, TransactionDTO $transactionDTO, TransactionDTO $transactionRefundDTO): TransactionEntitygetById(int $transactionId): TransactionEntitygetByWallet(int $walletId, int $limit = null, int $offset = null): arraygetByDate(int $walletId, string $startDate, string $endDate, int $limit = null, int $offset = null): arraygetByReference(string $referenceSource, string $referenceId): arraygetByUuid(string $uuid): ?TransactionEntityexistsTransactionByUuid(string $uuid): boolgetReservedTransactions(int $walletId): array