Skip to content

Commit a6dfd91

Browse files
committed
update docs. 9.x
1 parent a87ba14 commit a6dfd91

File tree

8 files changed

+249
-41
lines changed

8 files changed

+249
-41
lines changed

docs/basic-usage.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,52 @@ class User extends Model implements Customer
4040
}
4141
```
4242

43-
Add the `HasWallet` trait and `Product` interface to `Item` model.
43+
Add the `HasWallet` trait and interface to `Item` model.
44+
45+
Starting from version 9.x there are two product interfaces:
46+
- For an unlimited number of products (`ProductLimitedInterface`);
47+
- For a limited number of products (`ProductInterface`);
48+
49+
An example with an unlimited number of products:
4450
```php
4551
use Bavix\Wallet\Traits\HasWallet;
46-
use Bavix\Wallet\Interfaces\Product;
4752
use Bavix\Wallet\Interfaces\Customer;
53+
use Bavix\Wallet\Interfaces\ProductInterface;
4854

49-
class Item extends Model implements Product
55+
class Item extends Model implements ProductInterface
56+
{
57+
use HasWallet;
58+
59+
public function getAmountProduct(Customer $customer)
60+
{
61+
return 100;
62+
}
63+
64+
public function getMetaProduct(): ?array
65+
{
66+
return [
67+
'title' => $this->title,
68+
'description' => 'Purchase of Product #' . $this->id,
69+
];
70+
}
71+
}
72+
```
73+
74+
Example with a limited number of products:
75+
```php
76+
use Bavix\Wallet\Traits\HasWallet;
77+
use Bavix\Wallet\Interfaces\Customer;
78+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
79+
80+
class Item extends Model implements ProductLimitedInterface
5081
{
5182
use HasWallet;
5283

5384
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
5485
{
5586
/**
87+
* This is where you implement the constraint logic.
88+
*
5689
* If the service can be purchased once, then
5790
* return !$customer->paid($this);
5891
*/
@@ -74,6 +107,10 @@ class Item extends Model implements Product
74107
}
75108
```
76109

110+
I do not recommend using the limited interface when working with a shopping cart.
111+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
112+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
113+
77114
Proceed to purchase.
78115

79116
```php

docs/cart.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,77 @@ class User extends Model implements Customer
1616

1717
## Item Model
1818

19-
Add the `HasWallet` trait and `Product` interface to Item model.
19+
Add the `HasWallet` trait and interface to `Item` model.
2020

21+
Starting from version 9.x there are two product interfaces:
22+
- For an unlimited number of products (`ProductLimitedInterface`);
23+
- For a limited number of products (`ProductInterface`);
24+
25+
An example with an unlimited number of products:
2126
```php
2227
use Bavix\Wallet\Traits\HasWallet;
23-
use Bavix\Wallet\Interfaces\Product;
2428
use Bavix\Wallet\Interfaces\Customer;
29+
use Bavix\Wallet\Interfaces\ProductInterface;
2530

26-
class Item extends Model implements Product
31+
class Item extends Model implements ProductInterface
32+
{
33+
use HasWallet;
34+
35+
public function getAmountProduct(Customer $customer)
36+
{
37+
return 100;
38+
}
39+
40+
public function getMetaProduct(): ?array
41+
{
42+
return [
43+
'title' => $this->title,
44+
'description' => 'Purchase of Product #' . $this->id,
45+
];
46+
}
47+
}
48+
```
49+
50+
Example with a limited number of products:
51+
```php
52+
use Bavix\Wallet\Traits\HasWallet;
53+
use Bavix\Wallet\Interfaces\Customer;
54+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
55+
56+
class Item extends Model implements ProductLimitedInterface
2757
{
2858
use HasWallet;
2959

3060
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
3161
{
3262
/**
63+
* This is where you implement the constraint logic.
64+
*
3365
* If the service can be purchased once, then
3466
* return !$customer->paid($this);
3567
*/
3668
return true;
3769
}
38-
70+
3971
public function getAmountProduct(Customer $customer)
4072
{
41-
return round($this->price * 100);
73+
return 100;
4274
}
4375

4476
public function getMetaProduct(): ?array
4577
{
4678
return [
4779
'title' => $this->title,
48-
'description' => 'Purchase of Product #' . $this->getKey(),
80+
'description' => 'Purchase of Product #' . $this->id,
4981
];
5082
}
5183
}
5284
```
5385

86+
I do not recommend using the limited interface when working with a shopping cart.
87+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
88+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
89+
5490
## Fill the cart
5591

5692
Find the user and check the balance.

docs/credit-limits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ An example of working with a credit limit:
1111
/**
1212
* @var \Bavix\Wallet\Interfaces\Customer $customer
1313
* @var \Bavix\Wallet\Models\Wallet $wallet
14-
* @var \Bavix\Wallet\Interfaces\Product $product
14+
* @var \Bavix\Wallet\Interfaces\ProductInterface $product
1515
*/
1616
$wallet = $customer->wallet; // get default wallet
1717
$wallet->meta['credit'] = 10000; // credit limit

docs/gift.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,58 @@ class User extends Model implements Customer
1616

1717
## Item Model
1818

19-
Add the `HasWallet` trait and `Product` interface to Item model.
19+
Add the `HasWallet` trait and interface to `Item` model.
2020

21+
Starting from version 9.x there are two product interfaces:
22+
- For an unlimited number of products (`ProductLimitedInterface`);
23+
- For a limited number of products (`ProductInterface`);
24+
25+
An example with an unlimited number of products:
2126
```php
2227
use Bavix\Wallet\Traits\HasWallet;
23-
use Bavix\Wallet\Interfaces\Product;
2428
use Bavix\Wallet\Interfaces\Customer;
29+
use Bavix\Wallet\Interfaces\ProductInterface;
2530

26-
class Item extends Model implements Product
31+
class Item extends Model implements ProductInterface
32+
{
33+
use HasWallet;
34+
35+
public function getAmountProduct(Customer $customer)
36+
{
37+
return 100;
38+
}
39+
40+
public function getMetaProduct(): ?array
41+
{
42+
return [
43+
'title' => $this->title,
44+
'description' => 'Purchase of Product #' . $this->id,
45+
];
46+
}
47+
}
48+
```
49+
50+
Example with a limited number of products:
51+
```php
52+
use Bavix\Wallet\Traits\HasWallet;
53+
use Bavix\Wallet\Interfaces\Customer;
54+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
55+
56+
class Item extends Model implements ProductLimitedInterface
2757
{
2858
use HasWallet;
2959

3060
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
3161
{
3262
/**
63+
* This is where you implement the constraint logic.
64+
*
3365
* If the service can be purchased once, then
3466
* return !$customer->paid($this);
3567
*/
3668
return true;
3769
}
38-
70+
3971
public function getAmountProduct(Customer $customer)
4072
{
4173
return 100;
@@ -51,6 +83,10 @@ class Item extends Model implements Product
5183
}
5284
```
5385

86+
I do not recommend using the limited interface when working with a shopping cart.
87+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
88+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
89+
5490
## Santa Claus, give gifts
5591

5692
Find the user's and check the balance.

docs/pay-free.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,58 @@ class User extends Model implements Customer
1616

1717
## Item Model
1818

19-
Add the `HasWallet` trait and `Product` interface to Item model.
19+
Add the `HasWallet` trait and interface to `Item` model.
2020

21+
Starting from version 9.x there are two product interfaces:
22+
- For an unlimited number of products (`ProductLimitedInterface`);
23+
- For a limited number of products (`ProductInterface`);
24+
25+
An example with an unlimited number of products:
2126
```php
2227
use Bavix\Wallet\Traits\HasWallet;
23-
use Bavix\Wallet\Interfaces\Product;
2428
use Bavix\Wallet\Interfaces\Customer;
29+
use Bavix\Wallet\Interfaces\ProductInterface;
2530

26-
class Item extends Model implements Product
31+
class Item extends Model implements ProductInterface
32+
{
33+
use HasWallet;
34+
35+
public function getAmountProduct(Customer $customer)
36+
{
37+
return 100;
38+
}
39+
40+
public function getMetaProduct(): ?array
41+
{
42+
return [
43+
'title' => $this->title,
44+
'description' => 'Purchase of Product #' . $this->id,
45+
];
46+
}
47+
}
48+
```
49+
50+
Example with a limited number of products:
51+
```php
52+
use Bavix\Wallet\Traits\HasWallet;
53+
use Bavix\Wallet\Interfaces\Customer;
54+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
55+
56+
class Item extends Model implements ProductLimitedInterface
2757
{
2858
use HasWallet;
2959

3060
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
3161
{
3262
/**
63+
* This is where you implement the constraint logic.
64+
*
3365
* If the service can be purchased once, then
3466
* return !$customer->paid($this);
3567
*/
3668
return true;
3769
}
38-
70+
3971
public function getAmountProduct(Customer $customer)
4072
{
4173
return 100;
@@ -51,6 +83,10 @@ class Item extends Model implements Product
5183
}
5284
```
5385

86+
I do not recommend using the limited interface when working with a shopping cart.
87+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
88+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
89+
5490
## Pay Free
5591

5692
Find the user and check the balance.

docs/payment.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,58 @@ class User extends Model implements Customer
1616

1717
## Item Model
1818

19-
Add the `HasWallet` trait and `Product` interface to Item model.
19+
Add the `HasWallet` trait and interface to `Item` model.
2020

21+
Starting from version 9.x there are two product interfaces:
22+
- For an unlimited number of products (`ProductLimitedInterface`);
23+
- For a limited number of products (`ProductInterface`);
24+
25+
An example with an unlimited number of products:
2126
```php
2227
use Bavix\Wallet\Traits\HasWallet;
23-
use Bavix\Wallet\Interfaces\Product;
2428
use Bavix\Wallet\Interfaces\Customer;
29+
use Bavix\Wallet\Interfaces\ProductInterface;
2530

26-
class Item extends Model implements Product
31+
class Item extends Model implements ProductInterface
32+
{
33+
use HasWallet;
34+
35+
public function getAmountProduct(Customer $customer)
36+
{
37+
return 100;
38+
}
39+
40+
public function getMetaProduct(): ?array
41+
{
42+
return [
43+
'title' => $this->title,
44+
'description' => 'Purchase of Product #' . $this->id,
45+
];
46+
}
47+
}
48+
```
49+
50+
Example with a limited number of products:
51+
```php
52+
use Bavix\Wallet\Traits\HasWallet;
53+
use Bavix\Wallet\Interfaces\Customer;
54+
use Bavix\Wallet\Interfaces\ProductLimitedInterface;
55+
56+
class Item extends Model implements ProductLimitedInterface
2757
{
2858
use HasWallet;
2959

3060
public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
3161
{
3262
/**
63+
* This is where you implement the constraint logic.
64+
*
3365
* If the service can be purchased once, then
3466
* return !$customer->paid($this);
3567
*/
3668
return true;
3769
}
38-
70+
3971
public function getAmountProduct(Customer $customer)
4072
{
4173
return 100;
@@ -51,6 +83,10 @@ class Item extends Model implements Product
5183
}
5284
```
5385

86+
I do not recommend using the limited interface when working with a shopping cart.
87+
If you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface.
88+
With it, you can check the availability of all products with one request, there will be no N-queries in the database.
89+
5490
## Proceed to purchase
5591

5692
Find the user and check the balance.

0 commit comments

Comments
 (0)