Skip to Content
Headless SDKHooksProducts & Payments

Products & Payments Hooks

Hooks for accessing the product catalog, selection state, and payment information.

useProducts()

Access the product catalog and selection state. Only re-renders when the selected product changes.

const { products, selected, select } = useProducts() return ( <div> {products.map((p) => ( <button key={p.id} onClick={() => select(p.id)}> {p.name} - {p.price}/{p.period} </button> ))} {selected && <p>Selected: {selected.displayName}</p>} </div> )
PropertyTypeDescription
productsRuntimeProduct[]All configured products with resolved pricing
selectedRuntimeProduct | nullCurrently selected product
select(productId: string) => voidSelect a product by ID

RuntimeProduct (key fields)

FieldTypeDescription
idstringProduct identifier
namestringProduct name from config
displayNamestringResolved display name
pricestringFormatted price (e.g. "$9.99")
rawPricenumberPrice in cents/smallest unit
monthlyPricestringNormalized monthly price
weeklyPricestringNormalized weekly price
dailyPricestringNormalized daily price
yearlyPricestringNormalized yearly price
periodstringBilling period label (e.g. "month")
periodlystringAdverb form (e.g. "monthly")
periodDaysnumberPeriod length in days
currencyCodestringISO currency code (e.g. "USD")
currencySymbolstringCurrency symbol (e.g. "$")
hasTrialbooleanWhether the product has a trial
trialDaysnumberTrial length in days
trialPricestringFormatted trial price
paidTrialbooleanWhether the trial has a cost
storePriceIdstringPrice ID from the payment provider
stripePriceIdstringStripe price ID
paddlePriceIdstringPaddle price ID

usePayment()

Payment hook for triggering purchases and reading loading/error state. Only re-renders when payment state changes.

const { loading, error, purchase } = usePayment()
PropertyTypeDescription
loadingbooleanPayment operation in progress
errorstring | nullLast payment error message
purchase(productId: string, options?) => Promise<boolean>Purchase a product using the card on file

purchase(productId, options?)

Charges the card already on file for the given product. This is typically used on upsell pages after the user has already entered their card on the paywall via StripePaymentForm.

Automatically handles 3DS authentication, trial periods, and tracks purchase.complete / subscription.created events. Sets loading and error state during the operation.

In dev mode, the purchase simulates a successful charge after a short delay.

const { products } = useProducts() const { goToNextPage } = useNavigation() const { loading, purchase } = usePayment() const upsellProduct = products.find((p) => p.id.startsWith('upsell')) const handleAdd = () => { if (!upsellProduct) return purchase(upsellProduct.id, { onSuccess: () => goToNextPage(), onError: (error) => console.error(error), }) }

Options

FieldTypeDescription
onSuccess() => voidCalled when the purchase completes successfully
onError(error: string) => voidCalled with the error message on failure

Returns a Promise<boolean>true on success, false on failure.

Last updated on