Skip to content

Commit 89139a3

Browse files
author
Babichev Maxim
committed
update docs
1 parent 91dd4ef commit 89139a3

File tree

7 files changed

+364
-4
lines changed

7 files changed

+364
-4
lines changed

docs/gift.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ $item->balance; // int(0)
8181

8282
The first user buys the product and gives it.
8383

84+
> If the product uses the `Taxable` interface, then Santa will pay tax
85+
8486
```php
8587
$first->gift($last, $item);
8688
(bool)$last->paid($item, true); // bool(true)

docs/ru/_sidebar.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [Введение](README)
44
- [Требования](requirements)
55
- [Установка](installation)
6-
- [Lumen installation](lumen)
6+
- [Установка в Lumen](lumen)
77
- [Как использовать](basic-usage)
88
- [Обновление](upgrade-guide)
99

@@ -13,9 +13,9 @@
1313
- [Вывод](withdraw)
1414
- [Перевод](transfer)
1515
- [Пересчёт баланса](refresh)
16-
- [Confirm](confirm)
16+
- [Подтверждение](confirm)
1717
- [Exchange](exchange)
18-
- [Withdraw taxing](taxing)
18+
- [Налог на списание](taxing)
1919

2020
- Покупки
2121

docs/ru/confirm.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## User Model
2+
3+
Добавьте `CanConfirm` trait и `Confirmable` interface в модель User.
4+
5+
```php
6+
use Bavix\Wallet\Interfaces\Confirmable;
7+
use Bavix\Wallet\Interfaces\Wallet;
8+
use Bavix\Wallet\Traits\CanConfirm;
9+
use Bavix\Wallet\Traits\HasWallet;
10+
11+
class UserConfirm extends Model implements Wallet, Confirmable
12+
{
13+
use HasWallet, CanConfirm;
14+
}
15+
```
16+
17+
### Example:
18+
19+
Иногда, необходимо подтвердить операцию и пересчитать баланс.
20+
Теперь это доступно в библиотеке из каробки. Вот пример:
21+
22+
```php
23+
$user->balance; // int(0)
24+
$transaction = $user->deposit(100, null, false); // не подтверждена
25+
$transaction->confirmed; // bool(false)
26+
$user->balance; // int(0)
27+
28+
$user->confirm($transaction); // bool(true)
29+
$transaction->confirmed; // bool(true)
30+
31+
$user->balance; // int(100)
32+
```
33+
34+
Это работает!

docs/ru/gift.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
## User Model
2+
3+
Добавим `CanPay` trait и `Customer` interface в модель User.
4+
5+
> Трейт `CanPay` уже наследует `HasWallet`, повторное использование вызовет ошибку.
6+
7+
```php
8+
use Bavix\Wallet\Traits\CanPay;
9+
use Bavix\Wallet\Interfaces\Customer;
10+
11+
class User extends Model implements Customer
12+
{
13+
use CanPay;
14+
}
15+
```
16+
17+
## Item Model
18+
19+
Добавим `HasWallet` trait и `Product` interface в модель Item.
20+
21+
```php
22+
use Bavix\Wallet\Traits\HasWallet;
23+
use Bavix\Wallet\Interfaces\Product;
24+
use Bavix\Wallet\Interfaces\Customer;
25+
26+
class Item extends Model implements Product
27+
{
28+
use HasWallet;
29+
30+
public function canBuy(Customer $customer, int $quantity = 1, bool $force = null): bool
31+
{
32+
/**
33+
* If the service can be purchased once, then
34+
* return !$customer->paid($this);
35+
*/
36+
return true;
37+
}
38+
39+
public function getAmountProduct(): int
40+
{
41+
return 100;
42+
}
43+
44+
public function getMetaProduct(): ?array
45+
{
46+
return [
47+
'title' => $this->title,
48+
'description' => 'Purchase of Product #' . $this->id,
49+
'price' => $this->getAmountProduct(),
50+
];
51+
}
52+
53+
public function getUniqueId(): string
54+
{
55+
return (string)$this->getKey();
56+
}
57+
}
58+
```
59+
60+
## Дед мороз, дарит подарки
61+
62+
Находим дедушку мороза и счастливчика.
63+
64+
```php
65+
$first = User::first();
66+
$last = User::orderBy('id', 'desc')->first(); // last user
67+
$first->getKey() !== $last->getKey(); // true
68+
69+
$first->balance; // int(115)
70+
$last->balance; // int(0)
71+
```
72+
73+
У дедушки есть деньги на подарок.
74+
Находим сам подарок (товар).
75+
76+
```php
77+
$item = Item::first();
78+
$item->getAmountProduct(); // int(100)
79+
$item->balance; // int(0)
80+
```
81+
82+
Дедушка мороз дарит подарок "ребёнку".
83+
84+
> Если товар использует `Taxable` интерфейс, то дедушка заплатит налог
85+
86+
```php
87+
$first->gift($last, $item);
88+
(bool)$last->paid($item, true); // bool(true)
89+
$first->balance; // int(15)
90+
$last->balance; // int(0)
91+
$item->balance; // int(100)
92+
```
93+
94+
Это работает!

docs/ru/lumen.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Composer
2+
3+
Рекомендуем установку используя [Composer](https://getcomposer.org/).
4+
5+
В корне вашего проекта запустите:
6+
7+
```bash
8+
composer req bavix/laravel-wallet
9+
```
10+
11+
Убедитесь, что проект настроен на [autoload Composer-installed packages](https://getcomposer.org/doc/01-basic-usage.md#autoloading).
12+
13+
## Добавьте сервис-провайдер в приложение
14+
15+
[Editing the application file](https://lumen.laravel.com/docs/5.8/providers#registering-providers) `bootstrap/app.php`
16+
```php
17+
$app->register(\Bavix\Wallet\WalletServiceProvider::class);
18+
```
19+
20+
Запустите миграцию и используйте библиотеку.
21+
22+
## Если вам нужна кастомизация
23+
24+
Иногда это полезно...
25+
26+
### Миграции
27+
Опубликуйте миграции с помощью этой команды artisan:
28+
```bash
29+
php artisan vendor:publish --tag=laravel-wallet-migrations
30+
```
31+
32+
### Конфигурации
33+
Файл конфигурации можно опубликовать с помощью этой команды artisan:
34+
```bash
35+
php artisan vendor:publish --tag=laravel-wallet-config
36+
```
37+
38+
После установки пакета можно перейти к [использованию](basic-usage).

docs/ru/taxing.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
## User Model
2+
3+
Добавим `CanPay` trait и `Customer` interface в модель User.
4+
5+
> Трейт `CanPay` уже наследует `HasWallet`, повторное использование вызовет ошибку.
6+
7+
```php
8+
use Bavix\Wallet\Traits\CanPay;
9+
use Bavix\Wallet\Interfaces\Customer;
10+
11+
class User extends Model implements Customer
12+
{
13+
use CanPay;
14+
}
15+
```
16+
17+
## Item Model
18+
19+
Добавим `HasWallet` trait и `Product` interface в модель Item.
20+
21+
```php
22+
use Bavix\Wallet\Traits\HasWallet;
23+
use Bavix\Wallet\Interfaces\Product;
24+
use Bavix\Wallet\Interfaces\Customer;
25+
use Bavix\Wallet\Interfaces\Taxable;
26+
27+
class Item extends Model implements Product, Taxable
28+
{
29+
use HasWallet;
30+
31+
public function canBuy(Customer $customer, int $quantity = 1, bool $force = null): bool
32+
{
33+
/**
34+
* If the service can be purchased once, then
35+
* return !$customer->paid($this);
36+
*/
37+
return true;
38+
}
39+
40+
public function getAmountProduct(): int
41+
{
42+
return 100;
43+
}
44+
45+
public function getMetaProduct(): ?array
46+
{
47+
return [
48+
'title' => $this->title,
49+
'description' => 'Purchase of Product #' . $this->id,
50+
'price' => $this->getAmountProduct(),
51+
];
52+
}
53+
54+
public function getUniqueId(): string
55+
{
56+
return (string)$this->getKey();
57+
}
58+
59+
public function getFeePercent() : float
60+
{
61+
return 0.03; // 3%
62+
}
63+
}
64+
```
65+
66+
## Оплата с налогом
67+
68+
Находим пользователя и проверяем его баланс.
69+
70+
```php
71+
$user = User::first();
72+
$user->balance; // int(103)
73+
```
74+
75+
Деньги есть, это хорошо. Проверим стоимость товара.
76+
77+
```php
78+
$item = Item::first();
79+
$item->getAmountProduct(); // int(100)
80+
```
81+
82+
Товар стоит 100 бубликов. Значит налог составит 3 бублика.
83+
Пользователю хватает средств для покупки товара.
84+
85+
```php
86+
$user->pay($item); // success, 100 (product) + 3 (fee) = 103
87+
$user->balance; // int(0)
88+
```
89+
90+
## Минимальный налог
91+
92+
Добавим trait `MinimalTaxable` в модель `Item`.
93+
94+
```php
95+
use Bavix\Wallet\Traits\HasWallet;
96+
use Bavix\Wallet\Interfaces\Product;
97+
use Bavix\Wallet\Interfaces\Customer;
98+
use Bavix\Wallet\Interfaces\MinimalTaxable;
99+
100+
class Item extends Model implements Product, MinimalTaxable
101+
{
102+
use HasWallet;
103+
104+
public function canBuy(Customer $customer, int $quantity = 1, bool $force = null): bool
105+
{
106+
/**
107+
* If the service can be purchased once, then
108+
* return !$customer->paid($this);
109+
*/
110+
return true;
111+
}
112+
113+
public function getAmountProduct(): int
114+
{
115+
return 100;
116+
}
117+
118+
public function getMetaProduct(): ?array
119+
{
120+
return [
121+
'title' => $this->title,
122+
'description' => 'Purchase of Product #' . $this->id,
123+
'price' => $this->getAmountProduct(),
124+
];
125+
}
126+
127+
public function getUniqueId(): string
128+
{
129+
return (string)$this->getKey();
130+
}
131+
132+
public function getFeePercent() : float
133+
{
134+
return 0.03; // 3%
135+
}
136+
137+
public function getMinimalFee() : int
138+
{
139+
return 5; // 3%, minimum int(5)
140+
}
141+
}
142+
```
143+
144+
#### Успешная операция
145+
146+
Находим пользователя и проверяем баланс.
147+
148+
```php
149+
$user = User::first();
150+
$user->balance; // int(105)
151+
```
152+
153+
Денег хватает, проверяем стоимость товара.
154+
155+
```php
156+
$item = Item::first();
157+
$item->getAmountProduct(); // int(100)
158+
```
159+
160+
Налог 3%, а минимальный налог составляет 5 бубликов.
161+
Нашему пользователю хватает средств для покупки товара.
162+
163+
```php
164+
$user->pay($item); // успешно, 100 (product) + 5 (minimal fee) = 105
165+
$user->balance; // int(0)
166+
```
167+
168+
#### Ошибочная операция
169+
170+
Находим пользователя и проверяем баланс.
171+
172+
```php
173+
$user = User::first();
174+
$user->balance; // int(103)
175+
```
176+
177+
Находим товар.
178+
179+
```php
180+
$item = Item::first();
181+
$item->getAmountProduct(); // int(100)
182+
```
183+
184+
Налог составит 5 бубликов, а у пользователя только 103 бублика.
185+
Возникнет ошибка при попытке оплаты, воспользуемся `safePay` чтобы это проверить.
186+
187+
```php
188+
$user->safePay($item); // ошибка, 100 (product) + 5 (minimal fee) = 105
189+
$user->balance; // int(103)
190+
```
191+
192+
Это работает!

0 commit comments

Comments
 (0)