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