vanthao03596 / walletly
A flexible, feature-rich wallet library for Laravel with multi-currency support
v1.0.0
2026-03-26 03:16 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/events: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- larastan/larastan: ^2.0|^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^8.0|^9.2|^10.0
- phpunit/phpunit: ^10.1|^11.0
README
A flexible, feature-rich wallet library for Laravel with multi-currency support.
Features
- Multiple Wallets - Support multiple wallet types per user (main, bonus, credit)
- Multi-Currency Support - Handle different currencies with ease
- Transaction History - Complete audit trail of all transactions
- Flexible Operations - Deposit, withdraw, transfer between wallets
- Event-Driven Architecture - Hooks into every wallet operation
- Balance Calculations - Real-time balance with pending transactions support
- Comprehensive Testing Utilities - Fake mode, assertions, and factories
Requirements
- PHP 8.1+
- Laravel 10.0, 11.0 or 12.0
Installation
composer require vanthao03596/walletly
The package uses Laravel's auto-discovery, so the service provider and facade are registered automatically.
Publish Configuration
php artisan vendor:publish --provider="Wallet\WalletServiceProvider" --tag="config"
Database Setup
php artisan vendor:publish --provider="Wallet\WalletServiceProvider" --tag="migrations" php artisan migrate
Quick Start
Basic Usage
use Wallet\Wallet; // Get user's wallet $wallet = Wallet::of($user); // Deposit funds $transaction = $wallet->deposit(10000); // 100.00 in cents // Withdraw funds $transaction = $wallet->withdraw(5000); // 50.00 in cents // Get balance (in cents) $balance = $wallet->balance(); // 5000 // Transfer between wallets $wallet->transfer($anotherWallet, 2500);
Using HasWallet Trait
Add the HasWallet trait to your User model:
use Wallet\Traits\HasWallet; class User extends Model { use HasWallet; }
Then you can use:
$user->deposit(10000); $user->withdraw(5000); $user->balance(); $user->transfer($anotherUser, 2500);
Multiple Wallets
// Work with different wallet types $mainWallet = Wallet::of($user)->wallet('main'); $bonusWallet = Wallet::of($user)->wallet('bonus'); // Deposit to bonus wallet $bonusWallet->deposit(5000, ['reason' => 'Welcome bonus']); // Transfer from bonus to main $bonusWallet->transfer($mainWallet, 2500);
Transaction Metadata
// Add metadata to transactions $wallet->deposit(10000, [ 'description' => 'Order payment', 'order_id' => 12345, 'source' => 'stripe', ]); // Get transactions with metadata $transactions = $wallet->transactions() ->where('meta->order_id', 12345) ->get();
Documentation
For complete documentation, see the docs folder:
- Installation
- Configuration
- Basic Usage
- Multiple Wallets
- Transactions
- Events
- Exceptions
- Testing
- API Reference
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.