Autumn Payments
Always consult docs.useautumn.com for code examples and latest API.
Autumn handles Stripe checkout, upgrades, downgrades, and cancellations automatically.
Quick Reference
Payment Flow
checkout- Returns Stripe URL (new) or preview data (returning customer)attach- Confirms purchase when card already on file
Checkout Result
| Field | Description |
|---|---|
url | Stripe checkout URL (null if card on file) |
product | Target product with scenario |
current_product | Customer's current product |
lines | Invoice line items |
total | Amount in major currency units |
currency | Currency code |
Product Scenarios
| Scenario | Meaning | Action |
|---|---|---|
new | Not subscribed | Subscribe |
active | Current plan | Current Plan |
scheduled | Scheduled | Already Scheduled |
upgrade | Higher tier | Upgrade |
downgrade | Lower tier | Downgrade |
renew | Cancelled | Renew |
React Implementation
tsx1import { useCustomer, usePricingTable } from "autumn-js/react"; 2 3const { checkout, attach } = useCustomer(); 4const { products } = usePricingTable(); 5 6// Checkout flow 7const data = await checkout({ productId: "pro" }); 8if (data.url) { 9 window.location.href = data.url; // New customer 10} else { 11 // Show confirmation dialog, then: 12 await attach({ productId: "pro" }); 13} 14 15// Cancel 16const { cancel } = useCustomer(); 17await cancel({ productId: "pro" }); 18// Or downgrade to free: 19await attach({ productId: "free" });
Backend Implementation
typescript1import { Autumn } from "autumn-js"; 2 3const autumn = new Autumn({ secretKey: process.env.AUTUMN_SECRET_KEY }); 4 5// Checkout 6const { data } = await autumn.checkout({ customer_id, product_id: "pro" }); 7if (data.url) return redirect(data.url); 8 9// Attach (after user confirms) 10await autumn.attach({ customer_id, product_id: "pro" }); 11 12// Get products with scenarios 13const { data: productsData } = await autumn.products.list({ customer_id });
Prepaid Pricing
For seat-based or prepaid products, pass quantities:
typescript1await autumn.checkout({ 2 customer_id, 3 product_id: "credits_pack", 4 options: [{ feature_id: "credits", quantity: 500 }], 5});
Button Text Pattern
typescript1function getButtonText(product: Product): string { 2 const { scenario, properties } = product; 3 if (properties?.has_trial) return "Start Trial"; 4 if (scenario === "active") return "Current Plan"; 5 6 const text = { upgrade: "Upgrade", downgrade: "Downgrade", new: "Subscribe" }; 7 return text[scenario] ?? "Enable"; 8}
Common Gotchas
- URL field - It's
data.url, notdata.checkout_url - Don't build custom logic - Use
products.listfor scenarios - Proration automatic - Autumn handles upgrade/downgrade proration
- Cancel via free - Prefer attaching free plan over hard cancel
- Success URL - Pass
success_urlto redirect after Stripe checkout