bavix / laravel-wallet

It's easy to work with a virtual wallet
https://bavix.github.io/laravel-wallet/
MIT License
1.14k stars 230 forks source link

The "buy" function only accepts integer data #831

Closed JoelVeloz closed 9 months ago

JoelVeloz commented 10 months ago

Describe the bug The "buy" function only accepts integer data, how do I buy something with decimal data? , I am applying "WalletFloat" throughout my project, but when I try to create an item, and I want to pay, it does not withdraw the mentioned amount, which is $100, but 0.1, it is clear that it is because I use decimals, but there is no function to decimals? so that you explicitly put the value in decimal "0.1" and not 100, since you would have to apply another function for the conversion.

To Reproduce Steps to reproduce the behavior: use the same configuration from the documentation but with interfaces referring to float image

rez1dent3 commented 10 months ago

Hello. This is not a bug, it's a feature. I'll think in this direction. I'll answer you later.

rez1dent3 commented 10 months ago

Hello.

Starting from version 11.x, FormatterServiceInterface will be added, which will help you multiply a number by another number)

    public function getAmountProduct(Customer $customer): int
    {
        /** @var Wallet $wallet */
        $wallet = app(CastServiceInterface::class)->getWallet($customer);

        return (int) app(FormatterServiceInterface::class)->intValue(
            $this->price,
            $wallet->decimal_places,
        );
    }

BUT you need to remember about decimal_places, if it is different for different wallets, then you need to take this into account in the logic of the model.