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