Skip to content
Merxian

Checkout sessions

A checkout session is a hosted page where one buyer pays one transaction. Times on checkout sessions are epoch milliseconds.

Read Checkout sessions for the model and the lifecycle. For a walkthrough, read Accept a payment with hosted checkout.

The checkout session object#

A hosted checkout page for one transaction. Times are epoch milliseconds.

Attributes

  • idstring
  • accountIdstring
  • modestring

    One of: payment

  • statusstring

    The state of the session. open accepts changes. payment_pending waits for the payment result. complete and cancelled are final. expired passed its expiry time.

    One of: open, payment_pending, complete, expired, cancelled

  • One of: unpaid, pending, paid, failed, cancelled

  • transactionIdstringCan be absent
  • transactionobjectCan be absent

    A summary of the transaction for display. The transaction holds the authoritative amounts.

    Child attributes of transaction
    • idstring
    • revisioninteger

      The transaction revision that this summary shows.

    • statestring

      The transaction state when this summary was made.

      One of: draft, ready, processing, completed, past_due, canceled

    • currencystring

      Pattern ^[A-Z]{3}$.

    • subtotalobject

      An amount in minor units with its currency.

      Child attributes of subtotal
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • discountobject

      An amount in minor units with its currency.

      Child attributes of discount
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • netobject

      An amount in minor units with its currency.

      Child attributes of net
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • taxobject

      An amount in minor units with its currency.

      Child attributes of tax
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • totalobject

      An amount in minor units with its currency.

      Child attributes of total
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • An amount in minor units with its currency.

      Child attributes of amountCollected
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • An amount in minor units with its currency.

      Child attributes of amountRemaining
      • The amount in the smallest unit of the currency, for example cents.

      • currencystring

        An ISO 4217 alphabetic currency code.

        Pattern ^[A-Z]{3}$.

    • linesarray of objects
      Child attributes of lines
      • idstring
      • namestring
      • descriptionstringCan be absent

        Absent when the product has no description.

      • quantityinteger
      • One of: inclusive, exclusive

      • An amount in minor units with its currency.

        Child attributes of unitAmount
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • subtotalobject

        An amount in minor units with its currency.

        Child attributes of subtotal
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • discountobject

        An amount in minor units with its currency.

        Child attributes of discount
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • netobject

        An amount in minor units with its currency.

        Child attributes of net
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • taxobject

        An amount in minor units with its currency.

        Child attributes of tax
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • totalobject

        An amount in minor units with its currency.

        Child attributes of total
        • The amount in the smallest unit of the currency, for example cents.

        • currencystring

          An ISO 4217 alphabetic currency code.

          Pattern ^[A-Z]{3}$.

      • productIdstringCan be absent
      • priceIdstringCan be absent
  • urlstring (URL)

    The hosted checkout page. Only the create response includes the access token in this URL.

  • expiresAtinteger
  • createdAtinteger
  • customerEmailstringCan be absent
  • customerNamestringCan be absent
  • customerCountrystringCan be absent
  • business once the buyer gives business details.

    One of: consumer, business

  • customerBusinessNamestringCan be absent
  • customerVatIdstringCan be absent
  • billingAddressobjectCan be absent
    Child attributes of billingAddress
  • brandingobjectCan be absent

    The branding of the hosted page, frozen when the session was created.

  • clientReferenceIdstringCan be absent
  • metadataobject

    Your own key-value pairs. At most 50 entries. A key has at most 64 characters, a value at most 512.

The response can include fields that this page does not list. Ignore fields that you do not know.

