Skip to Content
API reference · Sessions

Create a session

Create a session from your server for Altruon.js or dynamic hosted checkout. Every request field, the response and code samples.

Creates a session: the currency, the cart and optional customer data for one checkout attempt. A session is single use and expires 15 minutes after you create it.

POST/api/session/v1/create
Sandbox
https://{your-domain}.api.sandbox.altruon.io
Production
https://{your-domain}.api.altruon.io

Authentication: your secret key in the x-secret-key header. Call this endpoint from your server only. See Authentication.

One request shape serves two checkouts:

CheckoutRequestWhat you use from the response
Altruon.js (embedded)hostedCheckout omitted or falsePass session_id to the browser and call altruon.setSession()
Dynamic hosted checkouthostedCheckout: trueRedirect the shopper to checkout_url

For how sessions behave, see Sessions.

Request body

Send JSON with Content-Type: application/json.

paymentDataobjectrequired

Payment settings for the session.

currencystringrequired

Three-letter ISO 4217 currency code, for example USD, EUR or BRL. Set it here: it cannot be changed from the browser.

paymentMethodstring

Payment method to lock the session to, for example card, pix or upi. Other values used in these docs: applepay, kakaopay, openbanking.

Omit it for discovery mode. On hosted checkout the shopper then sees every payment method routed for the session currency. On Altruon.js the component follows your routing entries: several entries for the currency render a drawer where the shopper picks a method, a single entry renders only the fields of that method.

Pass it and only that method is shown, for the life of the session. See Payment method pinning.

billingDataobjectrequired

The cart, and the billing platform that owns it.

billingPlatformIdstringrequired

ID of your billing platform connection in Altruon. Find it in the backoffice under Settings > Billing Platforms. Set it here: it cannot be changed from the browser.

lineItemsarray of objectsrequired

Items to purchase. Put exactly one plan item first, then add-ons. Set them here: they cannot be changed from the browser.

typestringrequired

Kind of item. plan for the subscription plan, charge for a one-time charge. Add-ons have their own types.

idstringrequired

ID of the item on your billing platform, for example a Stripe Billing price ID such as price_1SMtJj4hYau76GhIakR22BKu.

quantityinteger or stringrequired

Number of units. The examples in these docs send both 1 and "1".

frequencystring

Billing frequency, for example monthly, yearly or weekly.

couponCodesarray of strings

Coupons to apply to the estimate and to the subscription. An empty array sends no coupon. The billing platform rejects unknown coupons. See Coupons.

metadataobject

Your own key and value pairs, both strings. At most 50 keys. A key has at most 40 characters, a value at most 500 characters.

Altruon forwards them to the billing platform when the subscription is created:

  • Stripe Billing: subscription metadata
  • Chargebee: subscription meta_data
  • Frisbii: subscription metadata
  • Recurly: subscription custom_fields. The field names must already exist in Recurly.
customerCustomFieldsobject

Chargebee only. Custom fields written on the Chargebee customer when it is created. Every key must start with cf_, for example cf_field1. Keys without that prefix are rejected.

This map is separate from metadata, which is stored on the subscription. It is not returned to the shopper, and the hosted page cannot change it.

forceTrialPeriodDaysinteger

Trial length in days, from 1 to 730. Starts a trial with nothing due today for the subscription and overrides any trial configured on the plan. Line items of type charge are still charged today.

It must be nested inside billingData. At the top level of the body it is ignored. It cannot be used with hosted pages (hostedPageConfigId). See Trials.

redirectUrlstringrequired

Where the shopper goes after a successful payment. A full URL including the protocol, for example https://example.com/success.

After a redirect flow such as 3D Secure or a bank login, Altruon returns the shopper to this URL with ?trx_id= and the transaction ID appended.

hostedCheckoutbooleandefault false

Set it to true for dynamic hosted checkout. The response then includes checkout_url, and the session uses the full hosted checkout page with your site branding and the order summary.

Do not combine it with hostedPageConfigId: the two are mutually exclusive.

networkTokenboolean

