Skip to content

Commit 554aaee

Browse files
committed
micro-example
1 parent c4cad06 commit 554aaee

File tree

1 file changed

+13
-65
lines changed

1 file changed

+13
-65
lines changed

docs/confirm.md

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,31 @@
11
## User Model
22

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.
3+
Add the `CanConfirm` trait and `Confirmable` interface to your User model.
184

195
```php
6+
use Bavix\Wallet\Interfaces\Confirmable;
7+
use Bavix\Wallet\Interfaces\Wallet;
8+
use Bavix\Wallet\Traits\CanConfirm;
209
use Bavix\Wallet\Traits\HasWallet;
21-
use Bavix\Wallet\Interfaces\Product;
22-
use Bavix\Wallet\Interfaces\Customer;
2310

24-
class Item extends Model implements Product
11+
class UserConfirm extends Model implements Wallet, Confirmable
2512
{
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-
}
13+
use HasWallet, CanConfirm;
5514
}
5615
```
5716

58-
## Make a refund
59-
60-
Find the user and check the balance.
17+
### Example:
6118

6219
```php
63-
$user = User::first();
6420
$user->balance; // int(0)
65-
```
66-
67-
Find the goods and check the balance.
68-
69-
```php
70-
$item = Item::first();
71-
$item->balance; // int(100)
72-
```
21+
$transaction = $user->deposit(100, null, false); // not confirm
22+
$transaction->confirmed; // bool(false)
23+
$user->balance; // int(0)
7324

74-
Return of funds!
25+
$user->confirm($transaction); // bool(true)
26+
$transaction->confirmed; // bool(true)
7527

76-
```php
77-
(bool)$user->paid($item); // bool(true)
78-
(bool)$user->refund($item); // bool(true)
79-
$item->balance; // int(0)
80-
$user->balance; // int(100)
28+
$user->balance; // int(100)
8129
```
8230

8331
It worked!

0 commit comments

Comments
 (0)