Orders

Read and filter orders — the commercial record that groups the payment attempts behind every purchase, checkout, renewal, and setup flow.

An order is the commercial record of a single purchase intent. It is the durable, human-readable anchor that groups one or more payment attempts — the transactions Tokeflow orchestrates across your connected providers — under a stable identifier you can show on a receipt, reconcile against your ledger, or look up in support.

You never create an order directly. Tokeflow opens one automatically the moment a charge is initiated, then keeps its status in lockstep with the underlying transaction as it moves through your routing rules.

Tokeflow is payment orchestration, not a payment processor. An order records and standardizes the commercial event; the connected provider authorizes, captures, and settles the funds. Tokeflow never moves or settles money.

How orders are created

Every charge path produces exactly one order, distinguished by its order_type:

order_typeCreated whenTypical recurrence
apiYou call POST /transactions directly.none
checkoutA hosted or embedded Checkout session is paid.none or initial
renewalA subscription bills a new cycle.subsequent
trial_setupA trial subscription is provisioned and its first/setup charge runs.initial
card_setupA card is verified and tokenized without an immediate sale (a zero/auth-only verification).none

The order's status is derived from the transaction it groups. As the transaction is authorized, refunded, or charged back, Tokeflow advances the order status and appends an entry to its status history.

Today an order groups a single primary payment transaction. The data model is built to group multiple attempts (for example, a cascade fallback across providers) under one order, so always treat the order — not a single transaction — as the unit of reconciliation.

The order object

{
  "id": "ord_9f8e7d6c5b4a3210",
  "merchant_id": "mrc_8a1b2c3d4e5f",
  "organization_id": "org_1a2b3c4d5e6f",
  "customer_id": "cust_kj3x8rabc123",
  "external_order_id": "shop_order_456",
  "checkout_session_id": "cks_a1b2c3d4e5",
  "order_type": "checkout",
  "recurrence": "initial",
  "total_amount": 9900,
  "currency": "BRL",
  "status": "authorized",
  "metadata": {
    "cart_id": "cart_7788",
    "campaign": "winter_sale"
  },
  "created_at": "2026-01-15T12:30:00.000Z",
  "updated_at": "2026-01-15T12:30:04.000Z",
  "items": [
    {
      "id": "f3a1c2d4-1111-4a2b-9c3d-5e6f7a8b9c0d",
      "product_id": "prd_a1b2c3d4e5",
      "offer_id": "ofr_a1b2c3d4e5",
      "product_name": "Premium Plan",
      "offer_name": "Annual Discount",
      "billing_cycle": "yearly",
      "cycle_limit": 12,
      "is_first_charge": true,
      "quantity": 1,
      "unit_amount": 9900,
      "total_amount": 9900,
      "currency": "BRL",
      "installments": 1,
      "created_at": "2026-01-15T12:30:00.000Z"
    }
  ],
  "status_history": [
    {
      "from_status": null,
      "to_status": "pending",
      "triggered_by": "api",
      "created_at": "2026-01-15T12:30:00.000Z"
    },
    {
      "from_status": "pending",
      "to_status": "authorized",
      "triggered_by": "psp_webhook",
      "created_at": "2026-01-15T12:30:04.000Z"
    }
  ]
}

Fields

FieldTypeDescription
idstringUnique order identifier, prefixed ord_.
merchant_idstringMerchant that owns the order (mrc_).
organization_idstringOrganization the merchant belongs to (org_).
customer_idstringCustomer the order belongs to (cust_).
external_order_idstring | nullYour own order reference, echoed back for reconciliation. null when not supplied.
checkout_session_idstring | nullSource checkout session (cks_) for checkout / trial_setup orders; null otherwise.
order_typestringHow the order originated. One of api, checkout, renewal, trial_setup, card_setup.
recurrencestringPosition in a recurring series: none, initial, subsequent, or unscheduled.
total_amountintegerTotal in minor units (cents). 9900 = R$99.00.
currencystringISO 4217 currency code (e.g. BRL).
statusstringCurrent order status. See Order status.
metadataobject | nullArbitrary key/value data you attach at creation.
created_atstringISO 8601 UTC creation timestamp.
updated_atstringISO 8601 UTC last-update timestamp.
itemsarrayLine items snapshotted at order creation. Returned by the single-order endpoint; empty/omitted in list results.
status_historyarrayOrdered status transitions. Returned by the single-order endpoint.

List results (GET /orders) return order headers — the top-level fields above. The items and status_history arrays are populated only when you retrieve a single order by ID.

Order item fields

Each line item is an immutable snapshot of the product and offer at the time the order was created, so historical orders stay accurate even after you change your catalog.

