bavix / laravel-wallet

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

Wallet giving weird behavior #179

Closed Xinecraft closed 4 years ago

Xinecraft commented 4 years ago

Anyone know whats wrong with this code or its there some bug in package?

This is making the wallet go crazy. After running it the wallet amount changes to wierd high for example if a user has 6540 cent and deposit is of 750 cent then wallet bal ($user->balance) will show up 15037 till you run php artisan wallet:refresh (this command fixes it)

\DB::beginTransaction();
$quizUsers = $this->quiz()->cursor();

 foreach ($quizUsers as $index=>$quizUser)
 {
       $quizUser->user->deposit($some_amount, ['message' => 'Prize', 'type' => 'quiz_prize', 'resource_uuid' => $this->quiz->uuid, 'reference_id' => uniqidReal() ]);
 }
 \DB::commit();
rez1dent3 commented 4 years ago

I strongly doubt it. I get points through the "deposit" in automatic mode (crontab), there were no problems. I am logging every point accrual, everything is clear. I would look for a problem in the code.

Xinecraft commented 4 years ago

Hey, Thanks. It seems this issue is not occurring after I updated the version.

But do anyone know why the casting of Wallet "balance" to "int" doesn't work?

    /**
     * Wallet model configuration.
     */
    'wallet' => [
        'table' => 'wallets',
        'model' => Wallet::class,
        'casts' => [
            'balance' => 'int'
        ],
        'default' => [
            'name' => 'Default Wallet',
            'slug' => 'default',
            'decimal_places' => 0
        ],
    ],
rez1dent3 commented 4 years ago

@kinnngg Needed for long arithmetic to work. This is a cardinal difference between the 5th version and the 4th.

https://github.com/bavix/laravel-wallet/blob/master/src/Simple/Math.php

All arithmetic is reduced to a string in order to be able to create wallets of ether, bitcoin and others. A lot of people asked for this functionality.

Xinecraft commented 4 years ago

Ohk. Thanks