Skip to Content
Checkout

Dynamic hosted checkout

Create a session from your server with the cart and the customer, then redirect the shopper to an Altruon-hosted checkout page.

Dynamic hosted checkout sends a shopper to a checkout page hosted by Altruon, with the cart and the customer data defined at runtime by your server. Pick this route when each checkout is unique (plan, customer, coupons) and created from your backend, for example when you replace Stripe Billing hosted pages with Altruon and your billing platform.

Dynamic hosted checkout
Your serverAltruonShopper01 POST /api/session/v1/create02 session_id, checkout_url03 Redirect to checkout_url04 Pays on the hosted page05 Redirect to redirectUrl
The secret key never leaves your server. The shopper only ever sees the checkout URL.

Before you start

  • An acquirer is connected, with a routing entryThe routing entries for the session currency decide which payment methods the page shows. See Acquirers and Routing.
  • A billing platform is connectedYou pass its connection ID as billingData.billingPlatformId. See Billing platforms.
  • Your checkout appearance is configuredBranding, fields, redirect and skin come from Settings > Checkout, the same configuration hosted pages use. See Set up your checkout appearance.
  • Your secret keySessions are created with the x-secret-key header. See Authentication.

Create a checkout

Create the session

Call the Create Session API from your server with hostedCheckout: true, the line items, and the URL the shopper returns to. Add customerData to open the form pre-filled.

curl -X POST "https://{your-domain}.api.sandbox.altruon.io/api/session/v1/create" \
  -H "Content-Type: application/json" \
  -H "x-secret-key: sk_sandbox_..." \
  -d '{
    "hostedCheckout": true,
    "paymentData": { "currency": "BRL" },
    "billingData": {
      "billingPlatformId": "3287b8c7-ce43-41fd-9d58-f510e610b8f3",
      "lineItems": [{ "type": "plan", "id": "price_xxx", "quantity": 1 }]
    },
    "customerData": {
      "firstName": "João",
      "lastName": "Silva",
      "email": "joao@example.com"
    },
    "redirectUrl": "https://your-site.com/success"
  }'

In production, call https://{your-domain}.api.altruon.io with your production secret key. The Create Session reference lists every field.

Read the response

Altruon returns the session ID, the checkout URL and the expiry time.

{
  "session_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "expires_at": "2026-06-21T12:15:00Z",
  "checkout_url": "https://{your-domain}.sandbox.altruon.io/checkout/s/a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "locale": "pt_br",
  "payment_method_pinned_at_create": false,
  "available_payment_methods": [
    {
      "payment_method": "pix",
      "gateway": "PAGBRASIL",
      "gateway_connection_id": "..."
    },
    {
      "payment_method": "card",
      "gateway": "CHECKOUTCOM",
      "gateway_connection_id": "..."
    }
  ]
}

Redirect the shopper

Send the shopper to checkout_url. You can also build the URL yourself from session_id:

https://{your-domain}.altruon.io/checkout/s/{sessionId}              Production
https://{your-domain}.sandbox.altruon.io/checkout/s/{sessionId}      Sandbox

Altruon loads the session and renders your branded checkout with the order summary and the fields pre-filled from the session. You do not need a separate update call before the redirect.

Receive the shopper back

On success, the shopper is redirected to the session's redirectUrl, or to the Redirect URL of your site's checkout configuration. A subscription is created on your billing platform and the invoice is marked paid.

Test it

  1. Create a session against the sandbox URL with your sandbox secret key.
  2. Open checkout_url in a browser. Check that the order summary shows the plan and that the fields you sent are filled in.
  3. Complete a test payment. See Testing for sandbox test cards.
  4. Confirm that you land on your redirectUrl and that the subscription exists on your billing platform.

Pre-fill customer data

When the shopper opens /checkout/s/{sessionId}, Altruon pre-populates the form with the customerData and the top-level document you sent in the Create Session call. This applies to dynamic hosted checkout only: hosted pages always start with empty customer fields.

What gets pre-filled

Create Session fieldHosted checkout field
customerData.firstNameFirst name (main customer block)
customerData.lastNameLast name (main customer block)
customerData.emailEmail
customerData.phonePhone
customerData.billingAddress.streetBilling address line 1
customerData.billingAddress.numberBilling address line 2
customerData.billingAddress.cityCity
customerData.billingAddress.stateState or province
customerData.billingAddress.zipCodeZip or postal code
customerData.billingAddress.countryCountry
customerData.shippingAddress.*Shipping fields, if enabled in the backoffice
document (top level)PagBrasil CPF or CNPJ on the Pix and card forms
billingData.couponCodesPre-applied coupons in the order summary
billingData.lineItemsPlan, add-ons and pricing in the order summary

Field visibility

Only the fields enabled under Settings > Checkout > Fields are shown on the page. Data you send for a hidden field is still stored on the session and used at payment time, but the shopper does not see that input.

Email and the main first name and last name fields are always collected. The billing and shipping address blocks depend on your field configuration.

Good practice

  • Send the address early. Include as much of billingAddress as you already know, especially country, which is used for tax and routing. Altruon skips its IP-based country guess when the session already provides a country.
  • Names inside the billing address. If your checkout skin shows first name and last name inside the billing address section, set billingAddress.firstName and billingAddress.lastName as well as customerData.firstName and customerData.lastName.
  • Pre-filled values are a starting point. They are not locked. The shopper can change them before subscribing.
  • Retries keep the data. After a 3D Secure failure or a card decline, the shopper returns to the same session URL and the form is restored from the saved session data.

Address and document example

