hpwebdeveloper/laravel-pay-pocket
Laravel Pay Pocket adds virtual wallets to Laravel using simple wallets and wallet_logs tables. Manage multiple wallet types, deposit, withdraw/pay, check balances, and record logs with clear APIs and exceptions—built for in-app money, not payment gateways.
composer require hpwebdeveloper/laravel-pay-pocket.php artisan vendor:publish --tag="pay-pocket-migrations"
php artisan migrate
php artisan vendor:publish --tag="pay-pocket-wallets" --tag="config"
WalletOperations interface and ManagesWallet trait in your User model:
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
use HPWebdeveloper\LaravelPayPocket\Traits\ManagesWallet;
class User extends Authenticatable implements WalletOperations
{
use ManagesWallet;
}
app/Enums/WalletEnums.php (e.g., case CASH = 'cash';, case BONUS = 'bonus';).$user->deposit('cash', 100.00, 'Initial funding');
$user->deposit('bonus', 25.00, 'Welcome bonus');
$logs = $user->pay(80.00, 'Order #123'); // Uses cash first, then bonus if needed
pay() method automatically consumes from highest-priority wallet down until amount is covered.Collection<WalletsLog> returned by pay() to generate itemized receipts or audit trails:
$logs = $user->pay(50.00, 'Subscription renewal');
$details = $logs->map(fn($log) => [
'wallet' => $log->wallet_name,
'amount' => $log->value,
'balance_after' => $log->balance_after
])->toArray();
deposit() method for manual wallet top-ups (e.g., admin funding, rewards, refunds), optionally including descriptive notes for reconciliation.$user->deposit()) for readability in controllers. Use the LaravelPayPocket facade for service-layer or job-based logic where model context may be indirect.$user->walletBalance for total spendable balance, and $user->getWalletBalanceByType('bonus') for targeted wallet checks before complex operations.WalletEnums. Changing the order later affects payment behavior—test thoroughly when modifying the Enum.$notes parameter is valid, but including descriptive notes (e.g., 'Refund for order #456') enables better logging, debugging, and end-user communication.WalletEnums throws an InvalidArgumentException. Validate user inputs against the Enum before calling methods.wallets and wallets_logs tables but does not modify your users table. This keeps integration non-invasive but requires careful scaling of wallets_logs (e.g., indexing, archival).WalletsLog::where('wallet_name', WalletEnums::BONUS->value)->get();
Collection from pay() instead of void. Existing code ignoring the return value remains compatible, but new usage should leverage this for transparency and debugging.How can I help you explore Laravel packages today?