Skip to content

Commit d40bd77

Browse files
committed
update customer contract docs
1 parent 3642914 commit d40bd77

File tree

2 files changed

+126
-9
lines changed

2 files changed

+126
-9
lines changed

src/Interfaces/Customer.php

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,76 @@
1515

1616
interface Customer extends Wallet
1717
{
18-
public function pay(Product $product, bool $force = false): Transfer;
18+
/**
19+
* @throws ProductEnded
20+
* @throws BalanceIsEmpty
21+
* @throws InsufficientFunds
22+
* @throws RecordsNotFoundException
23+
* @throws TransactionFailedException
24+
* @throws ExceptionInterface
25+
*/
26+
public function payFree(Product $product): Transfer;
1927

2028
public function safePay(Product $product, bool $force = false): ?Transfer;
2129

30+
/**
31+
* @throws ProductEnded
32+
* @throws BalanceIsEmpty
33+
* @throws InsufficientFunds
34+
* @throws RecordsNotFoundException
35+
* @throws TransactionFailedException
36+
* @throws ExceptionInterface
37+
*/
38+
public function pay(Product $product, bool $force = false): Transfer;
39+
40+
/**
41+
* @throws ProductEnded
42+
* @throws RecordsNotFoundException
43+
* @throws TransactionFailedException
44+
* @throws ExceptionInterface
45+
*/
2246
public function forcePay(Product $product): Transfer;
2347

24-
public function paid(Product $product, bool $gifts = false): ?Transfer;
48+
public function safeRefund(Product $product, bool $force = false, bool $gifts = false): bool;
2549

50+
/**
51+
* @throws BalanceIsEmpty
52+
* @throws InsufficientFunds
53+
* @throws RecordsNotFoundException
54+
* @throws TransactionFailedException
55+
* @throws ModelNotFoundException
56+
* @throws ExceptionInterface
57+
*/
2658
public function refund(Product $product, bool $force = false, bool $gifts = false): bool;
2759

28-
public function safeRefund(Product $product, bool $force = false, bool $gifts = false): bool;
29-
60+
/**
61+
* @throws RecordsNotFoundException
62+
* @throws TransactionFailedException
63+
* @throws ModelNotFoundException
64+
* @throws ExceptionInterface
65+
*/
3066
public function forceRefund(Product $product, bool $gifts = false): bool;
3167

68+
public function safeRefundGift(Product $product, bool $force = false): bool;
69+
70+
/**
71+
* @throws BalanceIsEmpty
72+
* @throws InsufficientFunds
73+
* @throws RecordsNotFoundException
74+
* @throws TransactionFailedException
75+
* @throws ModelNotFoundException
76+
* @throws ExceptionInterface
77+
*/
78+
public function refundGift(Product $product, bool $force = false): bool;
79+
80+
/**
81+
* @throws RecordsNotFoundException
82+
* @throws TransactionFailedException
83+
* @throws ModelNotFoundException
84+
* @throws ExceptionInterface
85+
*/
86+
public function forceRefundGift(Product $product): bool;
87+
3288
/**
3389
* @throws ProductEnded
3490
* @throws BalanceIsEmpty
@@ -41,6 +97,9 @@ public function forceRefund(Product $product, bool $gifts = false): bool;
4197
*/
4298
public function payFreeCart(CartInterface $cart): array;
4399

100+
/** @return Transfer[] */
101+
public function safePayCart(CartInterface $cart, bool $force = false): array;
102+
44103
/**
45104
* @throws ProductEnded
46105
* @throws BalanceIsEmpty
@@ -53,9 +112,6 @@ public function payFreeCart(CartInterface $cart): array;
53112
*/
54113
public function payCart(CartInterface $cart, bool $force = false): array;
55114

56-
/** @return Transfer[] */
57-
public function safePayCart(CartInterface $cart, bool $force = false): array;
58-
59115
/**
60116
* @throws ProductEnded
61117
* @throws RecordsNotFoundException
@@ -66,6 +122,8 @@ public function safePayCart(CartInterface $cart, bool $force = false): array;
66122
*/
67123
public function forcePayCart(CartInterface $cart): array;
68124

125+
public function safeRefundCart(CartInterface $cart, bool $force = false, bool $gifts = false): bool;
126+
69127
/**
70128
* @throws BalanceIsEmpty
71129
* @throws InsufficientFunds
@@ -76,8 +134,6 @@ public function forcePayCart(CartInterface $cart): array;
76134
*/
77135
public function refundCart(CartInterface $cart, bool $force = false, bool $gifts = false): bool;
78136

79-
public function safeRefundCart(CartInterface $cart, bool $force = false, bool $gifts = false): bool;
80-
81137
/**
82138
* @throws RecordsNotFoundException
83139
* @throws TransactionFailedException
@@ -86,6 +142,8 @@ public function safeRefundCart(CartInterface $cart, bool $force = false, bool $g
86142
*/
87143
public function forceRefundCart(CartInterface $cart, bool $gifts = false): bool;
88144

145+
public function safeRefundGiftCart(CartInterface $cart, bool $force = false): bool;
146+
89147
/**
90148
* @throws BalanceIsEmpty
91149
* @throws InsufficientFunds
@@ -103,4 +161,6 @@ public function refundGiftCart(CartInterface $cart, bool $force = false): bool;
103161
* @throws ExceptionInterface
104162
*/
105163
public function forceRefundGiftCart(CartInterface $cart): bool;
164+
165+
public function paid(Product $product, bool $gifts = false): ?Transfer;
106166
}

