bavix/laravel-wallet
Virtual wallet system for Laravel: manage balances, deposits/withdrawals, transfers, and multi-wallet support with robust transaction history and concurrency safety. Well-tested, benchmarked, and extensible for payments, loyalty points, and in-app credits.
HasWalletFloat).PurchaseServiceInterface, PurchaseQueryHandlerInterface) and merchant fees, making it adaptable to complex billing scenarios.User, Product) without schema changes.canBuy() or external services).wallets() relationship).HasWallet, CanPay) to models and configure the package via config/wallet.php.balanceInt before enabling balanceFloat).illuminate/database, bavix/laravel-wallet (no heavy external deps).bavix/laravel-wallet-swap for exchange rates).pay() calls) may require database transactions or optimistic locking (e.g., lockForUpdate()).canBuy()) must be wrapped in transactions to avoid partial updates.0.1 + 0.2 != 0.3).with('wallet')) is recommended for purchase workflows.PurchaseService) requires deep understanding of the package’s architecture.canBuy()?observers or events).swap).User models), validation, and middleware.wallet:balance).composer require bavix/laravel-wallet).HasWallet into a non-critical model (e.g., TestUser).deposit(), withdraw()) and fractional amounts (HasWalletFloat).CanPay to User and Product models.pay(), refund()) and test with a mock cart.canBuy() logic) and transaction observers for logging.spatie/laravel-money).balance columns (rename conflicts; package uses wallet_balance).| Phase | Task | Dependencies | Tools/Validation |
|---|---|---|---|
| Discovery | Define wallet use cases (e.g., credits, subscriptions). | Business stakeholders. | User stories. |
| Setup | Install package, publish config. | Composer, Laravel. | composer require bavix/laravel-wallet |
| Model Integration | Add traits to User/Product models. |
Eloquent models. | php artisan make:model TestUser |
| Core Workflows | Implement deposit(), withdraw(), pay(). |
Basic transactions. | Unit tests (PHPUnit). |
| Purchase Logic | Configure CanPay, ProductInterface, and canBuy(). |
Cart system (if applicable). | Integration tests. |
| Validation | Test edge cases (e.g., negative balances, concurrency). | Load testing. | Laravel Dusk or Pest. |
| Monitoring | Add logging (e.g., WalletTransactionCreated). |
Observers/Events. | Sentry, Laravel Logs. |
| Scaling | Optimize with caching (Redis) or queues. | High traffic. | Blackfire, Laravel Horizon. |
PurchaseService) requires documentation and testing.How can I help you explore Laravel packages today?