Asks for a network token on the card stored by this checkout. Read only when the network token strategy is On request. Ignored when the strategy is Off or Always. A hosted page does not send it. See Network tokens.

customerDataobject

Customer identity and addresses. Optional. On dynamic hosted checkout these values pre-fill the page. They are defaults: the shopper can edit them before paying. After a failed 3D Secure or card redirect, the session restores the values that were last saved on it.

On Altruon.js you can pass the same fields from the browser instead. See Customer data.

firstNamestring

First name. Fills the main First name field on hosted checkout.

lastNamestring

Last name. Fills the main Last name field.

emailstring

Email address.

phonestring

Phone number, for example +5511999999999. Shown on hosted checkout only if the field is enabled under Settings > Checkout > Fields.

ipstring

IP address of the shopper. Used by some acquirers.

billingAddressobject

Billing address.

streetstring

Address line 1.

numberstring

Address line 2: apartment, suite and so on.

citystring

City.

statestring

State or province.

zipCodestring

Zip or postal code.

countrystring

ISO 3166-1 alpha-2 country code, for example BR or US. If it is not on the session, Altruon.js can set it from the browser.

firstNamestring

First name for the billing address. Send it only if your checkout collects a name under Billing address, separate from the main name fields. It is not copied from customerData.firstName.

lastNamestring

Last name for the billing address. Same rule as firstName.

shippingAddressobject

Shipping address, with the same fields as billingAddress. Shown on hosted checkout only if shipping fields are enabled.

documentstring

Tax or identity document of the shopper, for example a CPF or CNPJ in Brazil. A top-level field, not part of customerData. Pre-fills the document field of the PagBrasil Pix and card forms.

localestring

Language of hosted checkout and of the Altruon.js component. Supported: en and pt_br. pt-BR, pt and en-US are also accepted. Any other value falls back to en.

Omit it and the checkout picks the language from the currency: Portuguese for BRL, English otherwise.

styleCustomizationobject

Appearance of the embedded Altruon.js component. Hosted checkout ignores it and takes its appearance from Settings > Checkout. See Style options.

backgroundColorstringdefault #ffffff

Background color. Hex, rgb or a named color.

primaryColorstringdefault #4B5563

Color of buttons and interactive elements.

secondaryColorstringdefault #9CA3AF

Color of supporting elements.

accentColorstringdefault #3B82F6

Color of highlights and focus states.

borderRadiusstringdefault 8px

Corner radius.

headerTextColorstringdefault #1F2937

Color of header text.

textColorstringdefault #1F2937

Color of body text.

fontFamilystringdefault system-ui, sans-serif

Font family for all text.

dropShadowbooleandefault true

Whether elements have a drop shadow.

Example requests

Minimal request

{
  "paymentData": { "currency": "USD" },
  "redirectUrl": "https://example.com/success",
  "billingData": {
    "billingPlatformId": "3287b8c7-ce43-41fd-9d58-f510e610b8f3",
    "lineItems": [
      { "type": "plan", "id": "price_1SMtJj4hYau76GhIakR22BKu", "quantity": 1 }
    ]
  }
}

Complete request

{
  "paymentData": {
    "currency": "USD",
    "paymentMethod": "card"
  },
  "redirectUrl": "https://example.com/success",
  "locale": "en",
  "billingData": {
    "billingPlatformId": "3287b8c7-ce43-41fd-9d58-f510e610b8f3",
    "lineItems": [
      { "type": "plan", "id": "price_1SMtJj4hYau76GhIakR22BKu", "quantity": 1 }
    ],
    "frequency": "monthly",
    "couponCodes": ["SPRING25"],
    "metadata": {
      "user_id": "user_123",
      "platform": "web"
    }
  },
  "customerData": {
    "email": "shopper@example.com",
    "billingAddress": { "country": "US" }
  },
  "styleCustomization": {
    "backgroundColor": "#ffffff",
    "primaryColor": "#0066FF",
    "secondaryColor": "#6B7280",
    "accentColor": "#0066FF",
    "borderRadius": "12px",
    "headerTextColor": "#000000",
    "textColor": "#1F2937",
    "fontFamily": "Inter, system-ui, sans-serif",
    "dropShadow": true
  }
}