The checkout session object
{
  "id": "cs_6HvB2nQx9LmT4kWpR",
  "objectType": "checkout.session",
  "accountId": "acct_5Rn8bQ2xW7mK4tLzP",
  "mode": "payment",
  "status": "open",
  "paymentStatus": "unpaid",
  "url": "https://checkout.merxian.com/sandbox/s/cs_6HvB2nQx9LmT4kWpR",
  "transactionId": "txn_0F8mQ2rXbT4kL9pZa",
  "clientReferenceId": "A-1042",
  "customerType": "consumer",
  "customerEmail": "ada@example.com",
  "customerCountry": "DE",
  "metadata": {},
  "transaction": {
    "id": "txn_0F8mQ2rXbT4kL9pZa",
    "state": "draft",
    "revision": 1,
    "currency": "EUR",
    "subtotal": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "discount": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "net": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "tax": {
      "amountMinor": 2280,
      "currency": "EUR"
    },
    "total": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "amountCollected": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "amountRemaining": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "lines": [
      {
        "id": "txnitm_8QmZ3vK1pX6nT2bLw",
        "productId": "prod_5Tq8LmN2xB7vK4pRz",
        "priceId": "price_4Wm9TqLz2Xb7KdN8r",
        "name": "Team plan, annual",
        "quantity": 1,
        "taxBehavior": "exclusive",
        "unitAmount": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "subtotal": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "discount": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "net": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "tax": {
          "amountMinor": 2280,
          "currency": "EUR"
        },
        "total": {
          "amountMinor": 14280,
          "currency": "EUR"
        }
      }
    ]
  },
  "createdAt": 1789377667000,
  "expiresAt": 1789464067000
}

Create a checkout session#

POST/v1/checkout-sessions

Creates an open checkout session and returns the url of its hosted page. Send the buyer to that URL.

Give exactly one of these:

  • transactionId: a draft or ready transaction that you created.
  • transactionDraft: catalog prices and quantities. Merxian creates the transaction.

The url in this response carries the access token of the hosted page. Later reads return the URL without the token. Keep the URL from this response.

Requires the checkout:write scope.

Headers

  • Idempotency-KeystringRequired

    A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.

    At most 200 characters.

Request body

  • modestring

    One of: payment

    Default payment.

  • A draft or ready transaction of your account.

  • Catalog prices from which Merxian creates a new draft transaction.

    Child attributes of transactionDraft
    • currencystringRequired

      An ISO 4217 alphabetic currency code.

      Pattern ^[A-Z]{3}$.

    • lineItemsarray of objectsRequired

      One to 100 line items.

      At most 100 items.

      Child attributes of lineItems
      • priceIdstringRequired

        A catalog price of one of your products.

      • quantityinteger

        1 to 999. Default 1.

  • successUrlstring (URL)Required

    Where to send the buyer after payment. Must be https, except for a localhost URL in local development.

    At most 2048 characters.

  • cancelUrlstring (URL)Required

    Where to send the buyer after a cancelled or failed payment.

    At most 2048 characters.

  • customerEmailstring (email)

    Prefills the buyer email.

  • At most 256 characters.

  • A 2-letter ISO country code. Enables tax calculation at creation.

    Pattern ^[A-Za-z]{2}$.

  • Your own reference, returned with the session and its events.

    At most 200 characters.

  • Lets the buyer enter a promotion code on the hosted page.

    Default false.

  • Shows the billing address form. The page also shows it when the transaction has platform-issued invoices, because such an invoice needs the billing address.

    Default false.

  • Default false.

  • localestring

    The hosted checkout page is in English only.

  • metadataobject

    Your own key-value pairs. At most 50 entries. A key has at most 64 characters, a value at most 512.

  • expiresAtinteger

    When the session expires, in epoch milliseconds. Must be 30 minutes to 7 days from now. Defaults to 24 hours from now.

Returns

201The checkout session object.

Errors

StatusMeaning
400The request is not valid. See the error body for the field at fault.
401The API key is missing, malformed, revoked, or unknown.
403The API key does not hold the scope that this operation requires.
404The resource does not exist, or it belongs to another account.
409The request conflicts with the current state of the resource, or the idempotency key was used with a different request.
500An unexpected error occurred. Retry with the same idempotency key.
502Merxian could not complete the request. Retry with the same idempotency key.
503Merxian could not verify the API key. Retry later.

The error reference lists the codes in each error body.

Webhook events

This call can cause these events, later and in any order:

