A modern Laravel package providing a simple virtual wallet system.
anexponent/tgr-laravel-wallet is a Laravel package for a modern laravel package providing a simple virtual wallet system..
It currently has 0 GitHub stars and 39 downloads on Packagist (latest version v1.1.0).
Install it with composer require anexponent/tgr-laravel-wallet.
Discover more Laravel packages by anexponent
or browse all Laravel packages to compare alternatives.
Last updated
A modern, simple, and flexible virtual wallet system for Laravel.
This package allows you to attach a wallet to any model (usually a User), deposit and withdraw credits, and keep a full transaction history. Ideal for apps where users buy credits or virtual currency to spend on services or goods.
Assign a wallet to any model (User, Member, etc.) Track deposits, withdrawals, refunds, and custom transaction types Transaction metadata for payment references or descriptions Safe balance updates using database transactions Force withdrawals or failed deposits Configurable models for Wallet, Transaction, and User Supports Laravel 9, 10, and 11
Install the package with composer:
composer require anexponent/tgr-laravel-wallet
The package automatically merges default configuration, so you can start using it immediately.
php artisan migrate
Publish the migrations with this artisan command:
Optional: You can publish the migrations if you want to customize them:
php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=migrations
Default configuration is already merged automatically. The defaults are:
return [
'user_model' => App\Models\User::class,
'wallet_model' => Anexponent\Wallet\Wallet::class,
'transaction_model' => Anexponent\Wallet\Transaction::class,
];
Optional: You can publish the config to customize it:
php artisan vendor:publish --provider="Anexponent\Wallet\WalletServiceProvider" --tag=config
This will merge the config.php config file where you can specify the Users, Wallets & Transactions classes if you have custom ones.
Add the HasWallet trait to your User model.
use Anexponent\Wallet\HasWallet;
class User extends Model
{
use HasWallet;
...
}
At some point before making transactions, create the user's wallet.
$user->wallet()->firstOrCreate([]);
Then you can easily make transactions from your user model.
$user = User::find(1);
$user->balance; // 0
$user->deposit(100);
$user->balance; // 100
$user->withdraw(50);
$user->balance; // 50
$user->forceWithdraw(200);
$user->balance; // -150
You can easily add meta information to the transactions to suit your needs.
$user = User::find(1);
$user->deposit(100, 'deposit', ['stripe_source' => 'ch_BEV2Iih1yzbf4G3HNsfOQ07h', 'description' => 'Deposit of 100 credits from Stripe Payment']);
$user->withdraw(10, 'withdraw', ['description' => 'Purchase of Item #1234']);
Retrieve all transactions:
$transactions = $user->transactions;
Get signed amount
$transaction->signed_amount;
Each transaction includes: amount type accepted meta (array) balance (after transaction) hash (unique ID)
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.