The request in Create the session pre-fills the name and the email only. This customerData block adds the phone, the full address and the document for a shopper in Brazil:

{
  "customerData": {
    "firstName": "João",
    "lastName": "Silva",
    "email": "joao@example.com",
    "phone": "+5511999999999",
    "billingAddress": {
      "street": "Av. Paulista",
      "number": "1000",
      "city": "São Paulo",
      "state": "SP",
      "zipCode": "01310-100",
      "country": "BR"
    }
  },
  "document": "12345678909"
}

Session options

These fields of the Create Session request shape the hosted page. The Create Session reference has the full list with types and limits.

FieldWhat it does on the hosted page
hostedCheckoutSet it to true. The response then includes checkout_url. Do not combine it with hostedPageConfigId.
paymentData.paymentMethodOmit it to let the shopper choose among all the methods routed for the currency. Set it to show one method only. See Payment method.
customerData, documentPre-fill the form. See Pre-fill customer data.
localeSets the language of the page. See Language.
billingData.couponCodesPre-applies coupons in the order summary. See Coupons.
billingData.metadataAttaches your own key and value pairs to the subscription on your billing platform. See Metadata and custom fields.
billingData.customerCustomFieldsChargebee only: writes custom fields on the Chargebee customer.
billingData.forceTrialPeriodDaysOverrides the trial length for this checkout. See Override trial length per checkout.
redirectUrlWhere the shopper lands after a successful payment.

Full example

{
  "hostedCheckout": true,
  "paymentData": {
    "currency": "BRL"
  },
  "billingData": {
    "billingPlatformId": "3287b8c7-ce43-41fd-9d58-f510e610b8f3",
    "lineItems": [
      {
        "type": "plan",
        "id": "price_1SMtJj4hYau76GhIakR22BKu",
        "quantity": 1
      }
    ],
    "couponCodes": ["LAUNCH10"],
    "metadata": {
      "field_1": "value_123",
      "user_id": "user_456"
    },
    "customerCustomFields": {
      "cf_field1": "value_1",
      "cf_field2": "value_2"
    }
  },
  "customerData": {
    "firstName": "João",
    "lastName": "Silva",
    "email": "joao@example.com",
    "phone": "+5511999999999",
    "billingAddress": {
      "street": "Av. Paulista",
      "number": "1000",
      "city": "São Paulo",
      "state": "SP",
      "zipCode": "01310-100",
      "country": "BR"
    }
  },
  "document": "12345678909",
  "locale": "pt_br",
  "redirectUrl": "https://your-site.com/subscription/success"
}

Payment method

You sendModeWhat the shopper seespayment_method_pinned_at_create
No paymentData.paymentMethodDiscoveryEvery payment method routed for the currency, for example Pix and card for BRL. All methods stay available if a payment fails.false
"paymentMethod": "card" (or "pix", and so on)PinnedOnly that method, for the whole session.true

In discovery mode the response lists the routed methods in available_payment_methods, as in the example above.

Language

Set locale to en or pt_br. The API also accepts pt-BR, pt and en-US. Unsupported values fall back to English. When you omit locale, the hosted page picks the language from the currency: Portuguese for BRL, English for every other currency.

Metadata and custom fields

billingData.metadata attaches your key and value pairs to the subscription on your billing platform: subscription metadata on Stripe Billing, meta_data on Chargebee. It is the equivalent of subscription_data.metadata on Stripe hosted checkout.

When Chargebee is the billing platform for the checkout, pass customer custom fields in billingData.customerCustomFields:

  • Altruon sends every key that starts with cf_, such as cf_field1 or cf_field2, on the Chargebee customer create call.
  • Keys that do not start with cf_ are rejected.
  • The map is separate from billingData.metadata. Metadata is stored on the subscription, customerCustomFields is written on the Chargebee customer.
  • Set the map when you create the session. It is not returned to the shopper, and the hosted page cannot change it.

Document for Brazil

Set the top-level document field to pre-fill the PagBrasil CPF or CNPJ on the Pix and card forms.

Appearance

The logo, the colors, the Classic or Neo skin and the redirect after payment come from Settings > Checkout. The per-session styleCustomization object does not apply here: it styles the embedded Altruon.js component only.

Failed payments

If a card payment fails after a redirect to the acquirer, for example a failed 3D Secure challenge or a decline, the shopper returns to the same /checkout/s/{sessionId} URL. The form data is restored so they can retry while the session is still valid.

Session expiry

A session expires 15 minutes after you create it. An expired dynamic session cannot be restarted from the checkout page: create a new session from your server and redirect the shopper again.

Security

  • Create sessions only from your server, with the x-secret-key header. Never expose the secret key in the browser.
  • Sessions are scoped to your subdomain. A session created for one Altruon domain cannot be loaded on another.
  • The session ID is the access token for that checkout. Treat it like a single-use checkout token and share the URL only with the intended shopper.

Differences from hosted pages

Hosted pages (/checkout/p/{id})Dynamic hosted checkout (/checkout/s/{sessionId})
SetupCreated in the backoffice under Settings > Hosted PagesCreated with the Create Session API from your server
Cart and customerFixed per link, editable in the backofficePassed in each API call
URLOpaque hosted page IDSession ID from the API response
Conversion analyticsPer-link stats in the backofficeNot tracked in Settings > Hosted Pages, because there is no static configuration
Session expiryThe shopper can restart from the same linkYou must create a new session
BrandingSite checkout configuration, Classic or Neo skinThe same site checkout configuration
Customer pre-fillNo. The shopper enters all detailsYes, from customerData in the Create Session call

See Choose your checkout for the comparison with Altruon.js.

Next steps