Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

systemseven's avatar

Cashier Subscription returns null while running tests?

I've got a stock install of Laravel 5.6 and the latest Cashier: 7.0

Here's the flow:

  1. The test hits the create account endpoint to create an actual user
$this->json('POST','v1/users', $newUserData)

In my UserController I do the following:

$u->newSubscription($plan, $stripe_plan)
    ->create($token, ['email' => $u->email]);

I then try to cancel that account in the test by doing:

$this->json('DELETE','/v1/users/'.$content->id, ['plan' => $planName])

The create works fine - after dd'ing alot of things I can see that all the data is going into the database. In fact - I can see the customers created in stripe AND subscribed to the plans in stripe....

BUT when I try to cancel the subscription in my delete method of my UserController:

$user->subscription($request->input('plan'))->cancel();

I get the following error:

Call to a member function cancel() on null

This one has me stumped...anybody got any ideas?

0 likes
2 replies
bobbybouwmann's avatar

$user->subscription($plan) returns null.

Are you sure $request->input('plan') returns the correct value?

1 like
systemseven's avatar

Yep I’ve tested that. It’s working fine. I’ve even taken that out and hardcoded a plan - still nothing.

Please or to participate in this conversation.