Download the PHP package roboticsexpert/balance-manager without Composer
On this page you can find all versions of the php package roboticsexpert/balance-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roboticsexpert/balance-manager
More information about roboticsexpert/balance-manager
Files in roboticsexpert/balance-manager
Package balance-manager
Short Description Add balance (credit) for your users easily
License MIT
Informations about the package balance-manager
Laravel Balance manager
in many projects, you need to have credit (balance) concept for your user that make you distract from your main business logic.
with this package you will have balance for your users easily without being worry about Race Condition
and Double Spending
.
this project mainly designed for exchange systems, but you can use it in any project.
Installation
after instaling composer package, if you use auto discovery for service providers, everything ok, but if you blocked
that just add this line to config/app.php
in providers
section:
after that you should run
and this:
it will create balance.php
file in your config file.
Usage
First of all, you should decide with currencies you want to have in your system, and consider a KEY for each currency and add those keys in balance.php config file
you can use this project with 2 strategy,Facade or Dependency injection!
I suggest to you to use it with dependecy injection for IDE auto complete feature but use it as you prefer!
after that you can get BalanceManager
from with these to methods:
Facade
you can get BalanceManager service like this:
Dependency Injection
you can get BalanceManager service from app()
like this:
or get from laravel automatic dependency injection
Methods
Get all balance for user
it will return array of Balance
model
Change balance of user
$balanceChangeResult= $balanceManager->changeBalanceByUserIdAndCurrency(
int $userId, //user id
string $currency, // like USDT, TMN
string $reason, // a unique string for each action
IBalanceHistoryRelated $model, // a model that is author of change balance
Decimal $valueChange, // value you want to add or sub from user balance
Decimal $lockedValueChange // in general usage it should be new \Decimal\Decimal(0)
);