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

lara28580's avatar

How to make stripe invoices downloadable for my users?

I am trying to figure out how to make my invoices downloadable. I read the docs https://laravel.com/docs/master/billing#generating-invoice-pdfs and did it like so but this gives the user the receipts. What I want is the invoice pdf like it is on laracasts.

This is the method in my Invoicecontroller which provides the download function for the user to download his receipt.

public function download(Request $request, $invoiceId) {
      return $request->user()->downloadInvoice($invoiceId, [
          'vendor' => '',
          'product' => '',
      ]);
    }

Would prefer the invoice because it is highly customizable. Maybe someone got stuck on that too and knows how to do that?

best

0 likes
16 replies
lara28580's avatar

Thanks for your answer! Looks like this is something to look into for the next project but I implemented the whole process already like creating, updating and deleting subscriptions. Do you know if this is the way laracasts generates the invoices? There should be a easy way to get the invoices like it is for the receipts? I dont know maybe there is something in cashier but cant find something in the docs.

lara28580's avatar

@lenardo this does not really help there should be a link for the users to get their invoices like it is for the receipts. Cant figure out how laracasts is doing it.

automica's avatar

@smoketm laracasts is built on the laravel spark package. You’ll find some documentation on laravel main site for that

1 like
lara28580's avatar

@automica did not know that thank you

Thanks @timtom this looks promising, but what makes me wonder is why there is nothing from cashier provided. Something like for the receipts. Maybe I should stick with the receipts and edit the receipt.blade.php?

timtom's avatar

It's just that no one has developed this feature in the cashier :)

If you want to have custom receipts, I advise you to generate them yourself by a receipt view.

1 like
lara28580's avatar

If you want to have custom receipts, I advise you to generate them yourself by a receipt view.

@timtom what is that and how does that work?

timtom's avatar

I will not show you the code but you have all your payments in your database, so you can juste create a route who display view with data of payment. (Like a receipt)

1 like
lara28580's avatar

THanks @timtom! What I did now is to work with the invoice object because it provides the pdf url.

It looks like this

  public function download(Request $request, $invoiceId) {

      $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET', null));
      $stripe = $stripe->invoices->retrieve(
        $invoiceId,
        []
      );
      return redirect()->to($stripe->invoice_pdf);
}

What makes me a little bit concerned I cant ensure the invoice is related to the user

timtom's avatar

How do you retrieve the invoiceId ?

lara28580's avatar

Via link like so

<table>
    @foreach ($invoices as $invoice)
        <tr>
            <td>{{ $invoice->date()->toFormattedDateString() }}</td>
            <td>{{ $invoice->total() }}</td>
            <td><a href="/user/invoice/{{ $invoice->id }}">Download</a></td>
        </tr>
    @endforeach
</table>

What I could do is to check on every invoiceId if it belongs to the user

$invoice = $user->findInvoice($invoiceId) ?? null;

if($invoice == null)
	abort(404);
lara28580's avatar

Did it like so now and it works. Do you see any problems with this approach?

$invoice = null;
      try {
        $invoice = request()->user()->findInvoice($invoiceId);
      } finally {

        if($invoice == null) {
          abort(404);
        }

        return redirect()->to($invoice->invoice_pdf);
      }

Please or to participate in this conversation.