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
|
1 |
|
return \current($this->safePayCart(Cart::make()->addItem($product), $force)) ?: null; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Product $product |
40
|
|
|
* @param bool $force |
41
|
|
|
* @return Transfer |
42
|
|
|
* @throws |
43
|
|
|
*/ |
44
|
6 |
|
public function pay(Product $product, bool $force = null): Transfer |
45
|
|
|
{ |
46
|
6 |
|
return \current($this->payCart(Cart::make()->addItem($product), $force)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Product $product |
51
|
|
|
* @return Transfer |
52
|
|
|
* @throws |
53
|
|
|
*/ |
54
|
1 |
|
public function forcePay(Product $product): Transfer |
55
|
|
|
{ |
56
|
1 |
|
return \current($this->forcePayCart(Cart::make()->addItem($product))); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Product $product |
61
|
|
|
* @param bool $force |
62
|
|
|
* @param bool $gifts |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
3 |
|
public function safeRefund(Product $product, bool $force = null, bool $gifts = null): bool |
66
|
|
|
{ |
67
|
3 |
|
return $this->safeRefundCart(Cart::make()->addItem($product), $force, $gifts); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param Product $product |
72
|
|
|
* @param bool $force |
73
|
|
|
* @param bool $gifts |
74
|
|
|
* @return bool |
75
|
|
|
* @throws |
76
|
|
|
*/ |
77
|
4 |
|
public function refund(Product $product, bool $force = null, bool $gifts = null): bool |
78
|
|
|
{ |
79
|
4 |
|
return $this->refundCart(Cart::make()->addItem($product), $force, $gifts); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Product $product |
84
|
|
|
* @param bool $gifts |
85
|
|
|
* @return bool |
86
|
|
|
* @throws |
87
|
|
|
*/ |
88
|
1 |
|
public function forceRefund(Product $product, bool $gifts = null): bool |
89
|
|
|
{ |
90
|
1 |
|
return $this->forceRefundCart(Cart::make()->addItem($product), $gifts); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param Product $product |
95
|
|
|
* @param bool $force |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
1 |
|
public function safeRefundGift(Product $product, bool $force = null): bool |
99
|
|
|
{ |
100
|
1 |
|
return $this->safeRefundGiftCart(Cart::make()->addItem($product), $force); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param Product $product |
105
|
|
|
* @param bool $force |
106
|
|
|
* @return bool |
107
|
|
|
* @throws |
108
|
|
|
*/ |
109
|
1 |
|
public function refundGift(Product $product, bool $force = null): bool |
110
|
|
|
{ |
111
|
1 |
|
return $this->refundGiftCart(Cart::make()->addItem($product), $force); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param Product $product |
116
|
|
|
* @return bool |
117
|
|
|
* @throws |
118
|
|
|
*/ |
119
|
1 |
|
public function forceRefundGift(Product $product): bool |
120
|
|
|
{ |
121
|
1 |
|
return $this->forceRefundGiftCart(Cart::make()->addItem($product)); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|