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.
Before you start
- 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-keyheader. 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} SandboxAltruon 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
- Create a session against the sandbox URL with your sandbox secret key.
- Open
checkout_urlin a browser. Check that the order summary shows the plan and that the fields you sent are filled in. - Complete a test payment. See Testing for sandbox test cards.
- Confirm that you land on your
redirectUrland 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 field | Hosted checkout field |
|---|---|
customerData.firstName | First name (main customer block) |
customerData.lastName | Last name (main customer block) |
customerData.email | |
customerData.phone | Phone |
customerData.billingAddress.street | Billing address line 1 |
customerData.billingAddress.number | Billing address line 2 |
customerData.billingAddress.city | City |
customerData.billingAddress.state | State or province |
customerData.billingAddress.zipCode | Zip or postal code |
customerData.billingAddress.country | Country |
customerData.shippingAddress.* | Shipping fields, if enabled in the backoffice |
document (top level) | PagBrasil CPF or CNPJ on the Pix and card forms |
billingData.couponCodes | Pre-applied coupons in the order summary |
billingData.lineItems | Plan, 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
billingAddressas you already know, especiallycountry, 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.firstNameandbillingAddress.lastNameas well ascustomerData.firstNameandcustomerData.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.
| Field | What it does on the hosted page |
|---|---|
hostedCheckout | Set it to true. The response then includes checkout_url. Do not combine it with hostedPageConfigId. |
paymentData.paymentMethod | Omit 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, document | Pre-fill the form. See Pre-fill customer data. |
locale | Sets the language of the page. See Language. |
billingData.couponCodes | Pre-applies coupons in the order summary. See Coupons. |
billingData.metadata | Attaches your own key and value pairs to the subscription on your billing platform. See Metadata and custom fields. |
billingData.customerCustomFields | Chargebee only: writes custom fields on the Chargebee customer. |
billingData.forceTrialPeriodDays | Overrides the trial length for this checkout. See Override trial length per checkout. |
redirectUrl | Where 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 send | Mode | What the shopper sees | payment_method_pinned_at_create |
|---|---|---|---|
No paymentData.paymentMethod | Discovery | Every 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) | Pinned | Only 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 ascf_field1orcf_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,customerCustomFieldsis 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-keyheader. 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}) | |
|---|---|---|
| Setup | Created in the backoffice under Settings > Hosted Pages | Created with the Create Session API from your server |
| Cart and customer | Fixed per link, editable in the backoffice | Passed in each API call |
| URL | Opaque hosted page ID | Session ID from the API response |
| Conversion analytics | Per-link stats in the backoffice | Not tracked in Settings > Hosted Pages, because there is no static configuration |
| Session expiry | The shopper can restart from the same link | You must create a new session |
| Branding | Site checkout configuration, Classic or Neo skin | The same site checkout configuration |
| Customer pre-fill | No. The shopper enters all details | Yes, from customerData in the Create Session call |
See Choose your checkout for the comparison with Altruon.js.