isLoading: boolean, mutations via isPending: boolean — plus error: Error | null. See Introduction. The sections below list each hook’s specific returns.
usePaymentMethods
Loads the customer’s saved payment methods and exposes the two write actions a wallet UI needs:setDefault(id) and detach(id). Both invalidate the customer scope on success so the list re-renders. Takes no arguments; the customer comes from <UnitPayProvider> context.
Returns
paymentMethods—PaymentMethod[]— the customer’s saved methods, or[]while loading or when none exist. Card fields (cardLast4,cardBrand,expMonth,expYear) arenullfor non-card types.setDefault(paymentMethodId)—(id: string) => Promise<void>— points the customer default at this method. Invalidates the customer scope on success.detach(paymentMethodId)—(id: string) => Promise<void>— removes the method. Invalidates the customer scope on success. ThrowsPmInUseErrorwhen the method is a default still powering an active sub or auto-topup rule (see the warning below).isActing—boolean—truewhile asetDefaultordetachmutation is in flight.
usePaymentMethodDependencies
The preflight query for a “remove card” confirmation modal. It returns whether the method is the customer default and, if so, the active subscriptions and auto-topup credit accounts that a detach would orphan.data.blocksDetach mirrors the server-side guardrail — when true, route the user to the replace flow instead of letting them click “Delete”.
Parameters
The method to inspect. The query is disabled while this is
null / undefined.When
false, the query is disabled — useful for a modal that fetches on open (enabled: isOpen). Defaults to true.UseQueryResult<PaymentMethodDependencies, Error> (short staleTime of 10s, because dependency state changes whenever subs / auto-topup rules change). data once loaded is PaymentMethodDependencies:
paymentMethodIdstringisDefaultboolean— whether this is the customer default.blocksDetachboolean—truewhen detaching would orphan an active sub or auto-topup rule.activeSubscriptions—Array<{ id, status, planId, collectionMethod, currentBillingPeriodEnd }>.autoTopupAccounts—Array<{ id, creditCurrencyId, autoTopupThreshold, autoTopupAmount, autoTopupPackageId }>.
useSetupPaymentMethod
Mutation that captures a new payment method via a PSP SetupIntent. It always resolves to arequires_form SettleOutcome — the server mints a SetupIntent and returns the PSP client envelope, which you mount in <PaymentForm mode="save_only">. After the customer completes setup and the PSP webhook attaches the method, the payment-methods cache is invalidated so the next render shows it.
Parameters
Settlement callbacks dispatched after the mutation resolves — wire
onRequiresForm to mount the inline form. See the Settlement model.setupPaymentMethod(input?) alias accepts an optional input:
Where to send the customer after a successful hosted-mode setup.
Where to send the customer if they abandon a hosted-mode setup.
Whether to render the form inline (
embedded) or redirect to the PSP-hosted page (hosted).UseMutationResult extended with setupPaymentMethod(input?), which triggers the SetupIntent and resolves to a requires_form outcome whose client.token is the Stripe Elements clientSecret.
useReplacePaymentMethod
Mutation that performs an atomic “swap A for B” — it flips the customer default to the new method and detaches the old one in one server transaction. It’s the resolution path whenusePaymentMethodDependencies reports blocksDetach: the old default is still powering active subs / auto-topup rules, so you can’t just detach it.
Parameters — the hook takes no arguments; the replacement pair goes to the replacePaymentMethod(input) alias:
The method being replaced — typically the customer’s current default.
The method to become the new default. Must already be attached and active (capture one first with
useSetupPaymentMethod).UseMutationResult extended with replacePaymentMethod(input), which runs the swap and resolves to a ReplacePaymentMethodResult. On success it invalidates all customer-scoped queries (the PM list, default pointer, sub references). The result carries:
customerIdstringoldPaymentMethodIdstringnewPaymentMethodIdstringbecameDefaultboolean—trueiff the default pointer actually moved this call.clearedOldDefaultboolean—trueiff the old method was the default (and is now cleared).
See also
Invoices
Collect payment with
usePayInvoice once a method is on file.Settlement model
The
requires_form outcome and client envelope behind card capture.Error handling
The SDK error model and
PmInUseError.Customer
setupPayment() on useCustomer mints a hosted-link alternative.