Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Stripe API display invoices and line items

David Carr

Stripe API Tutorials Nova Framework

Table of Contents

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 Your Logo Your Logo Your Logo

Become a sponsor

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


My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.