FieldTypeDescription
idstringLine item identifier (UUID).
product_idstring | nullProduct reference (prd_).
offer_idstring | nullOffer reference (ofr_).
product_namestringSnapshot of the product name.
offer_namestring | nullSnapshot of the offer name.
billing_cyclestring | nullSnapshot of the offer billing cycle (e.g. monthly, yearly). null for one-time items.
cycle_limitinteger | nullSnapshot of the offer cycle limit, if any.
is_first_chargebooleantrue when first-charge / setup pricing was applied.
quantityintegerQuantity purchased.
unit_amountintegerUnit price in minor units (reflects first-charge pricing when is_first_charge is true).
total_amountintegerLine total in minor units (unit_amount × quantity).
currencystringISO 4217 currency code.
installmentsinteger | nullInstallments chosen at checkout. null or 1 means a single charge.
created_atstringISO 8601 UTC timestamp.

Status history fields

FieldTypeDescription
from_statusstring | nullStatus before the transition. null for the first entry.
to_statusstringStatus after the transition.
triggered_bystringWhat drove the change (e.g. api, system, psp_webhook).
created_atstringISO 8601 UTC timestamp of the transition.

Order status

StatusMeaning
pendingOrder created; the charge has not completed yet.
pre_authorizedAn authorization hold is in place, awaiting capture.
authorizedThe charge succeeded (authorized/captured).
failedThe charge did not succeed. Terminal.
canceledThe order was canceled before completion. Terminal.
refund_pendingA refund has been requested and is being processed.
partially_refundedPart of the amount has been refunded.
refundedThe full amount has been refunded.
charged_backA chargeback was recorded against the order.

Order status mirrors the underlying transaction's lifecycle. To inspect the payment-level detail behind a status — provider results, captures, voids — read the linked transaction and its refunds.

Endpoints

Base URL: https://api.tokeflow.com — all routes are under /api/v1.

Orders are read-only over the API. Authenticate with a server-side secret key (Authorization: Bearer sk_live_…). See Authentication for key anatomy and scopes. Both endpoints require the orders:read scope.

Secret keys (sk_*) are server-side only — never expose them in browser or mobile code.

GET/api/v1/orders

Auth: Organization key (with merchant_id) or Merchant key.

Returns a paginated list of order headers for the resolved merchant, newest data first. A Merchant key infers its merchant automatically. An Organization key spans every merchant in the org, so it must pass merchant_id to scope the query.

Query parameters

FieldTypeRequiredDescription
merchant_idstringConditionalRequired for Organization keys; omit for Merchant keys (inferred).
statusstringNoFilter by order status. Repeat the parameter or pass a comma-separated list for multiple values (e.g. status=authorized,refunded).
customer_idstringNoReturn only orders for this customer (cust_).
external_order_idstringNoMatch your own order reference.
order_typestringNoOne of api, checkout, renewal, trial_setup, card_setup.
currencystringNoISO 4217 currency code (e.g. BRL).
date_fromstringNoInclude orders created on or after this ISO 8601 timestamp.
date_tostringNoInclude orders created on or before this ISO 8601 timestamp.
pageintegerNoPage number, 1-indexed. Default 1.
limitintegerNoItems per page. Default 20, max 100.

Request

curl -G "https://api.tokeflow.com/api/v1/orders" \
  -H "Authorization: Bearer sk_live_mer_xxxxxxxxxxxxxxxx" \
  -H "Accept: application/json" \
  --data-urlencode "page=1" \
  --data-urlencode "limit=20" \
  --data-urlencode "status=authorized,refunded" \
  --data-urlencode "order_type=checkout" \
  --data-urlencode "currency=BRL" \
  --data-urlencode "date_from=2026-01-01T00:00:00Z" \
  --data-urlencode "date_to=2026-01-31T23:59:59Z"

With an Organization key, add merchant_id to the query string to scope the list to one merchant: GET /api/v1/orders?merchant_id=mrc_8a1b2c3d4e5f&status=authorized

Response 200 OK

