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