File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 44
55use Bavix \Wallet \Interfaces \Wallet ;
66use Bavix \Wallet \Models \Wallet as WalletModel ;
7+ use Bavix \Wallet \Services \WalletService ;
78use Illuminate \Database \Eloquent \Model ;
89use Illuminate \Database \Eloquent \Relations \BelongsTo ;
910use Illuminate \Database \Eloquent \Relations \MorphTo ;
1819 * @property string $uuid
1920 * @property string $type
2021 * @property int $amount
22+ * @property float $amountFloat
2123 * @property bool $confirmed
2224 * @property array $meta
2325 * @property Wallet $payable
@@ -94,4 +96,27 @@ public function wallet(): BelongsTo
9496 return $ this ->belongsTo (config ('wallet.wallet.model ' , WalletModel::class));
9597 }
9698
99+ /**
100+ * @return float
101+ */
102+ public function getAmountFloatAttribute (): float
103+ {
104+ $ decimalPlaces = app (WalletService::class)
105+ ->decimalPlaces ($ this ->wallet );
106+
107+ return $ this ->amount / $ decimalPlaces ;
108+ }
109+
110+ /**
111+ * @param float $amount
112+ * @return float
113+ */
114+ public function setAmountFloatAttribute (float $ amount ): void
115+ {
116+ $ decimalPlaces = app (WalletService::class)
117+ ->decimalPlaces ($ this ->wallet );
118+
119+ $ this ->amount = $ amount * $ decimalPlaces ;
120+ }
121+
97122}
Original file line number Diff line number Diff line change @@ -212,11 +212,19 @@ public function testMantissa(): void
212212
213213 $ transaction = $ user ->withdrawFloat (2556.72 );
214214 $ this ->assertEquals ($ transaction ->amount , -255672 );
215+ $ this ->assertEquals ($ transaction ->amountFloat , -2556.72 );
215216 $ this ->assertEquals ($ transaction ->type , Transaction::TYPE_WITHDRAW );
216217
217218 $ this ->assertEquals ($ user ->balance , 1000000 - 255672 );
218219 $ this ->assertEquals ($ user ->balanceFloat , 10000.00 - 2556.72 );
219220
221+ $ transaction = $ user ->depositFloat (2556.72 * 2 );
222+ $ this ->assertEquals ($ transaction ->amount , 255672 * 2 );
223+ $ this ->assertEquals ($ transaction ->amountFloat , 2556.72 * 2 );
224+ $ this ->assertEquals ($ transaction ->type , Transaction::TYPE_DEPOSIT );
225+
226+ $ this ->assertEquals ($ user ->balance , 1000000 + 255672 );
227+ $ this ->assertEquals ($ user ->balanceFloat , 10000.00 + 2556.72 );
220228 }
221229
222230 /**
You can’t perform that action at this time.
0 commit comments