Overview
Pre-built, conversion-optimized pages for checkout and customer management. No frontend code required.Checkout Sessions
Create a hosted checkout page for one-time payments or subscriptions.Create Checkout Session
curl -X POST https://api.atlas.co/functions/v1/checkout-sessions \
-H "Authorization: Bearer sk_test_xxx" \
-H "Content-Type: application/json" \
-d '{
"mode": "subscription",
"line_items": [
{ "price": "price_xxx", "quantity": 1 }
],
"success_url": "https://yoursite.com/success?session_id={CHECKOUT_SESSION_ID}",
"cancel_url": "https://yoursite.com/canceled",
"subscription_data": {
"trial_period_days": 14
}
}'
| Parameter | Type | Required | Description |
|---|---|---|---|
mode | string | Yes | payment or subscription |
line_items | array | Yes | Array of price objects with quantity |
success_url | string | Yes | Redirect URL after successful payment |
cancel_url | string | Yes | Redirect URL if customer cancels |
customer | string | No | Existing customer ID |
customer_email | string | No | Pre-fill customer email |
subscription_data.trial_period_days | integer | No | Free trial days |
{
"id": "cs_xxx",
"object": "checkout.session",
"url": "https://checkout.atlas.co/abc123",
"mode": "subscription",
"status": "open",
"expires_at": 1704931200
}
Redirect to Checkout
// Create session on your server
const response = await fetch('/api/create-checkout', { method: 'POST' });
const { url } = await response.json();
// Redirect to hosted checkout
window.location.href = url;
Customer Portal Sessions
Let customers manage their subscriptions, payment methods, and invoices.Create Portal Session
curl -X POST https://api.atlas.co/functions/v1/portal-sessions \
-H "Authorization: Bearer sk_test_xxx" \
-H "Content-Type: application/json" \
-d '{
"customer": "cus_xxx",
"return_url": "https://yoursite.com/account",
"configuration": {
"features": {
"subscription_cancel": { "enabled": true },
"subscription_pause": { "enabled": true },
"payment_method_update": { "enabled": true },
"invoice_history": { "enabled": true }
}
}
}'
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | Yes | Customer ID |
return_url | string | Yes | URL to return to after portal |
configuration.features.subscription_cancel | object | No | Object with enabled boolean |
configuration.features.subscription_pause | object | No | Object with enabled boolean |
configuration.features.payment_method_update | object | No | Object with enabled boolean |
configuration.features.invoice_history | object | No | Object with enabled boolean |
{
"id": "bps_xxx",
"object": "billing_portal.session",
"url": "https://portal.atlas.co/xyz789",
"customer": "cus_xxx",
"return_url": "https://yoursite.com/account",
"expires_at": 1704848400
}
Portal Features
| Feature | Description |
|---|---|
| subscription_cancel | Allow customers to cancel subscriptions |
| subscription_pause | Allow customers to pause subscriptions |
| payment_method_update | Allow customers to update payment methods |
| invoice_history | Show invoice history and download PDFs |
Full Integration Example
// Server-side: Create checkout session
app.post('/api/checkout', async (req, res) => {
const session = await atlas.checkoutSessions.create({
mode: 'subscription',
line_items: [{ price: 'price_xxx', quantity: 1 }],
success_url: 'https://yoursite.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'https://yoursite.com/pricing',
});
res.json({ url: session.url });
});
// Server-side: Create portal session
app.post('/api/portal', async (req, res) => {
const session = await atlas.portalSessions.create({
customer: req.user.customerId,
return_url: 'https://yoursite.com/account',
});
res.json({ url: session.url });
});
<!-- Client-side buttons -->
<button onclick="goToCheckout()">Subscribe</button>
<button onclick="goToPortal()">Manage Subscription</button>
<script>
async function goToCheckout() {
const { url } = await fetch('/api/checkout', { method: 'POST' }).then(r => r.json());
window.location.href = url;
}
async function goToPortal() {
const { url } = await fetch('/api/portal', { method: 'POST' }).then(r => r.json());
window.location.href = url;
}
</script>