Skip to main content

Using hosted pages

By default, billing.attach returns a paymentUrl — just redirect the customer and Autumn handles payment collection, confirmation, and activation.
const response = await autumn.billing.attach({
  customerId: "user_123",
  planId: "pro",
});

redirect(response.paymentUrl);
New customers without a payment method are sent to Stripe Checkout. Existing customers are sent to Autumn Checkout to review and confirm. After checkout, the customer is redirected to your successUrl (or the default URL in your Autumn dashboard).

Building your own checkout

For full control over the checkout experience, use redirectMode: "if_required". This charges the saved payment method directly instead of redirecting — the customer is only sent to Stripe Checkout if they don’t have a payment method yet.

Step 1: Preview the charge

Call billing.previewAttach to get line items, totals, and proration details to display in your UI.
const preview = await autumn.billing.previewAttach({
  customerId: "user_123",
  planId: "pro",
});

// preview.lineItems  — array of charges and credits
// preview.total      — net amount in cents
// preview.currency   — e.g. "usd"

Step 2: Confirm and charge

Once the customer confirms, call billing.attach with redirectMode: "if_required".
const response = await autumn.billing.attach({
  customerId: "user_123",
  planId: "pro",
  redirectMode: "if_required",
});

if (response.paymentUrl) {
  redirect(response.paymentUrl);
} else {
  showSuccess();
}

Handling the response

The billing.attach response has two key fields: payment_url — a URL the customer should be redirected to, or null if no redirect is needed. required_action — present when payment couldn’t be processed automatically. See Edge Cases for details on handling 3DS, payment failures, and retries.