Search code examples
phpstripe-paymentslaravel-cashier

Laravel Cashier Cancel returns call to member function cancel on null


Okay this makes no sense to me. the subscribed method is clearly returning true, but then the cancel returns "call to member function cancel on null". This should work according to Cashier's documentation. Does anyone have any idea why it would do this?

public function cancel() {
  $user = auth()->user();
  if( $user->subscribed('CkWraps Subscription') ) {
    $user->subscription('CKWraps Subscription')->cancel();
  }
  return back()->with('status', 'Your subscription has been canceled. We\'re sorry to see you go!');
}

Solution

  • Okay this is just weird, but I guess it was some sort of strange character encoding issue. Setting the subscription name as a constant fixed it.

        define("SUB", 'CkWraps Subscription');
        $user = auth()->user();
        if( $user->subscribed(SUB) ) {
            $user->subscription(SUB)->cancel();
        }