Skip to main content
Create hosted payment pages for checkout and customer self-service.

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
    }
  }'
Parameters:
ParameterTypeRequiredDescription
modestringYespayment or subscription
line_itemsarrayYesArray of price objects with quantity
success_urlstringYesRedirect URL after successful payment
cancel_urlstringYesRedirect URL if customer cancels
customerstringNoExisting customer ID
customer_emailstringNoPre-fill customer email
subscription_data.trial_period_daysintegerNoFree trial days
Response:
{
  "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 }
      }
    }
  }'
Parameters:
ParameterTypeRequiredDescription
customerstringYesCustomer ID
return_urlstringYesURL to return to after portal
configuration.features.subscription_cancelobjectNoObject with enabled boolean
configuration.features.subscription_pauseobjectNoObject with enabled boolean
configuration.features.payment_method_updateobjectNoObject with enabled boolean
configuration.features.invoice_historyobjectNoObject with enabled boolean
Response:
{
  "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

FeatureDescription
subscription_cancelAllow customers to cancel subscriptions
subscription_pauseAllow customers to pause subscriptions
payment_method_updateAllow customers to update payment methods
invoice_historyShow 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>