curl -X POST "https://api.merxian.com/v1/checkout-sessions" \
  -H "Authorization: Bearer $MERXIAN_API_KEY" \
  -H "Idempotency-Key: 9b3f6c1e-2a47-4d8b-b5e0-7c1d2e3f4a5b" \
  -H "Content-Type: application/json" \
  -d '{
    "transactionDraft": {
      "currency": "EUR",
      "lineItems": [
        {
          "priceId": "price_4Wm9TqLz2Xb7KdN8r",
          "quantity": 1
        }
      ]
    },
    "successUrl": "https://shop.example.com/checkout/success",
    "cancelUrl": "https://shop.example.com/checkout/cancel",
    "clientReferenceId": "A-1042",
    "customerEmail": "ada@example.com",
    "customerCountry": "DE"
  }'
Response · 201
{
  "id": "cs_6HvB2nQx9LmT4kWpR",
  "objectType": "checkout.session",
  "accountId": "acct_5Rn8bQ2xW7mK4tLzP",
  "mode": "payment",
  "status": "open",
  "paymentStatus": "unpaid",
  "url": "https://checkout.merxian.com/sandbox/s/cs_6HvB2nQx9LmT4kWpR?token=YOUR_SESSION_TOKEN",
  "transactionId": "txn_0F8mQ2rXbT4kL9pZa",
  "clientReferenceId": "A-1042",
  "customerType": "consumer",
  "customerEmail": "ada@example.com",
  "customerCountry": "DE",
  "metadata": {},
  "transaction": {
    "id": "txn_0F8mQ2rXbT4kL9pZa",
    "state": "draft",
    "revision": 1,
    "currency": "EUR",
    "subtotal": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "discount": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "net": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "tax": {
      "amountMinor": 2280,
      "currency": "EUR"
    },
    "total": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "amountCollected": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "amountRemaining": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "lines": [
      {
        "id": "txnitm_8QmZ3vK1pX6nT2bLw",
        "productId": "prod_5Tq8LmN2xB7vK4pRz",
        "priceId": "price_4Wm9TqLz2Xb7KdN8r",
        "name": "Team plan, annual",
        "quantity": 1,
        "taxBehavior": "exclusive",
        "unitAmount": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "subtotal": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "discount": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "net": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "tax": {
          "amountMinor": 2280,
          "currency": "EUR"
        },
        "total": {
          "amountMinor": 14280,
          "currency": "EUR"
        }
      }
    ]
  },
  "createdAt": 1789377667000,
  "expiresAt": 1789464067000
}

Retrieve a checkout session#

GET/v1/checkout-sessions/{sessionId}

Returns one checkout session with a summary of its transaction. A session after its expiry time reads as expired.

Requires the checkout:read scope.

Path parameters

  • sessionIdstringRequired

    The checkout session id.

Returns

200The checkout session object.

Errors

StatusMeaning
401The API key is missing, malformed, revoked, or unknown.
403The API key does not hold the scope that this operation requires.
404The resource does not exist, or it belongs to another account.
500An unexpected error occurred. Retry with the same idempotency key.
502Merxian could not complete the request. Retry with the same idempotency key.
503Merxian could not verify the API key. Retry later.

The error reference lists the codes in each error body.

curl "https://api.merxian.com/v1/checkout-sessions/cs_6HvB2nQx9LmT4kWpR" \
  -H "Authorization: Bearer $MERXIAN_API_KEY"
