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