krunaldodiya/wallet is a Laravel package for laravel wallet.
It currently has 0 GitHub stars and 44 downloads on Packagist (latest version 1.1.3).
Install it with composer require krunaldodiya/wallet.
Discover more Laravel packages by krunaldodiya
or browse all Laravel packages to compare alternatives.
Last updated
In a few projects I had to implement a virtual currency. The user would buy packs of credits with Stripe and then use them in the app in exchange of services or goods. This package is a small and simple implementation of this concept with place for customization.
Install the package with composer:
composer require krunaldodiya/wallet
Publish the migrations with this artisan command:
php artisan vendor:publish --provider="KD\Wallet\WalletServiceProvider" --tag=migrations
You can publish the config file with this artisan command:
php artisan vendor:publish --provider="KD\Wallet\WalletServiceProvider" --tag=config
This will merge the wallet.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 KD\Wallet\Traits\HasWallet;
class User extends Model
{
use HasWallet;
...
}
Then you can easily make transactions from your user model.
$user = User::find(1);
$user->balance; // 0
$transaction = $user->createTransaction(100, 'deposit', ['description' => 'transaction description'])
$user->deposit($transaction->transaction_id);
$user->balance; // 100
$transaction = $user->createTransaction(50, 'withdraw', ['description' => 'transaction description'])
$user->withdraw($transaction->transaction_id);
$user->balance; // 50
$transaction = $user->createTransaction(200, 'withdraw', ['description' => 'transaction description'])
$user->forceWithdraw($transaction->transaction_id);
$user->balance; // -150
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.