You can manage your user withdraw
and deposit
in your website with this package
composer require iamamirsalehi/laravel-balance
after installation publish needed files:
php artisan vendor:publish --provider="Iamamirsalehi\LaravelBalance\LaravelBalanceServiceProvider"
and run the migrations
php artisan migrate
- Deposit
- Withdraw unconfirmed yet
- Withdraw confirmed
- Rejected withdraw
- pend order
- execute order
- cancel order
use Iamamirsalehi\LaravelBalance\Services\Balance\BalanceService;
BalanceService::deposit([
'user_id' => 1,
'coin_id' => 1,
'price' => 300000
]);
as you can see you have three parameters to pass, the second one is might be confusing, coin_id
is actually the coin
to deposit and withdraw.
When actually user wants to withdraw, the user must ask his withdraw then admin can confirm
or reject the request.
So when user wants to have a withdraw, user should send the request like below with withdrawUnconfirmedyet
method.
use Iamamirsalehi\LaravelBalance\Services\Balance\BalanceService;
BalanceService::withdrawUnconfirmedyet([
'user_id' => 1,
'coin_id' => 1,
'price' => 500000
])->handle();
You can confirm withdraw with withdrawconfirmed
method
use Iamamirsalehi\LaravelBalance\Services\Balance\BalanceService;
BalanceService::withdrawconfirmed([
'user_id' => 1,
'coin_id' => 1,
'withdraw_id' => 1
])->handle();
Easily with rejectedWithdraw
method
use Iamamirsalehi\LaravelBalance\Services\Balance\BalanceService;
BalanceService::rejectedWithdraw([
'user_id' => 1,
'coin_id' => 1,
'withdraw_id' => 1
])->handle();
Coin code
The coin that is selected to done the action
Action code
Type of transaction
Action 1 (C)
Has direct effect on Asset (D)
Asset (D)
The amount of money that user has, the formula to calculate is D(n)=C(n)+D(n-1)
Action 2 (E)
Has direct effect on Liability (F)
Liability (F)
The amount of user blocked money, the formula to calculate is F(n)=E(n)+F(n-1)
Free balance
The free balance that user can deposit and withdraw, the formula to calculate G(n)=D(n)-F(n)
Coin code (A) | Action code (B) | Action 1 (C) | Asset (D) | Action 2 (E) | Liability (F) | Free balance (G) |
---|---|---|---|---|---|---|
7(TRX) | Deposit | 10 | 10 | 0 | 0 | 10 |
7(TRX) | Withdraw unconfirmed yet | 0 | 10 | 5 | 5 | 5 |
7(TRX) | Withdraw confirmed | -5 | 5 | -5 | 0 | 5 |
7(TRX) | Withdraw unconfirmed yet | 0 | 5 | 2 | 2 | 3 |
7(TRX) | Rejected withdraw | 0 | 5 | -2 | 0 | 5 |
7(TRX) | pend order | 0 | 5 | 2 | 2 | 3 |
7(TRX) | execute order | -2 | 3 | -2 | 0 | 3 |
7(TRX) | pend order | 0 | 3 | 2 | 2 | 1 |
7(TRX) | cancel order | 0 | 3 | -2 | 0 | 3 |
Action code | Action 1 | Action 2 |
---|---|---|
Deposit | (+x) | null |
Withdraw unconfirmed yet | null | (+x) |
Withdraw confirmed | (-x) | (-x) |
Rejected withdraw | null | (-x) |
pend order | null | (+x) |
execute order | (-x) | (-x) |
cancel order | null | (-x) |