Skip to content

Commit 36c237d

Browse files
committed
[10.x] update docs
1 parent b458f63 commit 36c237d

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Purchases
3636

3737
- [Payment](payment)
38+
- [Payment to a custom wallet](payment-custom-wallet)
3839
- [Payment Free](pay-free)
3940
- [Refund](refund)
4041
- [Gift](gift)

docs/batch-transactions.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ app(AtomicServiceInterface::class)->blocks($wallets, function () use ($wallets,
9090
});
9191
```
9292

93+
---
94+
95+
In version 10.x, it became possible to create transactions with a given uuid (generate on the client side).
96+
The main thing is to keep uniqueness.
97+
98+
```php
99+
use Bavix\Wallet\External\Api\TransactionQuery;
100+
101+
TransactionQuery::createDeposit($wallet, $amount, null, uuid: '5f7820d1-1e82-4d03-9414-05d0c44da9a1')
102+
TransactionQuery::createWithdraw($wallet, $amount, null, uuid: '6e87dbf2-7be7-48c2-b688-f46ba4e25786')
103+
```
104+
93105
---
94106
It worked!
95107

docs/batch-transfers.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ app(TransferQueryHandlerInterface::class)->apply(
3030

3131
The package will optimize queries and execute them in a single transaction. I strongly advise against creating large packs, because. this can lead to a large increase in request queuing.
3232

33+
---
34+
35+
In version 10.x, it became possible to create transactions&transfers with a given uuid (generate on the client side).
36+
The main thing is to keep uniqueness.
37+
38+
```php
39+
use Bavix\Wallet\External\Api\TransferQuery;
40+
41+
new TransferQuery($from, $wallet, $amount, new \Bavix\Wallet\External\Dto\Extra(
42+
deposit: new \Bavix\Wallet\External\Dto\Option(
43+
null,
44+
uuid: '71cecafe-da10-464f-9e00-c80437bb4c3e', // deposit transaction
45+
),
46+
withdraw: new \Bavix\Wallet\External\Dto\Option(
47+
null,
48+
uuid: '3805730b-39a1-419d-8715-0b7cc3f1ffc2', // withdraw transaction
49+
),
50+
uuid: 'f8becf81-3993-43d7-81f1-7a725c72e976', // transfer uuid
51+
))
52+
```
53+
3354
---
3455
It worked!
3556

docs/payment-custom-wallet.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
## User Model
2+
3+
Add the `CanPay` trait and `Customer` interface to your User model.
4+
5+
> The trait `CanPay` already inherits `HasWallet`, reuse will cause an error.
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+
Add the `HasWallet` trait and interface to `Item` model.
20+
If we want to achieve multi wallets for a product, then we need to add `HasWallets`.
21+
22+
Starting from version 9.x there are two product interfaces:
23+
- For an unlimited number of products (`ProductInterface`);
24+
- For a limited number of products (`ProductLimitedInterface`);
25+
26+
An example with an unlimited number of products:
27+
```php
28+
use Bavix\Wallet\Traits\HasWallet;
29+
use Bavix\Wallet\Traits\HasWallets;
30+
use Bavix\Wallet\Interfaces\Customer;
31+
use Bavix\Wallet\Interfaces\ProductInterface;
32+
33+
class Item extends Model implements ProductInterface
34+
{
35+
use HasWallet, HasWallets;
36+
37+
public function getAmountProduct(Customer $customer): int|string
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+
];
48+
}
49+
}
50+
```
51+
52+
Example with a limited number of products:
53+
```php
54+
use Bavix\Wallet\Traits\HasWallet;
55+
use Bavix\Wallet\Traits\HasWallets;
56+
use Bavix\Wallet\Interfaces\Customer;
57+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
58+
59+
class Item extends Model implements ProductLimitedInterface
60+
{
61+
use HasWallet, HasWallets;
62+
63+
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
64+
{
65+
return true;
66+
}
67+
68+
public function getAmountProduct(Customer $customer): int|string
69+
{
70+
return 100;
71+
}
72+
73+
public function getMetaProduct(): ?array
74+
{
75+
return [
76+
'title' => $this->title,
77+
'description' => 'Purchase of Product #' . $this->id,
78+
];
79+
}
80+
}
81+
```
82+
83+
I do not recommend using the limited interface when working with a shopping cart.
84+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
85+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
86+
87+
## Proceed to purchase
88+
89+
Find the user and check the balance.
90+
91+
```php
92+
$user = User::first();
93+
$user->balance; // 100
94+
```
95+
96+
Find the goods and check the cost.
97+
98+
```php
99+
$item = Item::first();
100+
$item->getAmountProduct($user); // 100
101+
102+
$receiving = $item->createWallet([
103+
'name' => 'Dollar',
104+
'meta' => [
105+
'currency' => 'USD',
106+
],
107+
]);
108+
```
109+
110+
The user can buy a product, buy...
111+
112+
```php
113+
$cart = app(Cart::class)
114+
->withItem($item, receiving: $receiving)
115+
;
116+
117+
$user->payCart($cart);
118+
$user->balance; // 0
119+
120+
$receiving->balanceInt; // $100
121+
```
122+
123+
It worked!

docs/upgrade-guide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,10 @@ The product has been divided into two interfaces:
248248
The old Product interface should be replaced with one of these.
249249

250250
Replace `Bavix\Wallet\Interfaces\Product` to `Bavix\Wallet\Interfaces\ProductLimitedInterface`.
251+
252+
## 9.x.x → 10.0.x
253+
254+
1. If you have a custom BookkeeperServiceInterface, then you need to update the contract.
255+
2. If you catch a LockProviderNotFoundException, then you need to remove the check. This exception no longer exists.
256+
3. If you have specific requests for transfers using the MorphMany relation, then you need to rewrite it to the HasMany relation.
257+

0 commit comments

Comments
 (0)