src/Traits/CanPay.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44

55
namespace Bavix\Wallet\Traits;
66

7+
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
8+
use Bavix\Wallet\Exceptions\InsufficientFunds;
9+
use Bavix\Wallet\Exceptions\ProductEnded;
710
use Bavix\Wallet\Interfaces\Product;
11+
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
12+
use Bavix\Wallet\Internal\Exceptions\ModelNotFoundException;
13+
use Bavix\Wallet\Internal\Exceptions\TransactionFailedException;
814
use Bavix\Wallet\Models\Transfer;
915
use Bavix\Wallet\Objects\Cart;
1016
use function current;
17+
use Illuminate\Database\RecordsNotFoundException;
1118

1219
trait CanPay
1320
{
1421
use CartPay;
1522

23+
/**
24+
* @throws ProductEnded
25+
* @throws BalanceIsEmpty
26+
* @throws InsufficientFunds
27+
* @throws RecordsNotFoundException
28+
* @throws TransactionFailedException
29+
* @throws ExceptionInterface
30+
*/
1631
public function payFree(Product $product): Transfer
1732
{
1833
return current($this->payFreeCart(app(Cart::class)->addItem($product)));
@@ -23,11 +38,25 @@ public function safePay(Product $product, bool $force = false): ?Transfer
2338
return current($this->safePayCart(app(Cart::class)->addItem($product), $force)) ?: null;
2439
}
2540

41+
/**
42+
* @throws ProductEnded
43+
* @throws BalanceIsEmpty
44+
* @throws InsufficientFunds
45+
* @throws RecordsNotFoundException
46+
* @throws TransactionFailedException
47+
* @throws ExceptionInterface
48+
*/
2649
public function pay(Product $product, bool $force = false): Transfer
2750
{
2851
return current($this->payCart(app(Cart::class)->addItem($product), $force));
2952
}
3053

54+
/**
55+
* @throws ProductEnded
56+
* @throws RecordsNotFoundException
57+
* @throws TransactionFailedException
58+
* @throws ExceptionInterface
59+
*/
3160
public function forcePay(Product $product): Transfer
3261
{
3362
return current($this->forcePayCart(app(Cart::class)->addItem($product)));
@@ -38,11 +67,25 @@ public function safeRefund(Product $product, bool $force = false, bool $gifts =
3867
return $this->safeRefundCart(app(Cart::class)->addItem($product), $force, $gifts);
3968
}
4069

70+
/**
71+
* @throws BalanceIsEmpty
72+
* @throws InsufficientFunds
73+
* @throws RecordsNotFoundException
74+
* @throws TransactionFailedException
75+
* @throws ModelNotFoundException
76+
* @throws ExceptionInterface
77+
*/
4178
public function refund(Product $product, bool $force = false, bool $gifts = false): bool
4279
{
4380
return $this->refundCart(app(Cart::class)->addItem($product), $force, $gifts);
4481
}
4582

83+
/**
84+
* @throws RecordsNotFoundException
85+
* @throws TransactionFailedException
86+
* @throws ModelNotFoundException
87+
* @throws ExceptionInterface
88+
*/
4689
public function forceRefund(Product $product, bool $gifts = false): bool
4790
{
4891
return $this->forceRefundCart(app(Cart::class)->addItem($product), $gifts);
@@ -53,11 +96,25 @@ public function safeRefundGift(Product $product, bool $force = false): bool
5396
return $this->safeRefundGiftCart(app(Cart::class)->addItem($product), $force);
5497
}
5598

99+
/**
100+
* @throws BalanceIsEmpty
101+
* @throws InsufficientFunds
102+
* @throws RecordsNotFoundException
103+
* @throws TransactionFailedException
104+
* @throws ModelNotFoundException
105+
* @throws ExceptionInterface
106+
*/
56107
public function refundGift(Product $product, bool $force = false): bool
57108
{
58109
return $this->refundGiftCart(app(Cart::class)->addItem($product), $force);
59110
}
60111

112+
/**
113+
* @throws RecordsNotFoundException
114+
* @throws TransactionFailedException
115+
* @throws ModelNotFoundException
116+
* @throws ExceptionInterface
117+
*/
61118
public function forceRefundGift(Product $product): bool
62119
{
63120
return $this->forceRefundGiftCart(app(Cart::class)->addItem($product));

0 commit comments

Comments
 (0)