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

lat4732's avatar
Level 12

Stripe call to a member function downloadInvoice() on null

Hello everyone!

I have this route

Route::get('/stripe/download/invoice/{company_id}/{invoice_id}', [AdminController::class, 'downloadStripeInvoice']);

which should download a specific invoice. Here's the controller code:

use Laravel\Cashier\Cashier;

public function downloadStripeInvoice($company_id, $invoice_id) {
    $company = Companies::where('id', $company_id)->first();
    $billable = Cashier::findBillable($company->user_id);

    return $billable->downloadInvoice($invoice_id, [], "invoice_" . $invoice_id);
}

But I'm getting an error Call to a member function downloadInvoice() on null. I dumped $company->user_id and it shows correct user_id for the company_id from the parameter. Any ideas why it isn't working?

0 likes
9 replies
furqanDev's avatar

Check if it is returning something

$billable = Cashier::findBillable($company->user_id);
dd($billable);
furqanDev's avatar

@crypt.001111101 The user in that company is not a stripe user. You can add a check there to see if the user is subscribed and is customer or not.

public function downloadStripeInvoice($company_id, $invoice_id) {
    $company = Companies::where('id', $company_id)->first();
    $billable = Cashier::findBillable($company->user_id);
	if($billable === null){
		return redirect()->back()->with('error', "User is not a stripe customer");
	}

    return $billable->downloadInvoice($invoice_id, [], "invoice_" . $invoice_id);
}
lat4732's avatar
Level 12

@furqanDev Doesn't make sense. All user_ids that exists in companies table are stripe customers. I'm creating a stripe customer for each company and there is no way a stripe customer doesn't exists if there is a record for a company in companies table.

lat4732's avatar
Level 12

@furqanDev Gosh. It's a regular id and it must be a stripe_id... Anyways.. Thanks!

furqanDev's avatar

@crypt.001111101 Yeah store stripe id in company table. Because it won't work with regular ID.

$user_id = $company->user_id; //This needs to be stripe id'
$billable = Cashier::findBillable($user_id);
1 like

Please or to participate in this conversation.