@@ -28,22 +28,22 @@ laravel-wallet - Easy work with virtual wallet.
2828
2929### Support Policy
3030
31- | Version | Laravel | PHP | Fixes |
32- | ------------| ----------------| -----------| ------------|
33- | 7.x | ^6.0,^7.0,^8.0 | ^ 7.4,^ 8.0 | 6 Sep 2022 |
34- | 8.x | ^9.0 | ^ 8.0 | 1 Jun 2022 |
35- | 9.x [ LTS] | ^9.0 | ^ 8.0 | 8 Aug 2023 |
31+ | Version | Laravel | PHP | End of improvements | End of support |
32+ | ------------| ----------------| ------------- | --------------------- | ---- ------------|
33+ | 7.x | ^6.0,^7.0,^8.0 | 7.4,8.0,8.1 | 1 Mar 2022 | 6 Sep 2022 |
34+ | 8.x | ^9.0 | 8.0,8.1 | 1 May 2022 | 1 Jun 2022 |
35+ | 9.x [ LTS] | ^9.0 | 8.0,8.1 | 1 Feb 2023 | 6 Nov 2023 |
3636
3737### Upgrade Guide
3838
3939To perform the migration, you will be [ helped by the instruction] ( https://bavix.github.io/laravel-wallet/#/upgrade-guide ) .
4040
4141### Extensions
4242
43- | Extension | Description |
44- | ----- | ----- |
45- | [ Swap] ( https://github.com/bavix/laravel-wallet-swap ) | Addition to the laravel-wallet library for quick setting of exchange rates |
46- | [ Warm Up] ( https://github.com/bavix/laravel-wallet-warmup ) | Addition to the laravel-wallet library for refresh balance wallets |
43+ | Extension | Description |
44+ | ----------------------------------------------------------- | ---------------------------------------------------------------------------- |
45+ | [ Swap] ( https://github.com/bavix/laravel-wallet-swap ) | Addition to the laravel-wallet library for quick setting of exchange rates |
46+ | [ Warm Up] ( https://github.com/bavix/laravel-wallet-warmup ) | Addition to the laravel-wallet library for refresh balance wallets |
4747
4848### Usage
4949Add the ` HasWallet ` trait and ` Wallet ` interface to model.
@@ -87,19 +87,52 @@ class User extends Model implements Customer
8787}
8888```
8989
90- Add the ` HasWallet ` trait and ` Product ` interface to ` Item ` model.
90+ Add the ` HasWallet ` trait and interface to ` Item ` model.
91+
92+ Starting from version 9.x there are two product interfaces:
93+ - For an unlimited number of products (` ProductLimitedInterface ` );
94+ - For a limited number of products (` ProductInterface ` );
95+
96+ An example with an unlimited number of products:
97+ ``` php
98+ use Bavix\Wallet\Traits\HasWallet;
99+ use Bavix\Wallet\Interfaces\Customer;
100+ use Bavix\Wallet\Interfaces\ProductInterface;
101+
102+ class Item extends Model implements ProductInterface
103+ {
104+ use HasWallet;
105+
106+ public function getAmountProduct(Customer $customer)
107+ {
108+ return 100;
109+ }
110+
111+ public function getMetaProduct(): ?array
112+ {
113+ return [
114+ 'title' => $this->title,
115+ 'description' => 'Purchase of Product #' . $this->id,
116+ ];
117+ }
118+ }
119+ ```
120+
121+ Example with a limited number of products:
91122``` php
92123use Bavix\Wallet\Traits\HasWallet;
93- use Bavix\Wallet\Interfaces\Product;
94124use Bavix\Wallet\Interfaces\Customer;
125+ use Bavix\Wallet\Interfaces\ProductLimitedInterface;
95126
96- class Item extends Model implements Product
127+ class Item extends Model implements ProductLimitedInterface
97128{
98129 use HasWallet;
99130
100131 public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
101132 {
102133 /**
134+ * This is where you implement the constraint logic.
135+ *
103136 * If the service can be purchased once, then
104137 * return !$customer->paid($this);
105138 */
@@ -121,6 +154,10 @@ class Item extends Model implements Product
121154}
122155```
123156
157+ I do not recommend using the limited interface when working with a shopping cart.
158+ If you are working with a shopping cart, then you should override the ` PurchaseServiceInterface ` interface.
159+ With it, you can check the availability of all products with one request, there will be no N-queries in the database.
160+
124161Proceed to purchase.
125162
126163``` php
@@ -132,7 +169,7 @@ $user->pay($item); // If you do not have enough money, throw an exception
132169var_dump($user->balance); // 0
133170
134171if ($user->safePay($item)) {
135- // try to buy again )
172+ // try to buy again
136173}
137174
138175var_dump((bool)$user->paid($item)); // bool(true)
@@ -144,7 +181,11 @@ var_dump((bool)$user->paid($item)); // bool(false)
144181### Eager Loading
145182
146183``` php
184+ // When working with one wallet
147185User::with('wallet');
186+
187+ // When using the multi-wallet functionality
188+ User::with('wallets');
148189```
149190
150191### How to work with fractional numbers?
0 commit comments