1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bavix\Wallet\Traits; |
4
|
|
|
|
5
|
|
|
use Bavix\Wallet\Interfaces\Wallet; |
6
|
|
|
use Bavix\Wallet\Models\Transaction; |
7
|
|
|
use Bavix\Wallet\Models\Transfer; |
8
|
|
|
use Bavix\Wallet\Services\CommonService; |
9
|
|
|
use function config; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Trait HasWalletFloat |
13
|
|
|
* |
14
|
|
|
* @package Bavix\Wallet\Traits |
15
|
|
|
* |
16
|
|
|
* @property-read float $balanceFloat |
17
|
|
|
*/ |
18
|
|
|
trait HasWalletFloat |
19
|
|
|
{ |
20
|
|
|
use HasWallet; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param float $amount |
24
|
|
|
* @param array|null $meta |
25
|
|
|
* @param bool $confirmed |
26
|
|
|
* |
27
|
|
|
* @return Transaction |
28
|
|
|
*/ |
29
|
|
|
public function forceWithdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction |
30
|
|
|
{ |
31
|
|
|
return $this->forceWithdraw($amount * $this->coefficient(), $meta, $confirmed); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return float |
36
|
|
|
*/ |
37
|
|
|
private function coefficient(): float |
38
|
|
|
{ |
39
|
|
|
return config('wallet.package.coefficient', 100.); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param float $amount |
44
|
|
|
* @param array|null $meta |
45
|
|
|
* @param bool $confirmed |
46
|
|
|
* |
47
|
|
|
* @return Transaction |
48
|
|
|
*/ |
49
|
|
|
public function depositFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction |
50
|
|
|
{ |
51
|
|
|
return $this->deposit($amount * $this->coefficient(), $meta, $confirmed); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param float $amount |
56
|
|
|
* @param array|null $meta |
57
|
|
|
* @param bool $confirmed |
58
|
|
|
* |
59
|
|
|
* @return Transaction |
60
|
|
|
*/ |
61
|
|
|
public function withdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction |
62
|
|
|
{ |
63
|
|
|
return $this->withdraw($amount * $this->coefficient(), $meta, $confirmed); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param float $amount |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
public function canWithdrawFloat(float $amount): bool |
71
|
|
|
{ |
72
|
|
|
return $this->canWithdraw($amount * $this->coefficient()); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param Wallet $wallet |
77
|
|
|
* @param float $amount |
78
|
|
|
* @param array|null $meta |
79
|
|
|
* @return Transfer |
80
|
|
|
* @throws |
81
|
|
|
*/ |
82
|
|
|
public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer |
83
|
|
|
{ |
84
|
|
|
return $this->transfer($wallet, $amount * $this->coefficient(), $meta); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param Wallet $wallet |
89
|
|
|
* @param float $amount |
90
|
|
|
* @param array|null $meta |
91
|
|
|
* @return null|Transfer |
92
|
|
|
*/ |
93
|
|
|
public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): ?Transfer |
94
|
|
|
{ |
95
|
|
|
return $this->safeTransfer($wallet, $amount * $this->coefficient(), $meta); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param Wallet $wallet |
100
|
|
|
* @param float $amount |
101
|
|
|
* @param array|null $meta |
102
|
|
|
* @return Transfer |
103
|
|
|
*/ |
104
|
|
|
public function forceTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer |
105
|
|
|
{ |
106
|
|
|
return $this->forceTransfer($wallet, $amount * $this->coefficient(), $meta); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return float |
111
|
|
|
*/ |
112
|
|
|
public function getBalanceFloatAttribute(): float |
113
|
|
|
{ |
114
|
|
|
return $this->balance / $this->coefficient(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|