Response · 200
{
  "id": "cs_6HvB2nQx9LmT4kWpR",
  "objectType": "checkout.session",
  "accountId": "acct_5Rn8bQ2xW7mK4tLzP",
  "mode": "payment",
  "status": "open",
  "paymentStatus": "unpaid",
  "url": "https://checkout.merxian.com/sandbox/s/cs_6HvB2nQx9LmT4kWpR",
  "transactionId": "txn_0F8mQ2rXbT4kL9pZa",
  "clientReferenceId": "A-1042",
  "customerType": "consumer",
  "customerEmail": "ada@example.com",
  "customerCountry": "DE",
  "metadata": {},
  "transaction": {
    "id": "txn_0F8mQ2rXbT4kL9pZa",
    "state": "draft",
    "revision": 1,
    "currency": "EUR",
    "subtotal": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "discount": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "net": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "tax": {
      "amountMinor": 2280,
      "currency": "EUR"
    },
    "total": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "amountCollected": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "amountRemaining": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "lines": [
      {
        "id": "txnitm_8QmZ3vK1pX6nT2bLw",
        "productId": "prod_5Tq8LmN2xB7vK4pRz",
        "priceId": "price_4Wm9TqLz2Xb7KdN8r",
        "name": "Team plan, annual",
        "quantity": 1,
        "taxBehavior": "exclusive",
        "unitAmount": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "subtotal": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "discount": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "net": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "tax": {
          "amountMinor": 2280,
          "currency": "EUR"
        },
        "total": {
          "amountMinor": 14280,
          "currency": "EUR"
        }
      }
    ]
  },
  "createdAt": 1789377667000,
  "expiresAt": 1789464067000
}

List checkout sessions#

GET/v1/checkout-sessions

Returns one page of your checkout sessions, newest first.

Requires the checkout:read scope.

Query parameters

  • limitinteger

    How many sessions to return. A value outside 1-100 fails with 400.

    1 to 100. Default 20.

  • cursorstring

    An opaque cursor taken from a previous response's pagination.nextCursor.

  • statusstring

    Keep only sessions in this status.

    One of: open, payment_pending, complete, expired, cancelled

Returns

200A page of checkout session objects, in data, with pagination.

Errors

StatusMeaning
400The request is not valid. See the error body for the field at fault.
401The API key is missing, malformed, revoked, or unknown.
403The API key does not hold the scope that this operation requires.
500An unexpected error occurred. Retry with the same idempotency key.
502Merxian could not complete the request. Retry with the same idempotency key.
503Merxian could not verify the API key. Retry later.

The error reference lists the codes in each error body.

curl "https://api.merxian.com/v1/checkout-sessions?status=complete&limit=20" \
  -H "Authorization: Bearer $MERXIAN_API_KEY"
Response · 200
{
  "data": [
    {
      "id": "cs_6HvB2nQx9LmT4kWpR",
      "objectType": "checkout.session",
      "accountId": "acct_5Rn8bQ2xW7mK4tLzP",
      "mode": "payment",
      "status": "complete",
      "paymentStatus": "paid",
      "url": "https://checkout.merxian.com/sandbox/s/cs_6HvB2nQx9LmT4kWpR",
      "transactionId": "txn_0F8mQ2rXbT4kL9pZa",
      "clientReferenceId": "A-1042",
      "customerType": "consumer",
      "customerEmail": "ada@example.com",
      "customerCountry": "DE",
      "metadata": {},
      "transaction": {
        "id": "txn_0F8mQ2rXbT4kL9pZa",
        "state": "draft",
        "revision": 1,
        "currency": "EUR",
        "subtotal": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "discount": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "net": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "tax": {
          "amountMinor": 2280,
          "currency": "EUR"
        },
        "total": {
          "amountMinor": 14280,
          "currency": "EUR"
        },
        "amountCollected": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "amountRemaining": {
          "amountMinor": 14280,
          "currency": "EUR"
        },
        "lines": [
          {
            "id": "txnitm_8QmZ3vK1pX6nT2bLw",
            "productId": "prod_5Tq8LmN2xB7vK4pRz",
            "priceId": "price_4Wm9TqLz2Xb7KdN8r",
            "name": "Team plan, annual",
            "quantity": 1,
            "taxBehavior": "exclusive",
            "unitAmount": {
              "amountMinor": 12000,
              "currency": "EUR"
            },
            "subtotal": {
              "amountMinor": 12000,
              "currency": "EUR"
            },
            "discount": {
              "amountMinor": 0,
              "currency": "EUR"
            },
            "net": {
              "amountMinor": 12000,
              "currency": "EUR"
            },
            "tax": {
              "amountMinor": 2280,
              "currency": "EUR"
            },
            "total": {
              "amountMinor": 14280,
              "currency": "EUR"
            }
          }
        ]
      },
      "createdAt": 1789377667000,
      "expiresAt": 1789464067000
    }
  ],
  "pagination": {
    "nextCursor": "eyJpZCI6InR4bl8wRjhtUTJyWGJUNGtMOXBaYSJ9"
  }
}

