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