Skip to content

Commit 5ece3f1

Browse files
author
Babichev Maxim
committed
update method pay
1 parent cefcdd2 commit 5ece3f1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Exceptions/ProductEnded.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Bavix\Wallet\Exceptions;
4+
5+
class ProductEnded extends \LogicException
6+
{
7+
8+
}

src/Traits/CanBePaid.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bavix\Wallet\Traits;
44

5+
use Bavix\Wallet\Exceptions\ProductEnded;
56
use Bavix\Wallet\Interfaces\Product;
67
use Bavix\Wallet\Models\Transfer;
78
use Illuminate\Database\Eloquent\Model;
@@ -21,6 +22,10 @@ trait CanBePaid
2122
*/
2223
public function pay(Product $product): Transfer
2324
{
25+
if (!$product->canBuy()) {
26+
throw new ProductEnded('The product is out of stock');
27+
}
28+
2429
return $this->transfer($product, $product->getAmountProduct(), $product->getMetaProduct());
2530
}
2631

0 commit comments

Comments
 (0)