Laravel - Cashier | swap() and cancelNow() on null

1k views Asked by At

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?

1

There are 1 answers

0
Bruno Mota On BEST ANSWER

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.