isLoading: boolean, the mutation via isPending: boolean — plus error: Error | null. See Introduction. The sections below list each hook’s specific returns.
useInvoices
Fetches the full invoice history for the customer in context as one cached list, plus adownloadPdf(id) helper that opens a row’s finalized PDF in a new tab. Takes no arguments; the customer comes from <UnitPayProvider> context.
Returns
invoices—Invoice[]— every invoice on the customer, or[]while loading or when none exist.statusmirrors the DB enum (draft·issued·partially_paid·paid·overdue·void·uncollectible); amounts (totalAmount,amountDue,amountPaid) are in minor units.downloadPdf(invoiceId)— opens the matching invoice’spdfUrlin a new tab. No-op when the row has no link yet (still finalizing) or when called outside the browser — grey out the button on!invoice.pdfUrl.
useInvoice
Loads the full payload for a single invoice — the header fields plus its lineitems and successful payments — for an invoice detail page. The server filters payments to status = 'succeeded', so the portal never has to hide retry noise.
Parameters
The invoice to fetch. The query is disabled (and
invoice stays null) while this is null / undefined.invoice—InvoiceDetail | null— the invoice plusitems: InvoiceItem[]andpayments: InvoicePayment[], ornullwhile loading. Amounts are in minor units.downloadPdf()— opens the invoice’spdfUrlin a new tab. No-op until the PDF finalizes server-side or when called outside the browser — grey out the button on!invoice.pdfUrl.
useUpcomingInvoice
Previews the next renewal for a subscription — the “you’ll be charged $X on date Y” portal card. It’s a pure read (GET /v1/subscriptions/:id/upcoming-invoice) that never mutates state; the server computes the line items from the current sub config (plan + addons + usage so far) at request time.
Parameters
The subscription to preview. The query is disabled (and
invoice stays null) while this is omitted.invoice: UpcomingInvoice | null — the renewal preview, or null when there is no upcoming renewal (canceled / ended subs, or before trial end) and while loading. Amounts are in minor units. creditApplied is always 0 in the preview.
usePayInvoice
Mutation that pays one outstanding invoice. The server picks the path — inline charge of a saved card, a hosted recovery form, or no action — and resolves to aSettleOutcome. Pass on* settlement handlers to wire your UX to each outcome.
Parameters
The invoice to collect payment for.
Settlement callbacks dispatched after the mutation resolves —
onChargedInline, onRequiresForm, onNoAction, etc. See the Settlement model.pay(input?) alias accepts an optional input:
Override the auto-generated
Idempotency-Key.Force the server to mint
requires_form even when a payment method is on file — the customer always sees the inline <PaymentForm> and explicitly confirms, instead of a silent off-session debit. Portal callers typically set this true.UseMutationResult extended with pay(input?) => Promise<SettleOutcome>. On success the hook invalidates the single-invoice cache and the full customer scope (settling an invoice can move money, change credit balance, and unblock a past_due sub), then dispatches your options handlers. The server picks the path:
- Customer has a PM and
amountDue > 0and noforceForm→ inline charge →charged_inline - No PM, or
forceForm, or the inline charge fails → mints a recovery checkout →requires_form - Already paid, or
amountDue === 0→no_action
forceForm is a per-call input — pass it to pay({ forceForm: true }), not to the hook’s options argument. The second argument (UsePayInvoiceOptions, which equals HandleSettlementOptions) carries only your settlement callbacks. The pay() input is where idempotencyKey and forceForm overrides live.See also
Settlement model
The full
SettleOutcome union and handleSettlement dispatch behind usePayInvoice.Payment methods
Capture a card before paying, or replace an in-use default.
Subscriptions
The subscriptions these invoices bill for.
Customer
payInvoice() on useCustomer mints a hosted-link alternative.