1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bavix\Wallet\Traits; |
4
|
|
|
|
5
|
|
|
use Bavix\Wallet\Interfaces\Product; |
6
|
|
|
use Bavix\Wallet\Models\Transfer; |
7
|
|
|
use Bavix\Wallet\Objects\Cart; |
8
|
|
|
use function current; |
9
|
|
|
|
10
|
|
|
trait CanPay |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
use CartPay; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param Product $product |
17
|
|
|
* @return Transfer |
18
|
|
|
* @throws |
19
|
|
|
*/ |
20
|
2 |
|
public function payFree(Product $product): Transfer |
21
|
|
|
{ |
22
|
2 |
|
return current($this->payFreeCart(Cart::make()->addItem($product))); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Product $product |
27
|
|
|
* @param bool $force |
28
|
|
|
* @return Transfer|null |
29
|
|
|
*/ |
30
|
|
|
public function safePay(Product $product, bool $force = null): ?Transfer |
31
|
|
|
{ |
32
|
|
|
return current($this->safePayCart(Cart::make()->addItem($product), $force)) ?: null; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Product $product |
37
|
|
|
* @param bool $force |
38
|
|
|
* @return Transfer |
39
|
|
|
* @throws |
40
|
|
|
*/ |
41
|
|
|
public function pay(Product $product, bool $force = null): Transfer |
42
|
|
|
{ |
43
|
|
|
return current($this->payCart(Cart::make()->addItem($product), $force)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Product $product |
48
|
|
|
* @return Transfer |
49
|
|
|
* @throws |
50
|
|
|
*/ |
51
|
1 |
|
public function forcePay(Product $product): Transfer |
52
|
|
|
{ |
53
|
1 |
|
return current($this->forcePayCart(Cart::make()->addItem($product))); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Product $product |
58
|
|
|
* @param bool $force |
59
|
|
|
* @param bool $gifts |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function safeRefund(Product $product, bool $force = null, bool $gifts = null): bool |
63
|
|
|
{ |
64
|
|
|
return $this->safeRefundCart(Cart::make()->addItem($product), $force, $gifts); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Product $product |
69
|
|
|
* @param bool $force |
70
|
|
|
* @param bool $gifts |
71
|
|
|
* @return bool |
72
|
|
|
* @throws |
73
|
|
|
*/ |
74
|
|
|
public function refund(Product $product, bool $force = null, bool $gifts = null): bool |
75
|
|
|
{ |
76
|
|
|
return $this->refundCart(Cart::make()->addItem($product), $force, $gifts); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param Product $product |
81
|
|
|
* @param bool $gifts |
82
|
|
|
* @return bool |
83
|
|
|
* @throws |
84
|
|
|
*/ |
85
|
|
|
public function forceRefund(Product $product, bool $gifts = null): bool |
86
|
|
|
{ |
87
|
|
|
return $this->forceRefundCart(Cart::make()->addItem($product), $gifts); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param Product $product |
92
|
|
|
* @param bool $force |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
public function safeRefundGift(Product $product, bool $force = null): bool |
96
|
|
|
{ |
97
|
|
|
return $this->safeRefundGiftCart(Cart::make()->addItem($product), $force); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param Product $product |
102
|
|
|
* @param bool $force |
103
|
|
|
* @return bool |
104
|
|
|
* @throws |
105
|
|
|
*/ |
106
|
|
|
public function refundGift(Product $product, bool $force = null): bool |
107
|
|
|
{ |
108
|
|
|
return $this->refundGiftCart(Cart::make()->addItem($product), $force); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param Product $product |
113
|
|
|
* @return bool |
114
|
|
|
* @throws |
115
|
|
|
*/ |
116
|
|
|
public function forceRefundGift(Product $product): bool |
117
|
|
|
{ |
118
|
|
|
return $this->forceRefundGiftCart(Cart::make()->addItem($product)); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|