{
  "success": true,
  "data": [
    {
      "id": "ord_9f8e7d6c5b4a3210",
      "merchant_id": "mrc_8a1b2c3d4e5f",
      "organization_id": "org_1a2b3c4d5e6f",
      "customer_id": "cust_kj3x8rabc123",
      "external_order_id": "shop_order_456",
      "checkout_session_id": "cks_a1b2c3d4e5",
      "order_type": "checkout",
      "recurrence": "initial",
      "total_amount": 9900,
      "currency": "BRL",
      "status": "authorized",
      "metadata": { "cart_id": "cart_7788" },
      "created_at": "2026-01-15T12:30:00.000Z",
      "updated_at": "2026-01-15T12:30:04.000Z"
    },
    {
      "id": "ord_1122334455667788",
      "merchant_id": "mrc_8a1b2c3d4e5f",
      "organization_id": "org_1a2b3c4d5e6f",
      "customer_id": "cust_kj3x8rabc123",
      "external_order_id": null,
      "checkout_session_id": null,
      "order_type": "api",
      "recurrence": "none",
      "total_amount": 15000,
      "currency": "BRL",
      "status": "refunded",
      "metadata": null,
      "created_at": "2026-01-12T09:05:00.000Z",
      "updated_at": "2026-01-13T17:42:00.000Z"
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "limit": 20,
      "total": 42,
      "total_pages": 3,
      "has_next": true,
      "has_prev": false
    }
  },
  "request_id": "req_8f3c2a1b9d7e",
  "timestamp": "2026-01-15T12:30:00.000Z"
}

GET/api/v1/orders/:id

Auth: Organization key (with merchant_id) or Merchant key.

Retrieves a single order with its items and status_history. The order is returned only if it belongs to the resolving merchant (and, for Organization keys, the specified merchant_id within your organization).

Path parameters

FieldTypeRequiredDescription
idstringYesThe order ID (ord_).

Query parameters

FieldTypeRequiredDescription
merchant_idstringConditionalRequired for Organization keys; omit for Merchant keys.

Request

curl "https://api.tokeflow.com/api/v1/orders/ord_9f8e7d6c5b4a3210" \
  -H "Authorization: Bearer sk_live_mer_xxxxxxxxxxxxxxxx" \
  -H "Accept: application/json"

Response 200 OK

{
  "success": true,
  "data": {
    "id": "ord_9f8e7d6c5b4a3210",
    "merchant_id": "mrc_8a1b2c3d4e5f",
    "organization_id": "org_1a2b3c4d5e6f",
    "customer_id": "cust_kj3x8rabc123",
    "external_order_id": "shop_order_456",
    "checkout_session_id": "cks_a1b2c3d4e5",
    "order_type": "checkout",
    "recurrence": "initial",
    "total_amount": 9900,
    "currency": "BRL",
    "status": "authorized",
    "metadata": { "cart_id": "cart_7788", "campaign": "winter_sale" },
    "created_at": "2026-01-15T12:30:00.000Z",
    "updated_at": "2026-01-15T12:30:04.000Z",
    "items": [
      {
        "id": "f3a1c2d4-1111-4a2b-9c3d-5e6f7a8b9c0d",
        "product_id": "prd_a1b2c3d4e5",
        "offer_id": "ofr_a1b2c3d4e5",
        "product_name": "Premium Plan",
        "offer_name": "Annual Discount",
        "billing_cycle": "yearly",
        "cycle_limit": 12,
        "is_first_charge": true,
        "quantity": 1,
        "unit_amount": 9900,
        "total_amount": 9900,
        "currency": "BRL",
        "installments": 1,
        "created_at": "2026-01-15T12:30:00.000Z"
      }
    ],
    "status_history": [
      {
        "from_status": null,
        "to_status": "pending",
        "triggered_by": "api",
        "created_at": "2026-01-15T12:30:00.000Z"
      },
      {
        "from_status": "pending",
        "to_status": "authorized",
        "triggered_by": "psp_webhook",
        "created_at": "2026-01-15T12:30:04.000Z"
      }
    ]
  },
  "request_id": "req_7b2d1e0c8f6a",
  "timestamp": "2026-01-15T12:30:05.000Z"
}

Response 404 Not Found

Returned when the order does not exist or does not belong to the resolved merchant.

{
  "error": {
    "type": "not_found_error",
    "code": "ORDER_NOT_FOUND",
    "message": "Order ord_9f8e7d6c5b4a3210 not found or does not belong to your merchant",
    "details": {},
    "request_id": "req_3c9a7f2b1d8e",
    "timestamp": "2026-01-15T12:31:00.000Z"
  }
}

Errors

Orders use the standard error envelope. Common cases:

HTTPtypeWhen
401authentication_errorMissing or invalid API key.
403authorization_errorKey lacks the orders:read scope, or an Organization key omitted merchant_id.
404not_found_errorOrder not found, or not owned by the resolved merchant.
429rate_limit_errorRate limit exceeded (default 100 requests / 60s per key). Back off and retry.
  • Transactions — the payment attempts an order groups, and where refunds live.
  • Checkout — sessions that create checkout orders.
  • Subscriptions — the source of renewal and trial_setup orders.
  • Authentication — key types, scopes, and the merchant_id rule for Organization keys.

On this page