Skip to content

Commit

Permalink
update docs. 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed May 2, 2022
1 parent 52ef08e commit d519758
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 41 deletions.
43 changes: 40 additions & 3 deletions docs/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,52 @@ class User extends Model implements Customer
}
```

Add the `HasWallet` trait and `Product` interface to `Item` model.
Add the `HasWallet` trait and interface to `Item` model.

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

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

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

Proceed to purchase.

```php
Expand Down
48 changes: 42 additions & 6 deletions docs/cart.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,77 @@ class User extends Model implements Customer

## Item Model

Add the `HasWallet` trait and `Product` interface to Item model.
Add the `HasWallet` trait and interface to `Item` model.

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* This is where you implement the constraint logic.
*
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
return true;
}

public function getAmountProduct(Customer $customer)
{
return round($this->price * 100);
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->getKey(),
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

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

## Fill the cart

Find the user and check the balance.
Expand Down
2 changes: 1 addition & 1 deletion docs/credit-limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ An example of working with a credit limit:
/**
* @var \Bavix\Wallet\Interfaces\Customer $customer
* @var \Bavix\Wallet\Models\Wallet $wallet
* @var \Bavix\Wallet\Interfaces\Product $product
* @var \Bavix\Wallet\Interfaces\ProductInterface $product
*/
$wallet = $customer->wallet; // get default wallet
$wallet->meta['credit'] = 10000; // credit limit
Expand Down
44 changes: 40 additions & 4 deletions docs/gift.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,58 @@ class User extends Model implements Customer

## Item Model

Add the `HasWallet` trait and `Product` interface to Item model.
Add the `HasWallet` trait and interface to `Item` model.

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* This is where you implement the constraint logic.
*
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
return true;
}

public function getAmountProduct(Customer $customer)
{
return 100;
Expand All @@ -51,6 +83,10 @@ class Item extends Model implements Product
}
```

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

## Santa Claus, give gifts

Find the user's and check the balance.
Expand Down
44 changes: 40 additions & 4 deletions docs/pay-free.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,58 @@ class User extends Model implements Customer

## Item Model

Add the `HasWallet` trait and `Product` interface to Item model.
Add the `HasWallet` trait and interface to `Item` model.

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* This is where you implement the constraint logic.
*
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
return true;
}

public function getAmountProduct(Customer $customer)
{
return 100;
Expand All @@ -51,6 +83,10 @@ class Item extends Model implements Product
}
```

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

## Pay Free

Find the user and check the balance.
Expand Down
44 changes: 40 additions & 4 deletions docs/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,58 @@ class User extends Model implements Customer

## Item Model

Add the `HasWallet` trait and `Product` interface to Item model.
Add the `HasWallet` trait and interface to `Item` model.

Starting from version 9.x there are two product interfaces:
- For an unlimited number of products (`ProductLimitedInterface`);
- For a limited number of products (`ProductInterface`);

An example with an unlimited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Product;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;

class Item extends Model implements Product
class Item extends Model implements ProductInterface
{
use HasWallet;

public function getAmountProduct(Customer $customer)
{
return 100;
}

public function getMetaProduct(): ?array
{
return [
'title' => $this->title,
'description' => 'Purchase of Product #' . $this->id,
];
}
}
```

Example with a limited number of products:
```php
use Bavix\Wallet\Traits\HasWallet;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductLimitedInterface;

class Item extends Model implements ProductLimitedInterface
{
use HasWallet;

public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool
{
/**
* This is where you implement the constraint logic.
*
* If the service can be purchased once, then
* return !$customer->paid($this);
*/
return true;
}

public function getAmountProduct(Customer $customer)
{
return 100;
Expand All @@ -51,6 +83,10 @@ class Item extends Model implements Product
}
```

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

## Proceed to purchase

Find the user and check the balance.
Expand Down
Loading

0 comments on commit d519758

Please sign in to comment.