GithubHelp home page GithubHelp logo

laravel-wallet's People

Contributors

chadtomkiss avatar depsimon avatar mannikj avatar tolawho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-wallet's Issues

Move Transaction Functions From HasWallet Trait To Wallet Model

It makes no real sense to pollute models utilizing the HasWallet trait with functions that actually belong to the Wallet model itself out of the box.
Developers might add proxy functions for more convenient use themselves if they want to.
The HasWallet trait should only do what its name implies: Provide the necessary wallet relations.

Atomic update on Wallet balance

Hi

On TransactionObserver you have this code :

public function created($transaction)
{
$transaction->wallet->balance += $transaction->amount;
$transaction->wallet->save();
}

I suggest to change any balance update to be like this :

public function created($transaction)
{
$transaction->wallet->increment('balance',$transaction->amount);
}

This will make Atomic update on balance .

package not install on livewire 11

I tried to install the package on Laravel 11, but it gives this error when installing:

composer require mannikj/laravel-wallet                                                                                                                                          
./composer.json has been updated                                                                                                                                                                                      
Running composer update mannikj/laravel-wallet
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - mannikj/laravel-wallet[v1.0.0, ..., v1.0.8, 2.0.0, ..., v2.1.1] require php ^7.0 -> your php version (8.2.0) does not satisfy that requirement.
    - mannikj/laravel-wallet v3.0.0 requires php ^7.2 -> your php version (8.2.0) does not satisfy that requirement.
    - mannikj/laravel-wallet[v4.0.0, v5.0.0] require php ^7.2.5 -> your php version (8.2.0) does not satisfy that requirement.
    - mannikj/laravel-wallet[v6.0.0, ..., v6.2.0] require illuminate/support ^7.0|^8.0 -> found illuminate/support[v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
    - mannikj/laravel-wallet v7.0.0 requires illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
    - mannikj/laravel-wallet v9.0.0 requires illuminate/support ^9.0 -> found illuminate/support[v9.0.0, ..., v9.52.16] but these were not loaded, likely because it conflicts with another require.
    - mannikj/laravel-wallet[v10.0.0, ..., v10.1.0] require illuminate/support ^10.0 -> found illuminate/support[v10.0.0, ..., v10.48.3] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires mannikj/laravel-wallet * -> satisfiable by mannikj/laravel-wallet[v1.0.0, ..., v1.0.8, 2.0.0, v2.0.1, v2.1.0, v2.1.1, v3.0.0, v4.0.0, v5.0.0, v6.0.0, v6.2.0, v7.0.0, v9.0.0, v10.0.0, v10.1.0].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require mannikj/laravel-wallet:*" to figure out if any version is installable, or "composer require mannikj/laravel-wallet:^2.1" if you know which you need.

optimist or pesimist transaction

Hello,
I came across your library by chance which is really nice :) . I was setting up the same thing but in your code I don't see any pessimistic or optimistic locks in the users' transactions. Or did I look at it wrong?
Thank's for response

Endless balance calculation when balance auto recalculation is enabled and wallet type is decimal

This can be reproduced without actual transactions by just using hardcoded strings instead of actual calculation. Example below:

public function actualBalance(bool $save = false) {
    $undefined = 0; /*$this->transactions()
        ->whereNotIn('type', \Wallet::biasedTransactionTypes())
        ->sum('amount');*/

    $credits = "318.40"; /*$this->transactions()
        ->whereIn('type', \Wallet::addingTransactionTypes())
        ->sum(\DB::raw('abs(amount)'));*/

    $debits = "465.60"; /*$this->transactions()
        ->whereIn('type', \Wallet::subtractingTransactionTypes())
        ->sum(\DB::raw('abs(amount)'));*/

    $balance = $undefined + $credits - $debits;
    dump(number_format($balance, 50));

    if ($save) {
        $this->balance = $balance;
        $this->save();
    }

    return $balance;
}

Expected result from dump would be -147.2 but due to php floating point handling, is actually -147.20000000000004547473508864641189575195312500000000. This causes model's isDirty method to always return true when comparing to the original value, whether it already matches balance or not.

One way to fix this is to use BCMath extension and format calculation expression as

$balance = bcsub(bcadd((string)$undefined, $credits, 2), $debits, 2);

Note that this solution works for wallet with decimals. There are probably other ways to do rounding as well if BCMath dependency is not preferred.

walletTransactions

hi
i am appreciate for useful package.
in walletTransactions() part return all Transactions i need to return just Transactions for that model id.
thanks a lot.

How to implement multiple wallets for a user

Hi, thanks for building this package!

I have a question, in the repository description, it says "you can equip your eloquent models with one or multiple digital wallets", and that's just what i'm trying to do, but i don't know how.

I would like to add to my project two wallets for the users, like:

  • coins: that the user can buy via PayPal or credit card).
  • points: that the user can obtain by completing tasks, like completing their profiles or using the app with regularity, etc.).

I would appreciate if you tell me how can I accomplish that. Thank you very much! ^_^

Class 'Wallet' not found

A class import is missing
You have a missing class import. Try importing this class: MannikJ\Laravel\Wallet\Models\Wallet.

In this file:
vendor/mannikj/laravel-wallet/src/Models/Transaction.php: line => 119

Can you Help?

Crossgrading from depsimon/laravel-wallet into Laravel 8

Hi guys,

So I've been using depsimon's version since laravel 5.7 with great success and now, upgrading to Laravel 8 I seem destined to change the dependency to yours. So I was wondering if you could supply the upgrade instructions. I see there's some differences i.r.t. the migrations, perhaps among other things.
What do I need to do?

Thanks in advance!

Error message: Column not found: 1054 Unknown column 'wallets.owner_id'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.