laravel-wallet maintained by evinkuraga
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- php ^7.3|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- php ^7.3|^8.0
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-json *
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.4|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- php ^7.3|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- ext-pdo *
- php ^7.3|^8.0
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- brick/math ~0.8
- php ^7.3|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- php ^7.3|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0|^8.0
- doctrine/dbal ^2.8|^3.0
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0|^4.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- nesbot/carbon ^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- nesbot/carbon ^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^6.0|^7.0
- nesbot/carbon ^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.2|^8.0
- ext-pdo *
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1|^8.0
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1|^8.0
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1|^8.0
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1|^8.0
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1|^8.0
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ^5.5|^6.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~5.9.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- nesbot/carbon ^1.20|^2.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- doctrine/dbal ^2.8
- ramsey/uuid ^3.0
- php ^7.1
- illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0|~5.8.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0
- php ^7.1
- laravel/framework ~5.5.0|~5.6.0|~5.7.0
- ramsey/uuid ^3.0

laravel-wallet - Easy work with virtual wallet.
- Vendor: bavix
- Package: laravel-wallet
- Version:
- PHP Version: 7.3+ (if you are using version 5.x then 7.2+)
- Laravel Version:
5.5,5.6,5.7,5.8,6.x,7.x,8.x - Composer:
composer require bavix/laravel-wallet
Upgrade Guide
Starting with version 5.x, support for Laravel 5 has been discontinued. Update laravel or use version 4.x.
To perform the migration, you will be helped by the instruction.
Extensions
| Extension | Description |
|---|---|
| Swap | Addition to the laravel-wallet library for quick setting of exchange rates |
| Vacuum | Addition to the laravel-wallet library for quick fix race condition |
Since version 6.2 the Vacuum package is built in and no longer requires additional steps.
Usage
Add the HasWallet trait and Wallet interface to model.
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Wallet;
class User extends Model implements Wallet
{
use HasWallet;
}
Now we make transactions.
$user = User::first();
$user->balance; // 0
$user->deposit(10);
$user->balance; // 10
$user->withdraw(1);
$user->balance; // 9
$user->forceWithdraw(200, ['description' => 'payment of taxes']);
$user->balance; // -191
Purchases
Add the CanPay trait and Customer interface to your User model.
use Bavix\Wallet\Traits\CanPay;
use Bavix\Wallet\Interfaces\Customer;
class User extends Model implements Customer
{
use CanPay;
}
Add the HasWallet trait and Product interface to Item model.
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
class Item extends Model implements Product
{
use HasWallet;
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
return true;
}
public function getAmountProduct(Customer $customer)
{
return 100;
}
public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
public function getUniqueId(): string
{
return (string)$this->getKey();
}
}
Proceed to purchase.
$user = User::first();
$user->balance; // 100
$item = Item::first();
$user->pay($item); // If you do not have enough money, throw an exception
var_dump($user->balance); // 0
if ($user->safePay($item)) {
// try to buy again )
}
var_dump((bool)$user->paid($item)); // bool(true)
var_dump($user->refund($item)); // bool(true)
var_dump((bool)$user->paid($item)); // bool(false)
Eager Loading
User::with('wallet');
How to work with fractional numbers?
Add the HasWalletFloat trait and WalletFloat interface to model.
use Bavix\Wallet\Traits\HasWalletFloat;
use Bavix\Wallet\Interfaces\WalletFloat;
use Bavix\Wallet\Interfaces\Wallet;
class User extends Model implements Wallet, WalletFloat
{
use HasWalletFloat;
}
Now we make transactions.
$user = User::first();
$user->balance; // 100
$user->balanceFloat; // 1.00
$user->depositFloat(1.37);
$user->balance; // 237
$user->balanceFloat; // 2.37
Supported by
Contributors
Code Contributors
This project exists thanks to all the people who contribute. [Contribute].
Financial Contributors
Become a financial contributor and help us sustain our community. [Contribute]
Individuals
Organizations
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]