CustomerInvoiceList
The CustomerInvoiceList component is designed to render a customer's invoice history. It fetches and displays invoice data from the payment service, offering two distinct layouts: a simple, date-grouped list with infinite scroll, and a detailed, paginated table. This component must be used within a PaymentProvider to function correctly.
Props#
Prop | Type | Description | Default |
|---|---|---|---|
|
| The ID of the customer whose invoices are to be displayed. |
|
|
| Filter invoices by a specific subscription ID. |
|
|
| Filter invoices by a specific currency ID. |
|
|
| If |
|
|
| If |
|
|
| If |
|
|
| A comma-separated string of invoice statuses to display (e.g., |
|
|
| The number of invoices to fetch per page. |
|
|
| The target attribute for invoice links (e.g., |
|
|
| Defines a call-to-action for certain invoices. Set to |
|
|
| The display mode for the invoice list. |
|
|
| A callback function that is triggered when the invoice data changes. |
|
|
| In |
|
Basic Usage (List View)#
The default view (type="list") renders a simple list of invoices, grouped by date, with an infinite scroll mechanism to load more items.
CustomerInvoiceListPage.tsx
import { PaymentProvider, CustomerInvoiceList } from '@blocklet/payment-react';
function InvoiceHistoryPage() {
// Assuming customerId is available, e.g., from session or props
const customerId = 'cus_xxxxxxxxxxxxxx';
return (
<PaymentProvider>
<CustomerInvoiceList customer_id={customerId} />
</PaymentProvider>
);
}Table View#
For a more detailed and structured presentation, you can set type="table". This mode displays invoices in a paginated table with sortable columns.
CustomerInvoiceTablePage.tsx
import { PaymentProvider, CustomerInvoiceList } from '@blocklet/payment-react';
function InvoiceHistoryTable() {
const customerId = 'cus_xxxxxxxxxxxxxx';
return (
<PaymentProvider>
<CustomerInvoiceList
customer_id={customerId}
type="table"
relatedSubscription={true} // Show a column for the related subscription
pageSize={5}
/>
</PaymentProvider>
);
}In this example, the relatedSubscription prop is enabled to add a column that links directly to the subscription associated with each invoice, which is useful for subscription-based services.
Filtering Invoices#
You can use various props to filter the invoices displayed. For example, to show only paid invoices related to staking:
FilteredInvoiceListPage.tsx
import { PaymentProvider, CustomerInvoiceList } from '@blocklet/payment-react';
function FilteredInvoiceList() {
const customerId = 'cus_xxxxxxxxxxxxxx';
return (
<PaymentProvider>
<CustomerInvoiceList
customer_id={customerId}
type="table"
status="paid" // Only show paid invoices
include_staking={true} // Also include staking transactions
/>
</PaymentProvider>
);
}Enabling Payments for Open Invoices#
By setting the action prop to 'pay', you can add a "Pay" button to any invoices with open or uncollectible status. Clicking this button will initiate the payment flow using the connect instance from PaymentProvider.
PayableInvoiceListPage.tsx
import { PaymentProvider, CustomerInvoiceList } from '@blocklet/payment-react';
function PayableInvoiceList() {
const customerId = 'cus_xxxxxxxxxxxxxx';
return (
<PaymentProvider>
<CustomerInvoiceList
customer_id={customerId}
status="open,uncollectible" // Show only invoices that need payment
action="pay" // Add a "Pay" button
/>
</PaymentProvider>
);
}