Invoices

Invoices

Retrieving Invoices

You may easily retrieve an array of a billable model's invoices using the invoices method. The invoices method returns a collection of Shopkeeper's Invoice instances:

const invoices = await user.invoices()

If you would like to include pending invoices in the results, you may use the invoicesIncludingPending method:

const invoice = await user.invoicesIncludingPending()

You may use the findInvoice method to retrieve a specific invoice by its ID:

const invoice = await user.findInvoice(invoiceId)

Displaying Invoice Information

When listing the invoices for the customer, you may use the invoice's methods to display the relevant invoice information. For example, you may wish to list every invoice in a table, allowing the user to easily download any of them:

<table>
@each(invoice in invoices)
<tr>
<td>{{ invoice->date()->format() }}</td>
<td>{{ invoice->total() }}</td>
<td><a href="/user/invoice/{{ invoice->id }}">Download</a></td>
</tr>
@end
</table>

Upcoming Invoices

To retrieve the upcoming invoice for a customer, you may use the upcomingInvoice method:

const invoice = await user.upcomingInvoice()

Similarly, if the customer has multiple subscriptions, you can also retrieve the upcoming invoice for a specific subscription:

const subscription = await user.subscription('default')
const invoice = await subscription.upcomingInvoice()

Previewing subscription Invoices

Using the previewInvoice method, you can preview an invoice before making price changes. This will allow you to determine what your customer's invoice will look like when a given price change is made:

const subscription = await user.subscription('default')
const invoice = await subscription.previewInvoice('price_yearly')

You may pass an array of prices to the previewInvoice method in order to preview invoices with multiple new prices:

const subscription = await user.subscription('default')
const invoice = await subscription.previewInvoice(['price_yearly', 'price_metered'])

Generating Invoice PDFs

This feature is not developed yet.