Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Stripe API display invoices and line items

David Carr

Stripe API Nova Framework Tutorials

    Invoices are created automatically, using Stripe’s API it’s possible to pull the invoices into your application.

    I’m using Nova Framework not setup with Nova? please read Getting Stripe API setup with Nova Framework

    To get all invoices from Stripe call Invoice::all()->data this will return an array of the invoices.

    $invoices = Invoice::all()->data;

    Loop over the array and display the invoices in a table, I’ve chosen to display only the date, payment amount, status and a link to download a custom invoice.

    <table class='table table-striped table-hover table-bordered'>
        <th>{{ __d('users', 'Date') }}</th>
        <th>{{ __d('users', 'Payment') }}</th>
        <th>{{ __d('users', 'Status') }}</th>
        <th>{{ __d('users', 'Invoice') }}</th>
    @foreach($invoices as $invoice)
            <td>{{ date('jS M Y H:iA', $invoice->date) }}</td>
            <td>&pound;{{ $invoice->total / 100 }}</td>
            <td>{{ ($invoice->paid) ? 'Yes' : 'No' }}</td>
            <td><a href='{{ site_url("account/invoice/$invoice->id") }}' class='btn btn-info btn-xs'>{{ __d('users', 'Download') }}</a></td>

    The array contains line items for each invoice, it’s not practical to display the line items here so instead display them in a dedicated page. 

    Getting line items

    First get a single invoice:

    $invoice = Invoice::retrieve($id);

    Next setup a table loop over the items by calling $invoice->lines->data and loop over that.

    <table class='table table-striped table-hover'>
    @foreach($invoice->lines->data as $line)
            <td>{{ ($line->description =='') ? $line->plan->name : $line->description }}</td>
            <td>&pound;{{ $line->amount / 100 }}</td>
            <td style="text-align: right"><b>Total</b></td>
            <td><b>&pound;{{ $invoice->total / 100 }}</b></td>


Laravel Modules Book by David Carr

Help support the blog so that I can continue creating new content!

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2022 DC Blog. All code MIT license. All rights reserved.