-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #824 from bavix/docs-float
[docs] documentation of float wallets has been expanded
- Loading branch information
Showing
9 changed files
with
215 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
It is necessary to expand the model that will have the wallet. | ||
This is done in two stages: | ||
- Add `Wallet` interface; | ||
- Add the `HasWalletFloat` trait; | ||
|
||
Let's get started. | ||
```php | ||
use Bavix\Wallet\Traits\HasWalletFloat; | ||
use Bavix\Wallet\Interfaces\Wallet; | ||
|
||
class User extends Model implements Wallet | ||
{ | ||
use HasWalletFloat; | ||
} | ||
``` | ||
|
||
The model is prepared to work with a wallet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Deposit float | ||
|
||
A deposit is a sum of money which is part of the full price of something, | ||
and which you pay when you agree to buy it. | ||
|
||
In this case, the Deposit is the replenishment of the wallet. | ||
|
||
--- | ||
|
||
## User Model | ||
|
||
[User Simple](_include/models/user_simple_float.md ':include') | ||
|
||
## Make a Deposit | ||
|
||
Find user: | ||
|
||
```php | ||
$user = User::first(); | ||
``` | ||
|
||
As the user uses `HasWalletFloat`, he will have `balance` property. | ||
Check the user's balance. | ||
|
||
```php | ||
$user->balance; // 0 | ||
$user->balanceInt; // 0 | ||
$user->balanceFloatNum; // 0 | ||
``` | ||
|
||
The balance is zero, which is what we expected. | ||
|
||
```php | ||
$user->depositFloat(10.1); | ||
$user->balance; // 1010 | ||
$user->balanceInt; // 1010 | ||
$user->balanceFloatNum; // 10.1 | ||
``` | ||
|
||
Wow! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Transfer | ||
|
||
Transfer in our system are two well-known [Deposit](deposit-float) and [Withdraw](withdraw-float) | ||
operations that are performed in one transaction. | ||
|
||
The transfer takes place between wallets. | ||
|
||
--- | ||
|
||
## User Model | ||
|
||
[User Simple](_include/models/user_simple_float.md ':include') | ||
|
||
## Make a Transfer | ||
|
||
Find user: | ||
|
||
```php | ||
$first = User::first(); | ||
$last = User::orderBy('id', 'desc')->first(); // last user | ||
$first->getKey() !== $last->getKey(); // true | ||
``` | ||
|
||
As the user uses `HasWalletFloat`, he will have `balance` property. | ||
Check the user's balance. | ||
|
||
```php | ||
$fist->balanceFloatNum; // 100.00 | ||
$last->balanceFloatNum; // 0 | ||
``` | ||
|
||
The transfer will be from the first user to the second. | ||
|
||
```php | ||
$first->transferFloat($last, 5); | ||
$first->balanceFloatNum; // 95 | ||
$last->balanceFloatNum; // 5 | ||
``` | ||
|
||
It worked! | ||
|
||
## Force Transfer | ||
|
||
Check the user's balance. | ||
|
||
```php | ||
$first->balanceFloatNum; // 100 | ||
$last->balanceFloatNum; // 0 | ||
``` | ||
|
||
The transfer will be from the first user to the second. | ||
|
||
```php | ||
$first->forceTransferFloat($last, 500); | ||
$first->balanceFloatNum; // -400 | ||
$last->balanceFloatNum; // 500 | ||
``` | ||
|
||
It worked! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Withdraw | ||
|
||
When there is enough money in the account, you can transfer/withdraw | ||
it or buy something in the system. | ||
|
||
Since the currency is virtual, you can buy any services on your website. | ||
For example, priority in search results. | ||
|
||
--- | ||
|
||
## User Model | ||
|
||
[User Simple](_include/models/user_simple_float.md ':include') | ||
|
||
## Make a Withdraw | ||
|
||
Find user: | ||
|
||
```php | ||
$user = User::first(); | ||
``` | ||
|
||
As the user uses `HasWalletFloat`, he will have `balance` property. | ||
Check the user's balance. | ||
|
||
```php | ||
$user->balance; // 10000 | ||
$user->balanceInt; // 10000 | ||
$user->balanceFloatNum; // 100.00 | ||
``` | ||
|
||
The balance is not empty, so you can withdraw funds. | ||
|
||
```php | ||
$user->withdrawFloat(10); | ||
$user->balance; // 9000 | ||
$user->balanceInt; // 9000 | ||
$user->balanceFloatNum; // 90.00 | ||
``` | ||
|
||
It worked! | ||
|
||
## Force Withdraw | ||
|
||
Forced withdrawal is necessary for those cases when | ||
the user has no funds. For example, a fine for spam. | ||
|
||
```php | ||
$user->balanceFloatNum; // 90.00 | ||
$user->forceWithdrawFloat(101); | ||
$user->balanceFloatNum; // -11.00 | ||
``` | ||
|
||
## And what will happen if the money is not enough? | ||
|
||
There can be two situations: | ||
|
||
- The user's balance is zero, then we get an error | ||
`Bavix\Wallet\Exceptions\BalanceIsEmpty` | ||
- If the balance is greater than zero, but it is not enough | ||
`Bavix\Wallet\Exceptions\InsufficientFunds` |