Expire a checkout session#

POST/v1/checkout-sessions/{sessionId}/expire

Closes an open or payment_pending session and cancels a payment that the session started. After this, the buyer cannot pay on the hosted page.

An expired session returns the same session again. A complete or cancelled session returns 409.

Requires the checkout:write scope.

Path parameters

  • sessionIdstringRequired

    The checkout session id.

Headers

  • Idempotency-KeystringRequired

    A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.

    At most 200 characters.

Returns

200The checkout session object.

Errors

StatusMeaning
400The request is not valid. See the error body for the field at fault.
401The API key is missing, malformed, revoked, or unknown.
403The API key does not hold the scope that this operation requires.
404The resource does not exist, or it belongs to another account.
409The request conflicts with the current state of the resource, or the idempotency key was used with a different request.
500An unexpected error occurred. Retry with the same idempotency key.
502Merxian could not complete the request. Retry with the same idempotency key.
503Merxian could not verify the API key. Retry later.

The error reference lists the codes in each error body.

Webhook events

This call can cause these events, later and in any order:

curl -X POST "https://api.merxian.com/v1/checkout-sessions/cs_6HvB2nQx9LmT4kWpR/expire" \
  -H "Authorization: Bearer $MERXIAN_API_KEY" \
  -H "Idempotency-Key: 9b3f6c1e-2a47-4d8b-b5e0-7c1d2e3f4a5b"
Response · 200
{
  "id": "cs_6HvB2nQx9LmT4kWpR",
  "objectType": "checkout.session",
  "accountId": "acct_5Rn8bQ2xW7mK4tLzP",
  "mode": "payment",
  "status": "expired",
  "paymentStatus": "unpaid",
  "url": "https://checkout.merxian.com/sandbox/s/cs_6HvB2nQx9LmT4kWpR",
  "transactionId": "txn_0F8mQ2rXbT4kL9pZa",
  "clientReferenceId": "A-1042",
  "customerType": "consumer",
  "customerEmail": "ada@example.com",
  "customerCountry": "DE",
  "metadata": {},
  "transaction": {
    "id": "txn_0F8mQ2rXbT4kL9pZa",
    "state": "draft",
    "revision": 1,
    "currency": "EUR",
    "subtotal": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "discount": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "net": {
      "amountMinor": 12000,
      "currency": "EUR"
    },
    "tax": {
      "amountMinor": 2280,
      "currency": "EUR"
    },
    "total": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "amountCollected": {
      "amountMinor": 0,
      "currency": "EUR"
    },
    "amountRemaining": {
      "amountMinor": 14280,
      "currency": "EUR"
    },
    "lines": [
      {
        "id": "txnitm_8QmZ3vK1pX6nT2bLw",
        "productId": "prod_5Tq8LmN2xB7vK4pRz",
        "priceId": "price_4Wm9TqLz2Xb7KdN8r",
        "name": "Team plan, annual",
        "quantity": 1,
        "taxBehavior": "exclusive",
        "unitAmount": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "subtotal": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "discount": {
          "amountMinor": 0,
          "currency": "EUR"
        },
        "net": {
          "amountMinor": 12000,
          "currency": "EUR"
        },
        "tax": {
          "amountMinor": 2280,
          "currency": "EUR"
        },
        "total": {
          "amountMinor": 14280,
          "currency": "EUR"
        }
      }
    ]
  },
  "createdAt": 1789377667000,
  "expiresAt": 1789464067000
}

Try refund, payment.succeeded,POST /v1/transactions, orIdempotency-Key.