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

Error after create #57

Closed kak2z7702 closed 4 years ago

kak2z7702 commented 5 years ago

Hi)) I do this: 1.

    public function index(User $user)
    {
        if(is_null($user->getWallet('refill'))){
            $user->createWallet([
                'name' => ucfirst('refill') . 'Wallet',
                'slug' => 'refill',
            ]);
        }
        //$user->fresh();
        //$user->wallet->fresh();

        dd($user->getWallet('refill'));
    }
  1. i have error

    Illuminate \ Database \ QueryException (23000)
    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'App\Models\User-2-refill' for key 'wallets_holder_type_holder_id_slug_unique' (SQL: insert into `wallets` (`name`, `slug`, `holder_id`, `holder_type`, `updated_at`, `created_at`) values (RefillWallet, refill, 2, App\Models\User, 2019-07-05 19:05:32, 2019-07-05 19:05:32))
  2. refresh page

    Wallet {#638 ▼
    #fillable: array:6 [▶]
    #casts: array:1 [▶]
    #connection: "mysql"
    #table: "wallets"
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:9 [▶]
    #original: array:9 [▶]
    #changes: []
    #dates: []
    #dateFormat: null
    #appends: []
    #dispatchesEvents: []
    #observables: []
    #relations: []
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #guarded: array:1 [▶]
    }

What am I doing wrong? Thank.

kak2z7702 commented 5 years ago
    public function createWallet(array $data): WalletModel
    {
        /**
         * Create a default wallet
         */
        $this->getBalanceAttribute();

        /**
         * @var WalletModel $wallet
         */
        $wallet = $this->wallets()->create($data);
        $this->_wallets[$wallet->slug] = $wallet;

        return $wallet;
    }

my wallet has a default name "refill" If I create this wallet, then it is created twice. need to check the existence of the wallet in this method.

kak2z7702 commented 5 years ago

this work better

    /**
     * @param array $data
     * @return WalletModel
     */
    public function createWallet(array $data): WalletModel
    {

        /**
         * @var WalletModel $wallet
         */
        $wallet = $this->wallets()->create($data);
        $this->_wallets[$wallet->slug] = $wallet;

        /**
         * Create a default wallet
         */
        $this->getBalanceAttribute();

        return $wallet;
    }
rez1dent3 commented 5 years ago

@kak2z7702 Alexey, Thank you! This morning I will fix it.


Алексей, спасибо. Сегодня утром сделаю фикс данного бага.

rez1dent3 commented 5 years ago

@kak2z7702 fixed. thank. tag 3.0.3

rez1dent3 commented 5 years ago

I will close issue, if I can help you with anything else-create a new one or open it

Tarun-developer commented 4 years ago

it is a bug if you want custom default wallet

rez1dent3 commented 4 years ago

@ucanbehack I did not understand your problem. More?

Ecoent commented 4 years ago

Hi there, got few questions: 1) does the wallet work with fiat currencies and cryptos? 2) can this work with Stripe (for ecommerce), Paypal? 3) Any test / demo links? 4) Can admin control KYC for the users?

rez1dent3 commented 4 years ago

@Ecoent This is a library for creating virtual wallets. Everything can be implemented, but the developer is already doing it on his side.

Ecoent commented 4 years ago

@rez1dent3 thank you very much! would love to use this as early as possible for ecommerce apps. If you can share links or any more information, that will be awesome!

so the code thats published, is this usable now for real life app testing?

rez1dent3 commented 4 years ago

@Ecoent I use the library in production, but I can’t decide for you.If you have more questions, then create an issue. This issue is about another issue that most likely is no longer there.

Tarun-developer commented 4 years ago

@ucanbehack I did not understand your problem. More?

/**

in this case if we want to set custom default wallet name so have to return from above after creating new wallet

rez1dent3 commented 4 years ago

@ucanbehack All right. The default wallet will be created automatically. This is the expected behavior of the system.

rez1dent3 commented 4 years ago

No more questions. I am closing the issue. There will be questions - reopen or create a new one.