Skip to content

Commit dae3769

Browse files
committed
add docs
1 parent e96ac5e commit dae3769

File tree

5 files changed

+289
-5
lines changed

5 files changed

+289
-5
lines changed

docs/_sidebar.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- [Transfer](transfer)
1414
- [Refresh balance](refresh)
1515
- [Confirm](confirm)
16-
- [Exchange](exchange)
16+
<!-- - [Exchange](exchange)-->
1717
- [Withdraw taxing](taxing)
1818

1919
- Purchases
@@ -29,8 +29,8 @@
2929
- [New Wallet](new-wallet)
3030
- [Transfer](wallet-transfer)
3131

32-
- Currencies
32+
<!--- Currencies-->
3333

34-
- [Rate Service](rate)
35-
- [Create Wallet](rate-wallet)
36-
- [Taxing](rate-taxing)
34+
<!-- - [Rate Service](rate)-->
35+
<!-- - [Create Wallet](rate-wallet)-->
36+
<!-- - [Taxing](rate-taxing)-->

docs/confirm.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class UserConfirm extends Model implements Wallet, Confirmable
1616

1717
### Example:
1818

19+
Sometimes you need to create an operation and confirm its field.
20+
That is what this trey does.
21+
1922
```php
2023
$user->balance; // int(0)
2124
$transaction = $user->deposit(100, null, false); // not confirm

docs/exchange.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Exchange
2+
3+
A description of this feature will appear later. Wait!
4+
For now you can study to see the code in the unit test.

docs/gift.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## User Model
2+
3+
Add the `CanPay` trait and `Customer` interface to your User model.
4+
5+
```php
6+
use Bavix\Wallet\Traits\CanPay;
7+
use Bavix\Wallet\Interfaces\Customer;
8+
9+
class User extends Model implements Customer
10+
{
11+
use CanPay;
12+
}
13+
```
14+
15+
## Item Model
16+
17+
Add the `HasWallet` trait and `Product` interface to Item model.
18+
19+
```php
20+
use Bavix\Wallet\Traits\HasWallet;
21+
use Bavix\Wallet\Interfaces\Product;
22+
use Bavix\Wallet\Interfaces\Customer;
23+
24+
class Item extends Model implements Product
25+
{
26+
use HasWallet;
27+
28+
public function canBuy(Customer $customer, int $quantity = 1, bool $force = null): bool
29+
{
30+
/**
31+
* If the service can be purchased once, then
32+
* return !$customer->paid($this);
33+
*/
34+
return true;
35+
}
36+
37+
public function getAmountProduct(): int
38+
{
39+
return 100;
40+
}
41+
42+
public function getMetaProduct(): ?array
43+
{
44+
return [
45+
'title' => $this->title,
46+
'description' => 'Purchase of Product #' . $this->id,
47+
'price' => $this->getAmountProduct(),
48+
];
49+
}
50+
51+
public function getUniqueId(): string
52+
{
53+
return (string)$this->getKey();
54+
}
55+
}
56+
```
57+
58+
## Santa Claus, give gifts
59+
60+
Find the user's and check the balance.
61+
62+
```php
63+
$first = User::first();
64+
$last = User::orderBy('id', 'desc')->first(); // last user
65+
$first->getKey() !== $last->getKey(); // true
66+
67+
$first->balance; // int(115)
68+
$last->balance; // int(0)
69+
```
70+
71+
One user wants to give a gift to another.
72+
Find the product.
73+
74+
```php
75+
$item = Item::first();
76+
$item->getAmountProduct(); // int(100)
77+
$item->balance; // int(0)
78+
```
79+
80+
The first user buys the product and gives it.
81+
82+
```php
83+
$first->gift($last, $item);
84+
(bool)$last->paid($item, true); // bool(true)
85+
$first->balance; // int(15)
86+
$last->balance; // int(0)
87+
$item->balance; // int(100)
88+
```
89+
90+
It worked!

docs/taxing.md

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

0 commit comments

Comments
 (0)