0

Trying to understand, why I'm not able to popup users balance using paypal sandox.

Here is my AccountBalance.php part code, when user paid in paypal

public function rebuildBalance($user_id, $amount, $bonus = 0, $frozen = false, $currency) {
        $balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();

        if ($bonus == 0) {
            if ($frozen) {
                $balance->balance_frozen += $amount;
            } else {

                $balance->balance += $amount;
            }

        } else {
            $balance->bonus += $amount;
        }

And when transaction is over, I got Creating default object from empty value

to this part $balance->balance += $amount;

Thankx

1 Answer 1

2

This is because your $balance variable is null from this query:

 $balance = UserBalance::where('user_id', $user_id)->where('currency_id', $currency)->first();

Figure out why this query doesn't work the way you intend it to and you should be fine. A good start would be to figure out what $currency variable holds - and make sure you pass it correctly when calling rebuildBalance(args).

If you try to assign a property to null you get your exact error.

Sign up to request clarification or add additional context in comments.

1 Comment

in db I have record for this transaction, and I wondering... why there currency_id is equal 2, if table currency has only 1 value euro with ID 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.