Response

A successful request returns 200 OK.

session_idstring

Unique ID of the session, a UUID.

expires_atstring

ISO 8601 timestamp of when the session expires: 15 minutes after creation.

checkout_urlstring

URL of the hosted checkout page for this session. Present when you sent hostedCheckout: true. Redirect the shopper to it.

localestring

Checkout language of the session, for example pt_br.

payment_method_pinned_at_createboolean

true if you sent paymentData.paymentMethod, false if you left it out. Always present. See Payment method pinning.

available_payment_methodsarray of objects

Payment methods routed for the session currency. Present in discovery mode, when the request had no paymentMethod.

payment_methodstring

Payment method, for example card or pix.

gatewaystring

Acquirer that the method is routed to, for example CHECKOUTCOM or PAGBRASIL.

gateway_connection_idstring

UUID of the acquirer connection.

payment_methodstring

The payment method you pinned. Present when the request had a paymentMethod.

gatewaystring

Acquirer selected for the pinned method. Present when the request had a paymentMethod.

gateway_connection_idstring

UUID of the acquirer connection. Present when the request had a paymentMethod.

trialobject

Present when the plan has a trial in your billing catalog, or when you sent billingData.forceTrialPeriodDays. Output only. See Trials.

inTrialboolean

Whether the cart is in a trial period.

trialStartstring

ISO 8601 timestamp of when the trial starts.

trialEndstring

ISO 8601 timestamp of when the trial ends.

amountDueNowstring

Amount charged at signup. "0" for a trial with nothing else in the cart. With a one-time charge line item, it is the total of the charges.

nextInvoiceDatestring

Date of the first invoice after the trial.

Example responses

{
  "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": "550e8400-e29b-41d4-a716-446655440000"
    },
    {
      "payment_method": "card",
      "gateway": "CHECKOUTCOM",
      "gateway_connection_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7"
    }
  ]
}

checkout_url appears in these examples because the requests set hostedCheckout: true.

Payment method pinning

payment_method_pinned_at_create records what you asked for when you created the session. It does not change when the shopper selects a payment method or retries with another one during checkout.

ValueYou sentHosted checkout shows
falseNo paymentMethod (discovery mode)Every payment method routed for the session currency, for example Pix and card for BRL. After a failed payment all methods stay available, so the shopper can switch.
trueA paymentMethod (pinned)Only that method and its acquirer. It stays locked for the life of the session, including after a failed payment.

Use discovery mode when the shopper should choose. Pin the method when you already know it, for example a card-only upgrade flow or a link in your app that says "pay with Pix".

Hosted checkout reads the field for you. You only need to branch on it if you build your own checkout UI. The same value is returned by GET /api/session/v1/{sessionId}.

Errors

A failed request returns a 4xx or 5xx status with an error object:

{
  "error": {
    "code": "invalid_request",
    "message": "Missing required field: paymentData.currency",
    "details": {}
  }
}

The codes this endpoint returns are invalid_request, unauthorized, invalid_line_item, invalid_billing_platform and rate_limit_exceeded. A trial with nothing due today on an acquirer and payment method that does not support trials is also rejected here. See Errors for what each one means and what to do.

Code samples

Each sample creates a session and reads session_id. Keep the secret key in an environment variable.

curl -X POST "https://{your-domain}.api.sandbox.altruon.io/api/session/v1/create" \
  -H "Content-Type: application/json" \
  -H "x-secret-key: $ALTRUON_SECRET_KEY" \
  -d '{
    "paymentData": { "currency": "USD", "paymentMethod": "card" },
    "redirectUrl": "https://example.com/success",
    "billingData": {
      "billingPlatformId": "3287b8c7-ce43-41fd-9d58-f510e610b8f3",
      "lineItems": [
        { "type": "plan", "id": "price_1SMtJj4hYau76GhIakR22BKu", "quantity": 1 }
      ]
    }
  }'

Next steps