2

Basically I have this problem which keeps occuring.

Once a user subscribes, it all works fine. He can cancel/change subscription no problem.

However, once they have changed their subscription once, I cant call swap or cancel without it throwing an error on null

Call to a member function cancelNow() on null Call to a member function Swap() on null

Both mean that $user->subscription($membership_group) = null.

What could be causing this?

e4stwood
  • 109
  • 1
  • 2
  • 8
  • Update: the problem arises after I've switched the user to a new plan then try and do something with the user. E.G i change the user from plan 1 to 2 then try cancel - user->subscribed->cancel on null error. I have also noticed that when Ichange the users plan with swap it changes the plan but not the name in subscriptions – e4stwood Jan 02 '17 at 15:08
  • Have you got the issue resolved? then kindly share your findings thanks. – Dawood Butt Aug 11 '18 at 11:49
  • has this ever been fixed? I am getting the same error on cancelNow – Tomas Lucena Nov 17 '22 at 13:31

1 Answers1

2

This is the solution I found, quite ugly! I will report this bug.

    $user->subscription('current_plan')->swap('plan_to_subscribe');
    $user->save();

    // Messed up work around cause of swap method bug
    DB::update('update subscriptions set name = ? where user_id = ?', [
        $plan,
        $user->id
    ]);

Anyway works for the moment...

Also I guess this is already fixed: https://github.com/laravel/cashier/commit/1e87a60f1bf5c8981730d2481350f74fccaf0947#diff-dde586b4ea0798ea4a467b9eba070a7e

Just waiting on a release.

Bruno Mota
  • 111
  • 2
  • 9