vanthao03596/walletly
最新稳定版本:v1.0.0
Composer 安装命令:
composer require vanthao03596/walletly
包简介
A flexible, feature-rich wallet library for Laravel with multi-currency support
README 文档
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.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-26