Skip to main content

Invoice History

Subscribd records every charge as an Invoice. Each invoice carries line items, a status, a total, and a PDF download link.

Livewire component

Drop the Livewire component into any authenticated page for a paginated invoice table with PDF download links:
<livewire:subscribd::subscriber.invoice-history />

{{-- Custom page size --}}
<livewire:subscribd::subscriber.invoice-history :per-page="25" />

Blade component

The static Blade component renders a non-paginated list. Use it in contexts where server-side reactivity is not needed:
<x-subscribd-invoice-history :per-page="5" />

Accessing invoices programmatically

// All invoices for the user, newest first
$invoices = $user->invoices()->get();

// Paginated
$invoices = $user->invoices()->paginate(15);

// Latest paid invoice
$latest = $user->latestInvoice();

// Filter by status
$paid   = $user->invoices()->paid()->get();
$failed = $user->invoices()->failed()->get();

Invoice properties

$invoice->status->value;       // 'paid', 'failed', 'pending', 'refunded'
$invoice->total();             // Money object
$invoice->subtotal();          // Money object (before tax/discount)
$invoice->tax();               // Money object
$invoice->discount();          // Money object
$invoice->currency;            // 'USD', 'EUR', etc.
$invoice->period_start;        // Carbon
$invoice->period_end;          // Carbon
$invoice->paid_at;             // Carbon|null

Invoice totals

Invoice amounts are returned as Money objects from the moneyphp/money library:
$invoice->total()->getAmount()->toInt();    // e.g. 4900 (cents)
$invoice->total()->getCurrency()->getCode(); // 'USD'

// Format for display
$formatter = new \Money\Formatter\DecimalMoneyFormatter(new \Money\Currencies\ISOCurrencies());
echo $formatter->format($invoice->total()); // '49.00'

PDF download

The pdf_url column is populated automatically for Stripe-hosted checkout invoices and is also populated when the dompdf driver generates a PDF locally:
$invoice->pdf_url; // URL string or null

// Generate a download response in a controller
return response()->download($invoice->pdfPath());
Render a download link in Blade:
@if ($invoice->pdf_url)
    <a href="{{ $invoice->pdf_url }}">Download PDF</a>
@endif

{{-- Or use the component --}}
<x-subscribd-invoice-link :invoice="$invoice">Download PDF</x-subscribd-invoice-link>

Invoice line items

Each invoice has one or more line items accessible via the lines relationship:
foreach ($invoice->lines as $line) {
    $line->description;
    $line->amount();   // Money
    $line->quantity;
    $line->period_start;
    $line->period_end;
}

Next steps

  • One-Off Charges — Charge outside a subscription
  • Tax — Tax configuration and calculation