{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/payments-ai/json-schema/payments-ai-public-api-order-response-schema.json",
  "title": "PublicApiOrderResponse",
  "description": "Order returned by API-key create and read. No mount fields and no processor purchase URL.",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/payments-ai-mor-openapi.json#/components/schemas/PublicApiOrderResponse",
  "type": "object",
  "required": [
    "orderId",
    "checkoutUrl",
    "currency",
    "amountDue",
    "recurringAmount",
    "billingPeriod",
    "periodLength",
    "trialPeriodDays",
    "items",
    "metadata",
    "status",
    "transactionId"
  ],
  "properties": {
    "orderId": {
      "type": "string"
    },
    "checkoutUrl": {
      "type": "string"
    },
    "currency": {
      "$ref": "#/$defs/SharedTypes.CurrencyCode"
    },
    "amountDue": {
      "allOf": [
        {
          "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
        }
      ],
      "description": "Amount the buyer owes today, before tax."
    },
    "recurringAmount": {
      "type": [
        "number",
        "null"
      ],
      "allOf": [
        {
          "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
        }
      ],
      "description": "Later renewal total. Null when the order has no recurring item."
    },
    "billingPeriod": {
      "allOf": [
        {
          "$ref": "#/$defs/BillingPeriod"
        }
      ],
      "nullable": true
    },
    "periodLength": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int32"
    },
    "trialPeriodDays": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int32"
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PublicApiOrderItemResponse"
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "The metadata sent on create, exactly as sent. `{}` when none was sent."
    },
    "status": {
      "$ref": "#/$defs/PublicApiOrderStatus"
    },
    "transactionId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Internal Payments AI transaction id when a payment row exists for this order (excluding pending or failed). Null while unpaid or between checkout confirm and webhook linkage."
    },
    "subscriptionId": {
      "type": "string",
      "description": "Present when the order has exactly one recurring line item and one subscription row is linked."
    },
    "subscriptionIds": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Present when the order has two or more recurring line items, or when multiple subscription rows are linked."
    }
  },
  "$defs": {
    "BillingPeriod": {
      "type": "string",
      "enum": [
        "day",
        "week",
        "month",
        "year"
      ]
    },
    "PublicApiOrderItemResponse": {
      "type": "object",
      "required": [
        "label",
        "unitPrice",
        "quantity",
        "lineTotal",
        "itemType"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "unitPrice": {
          "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
        },
        "quantity": {
          "type": "integer",
          "format": "int32",
          "minimum": 1
        },
        "lineTotal": {
          "$ref": "#/$defs/SharedTypes.MoneyAmountValue"
        },
        "itemType": {
          "$ref": "#/$defs/PublicApiOrderItemType"
        },
        "billingPeriod": {
          "$ref": "#/$defs/BillingPeriod"
        },
        "periodLength": {
          "type": "integer",
          "format": "int32",
          "minimum": 1
        }
      },
      "description": "One line returned after create or merchant read."
    },
    "PublicApiOrderItemType": {
      "type": "string",
      "enum": [
        "one_time",
        "recurring"
      ]
    },
    "PublicApiOrderStatus": {
      "type": "string",
      "enum": [
        "open",
        "completed",
        "expired"
      ],
      "description": "Payment lifecycle for a merchant order read. `open` includes unpaid and paid-awaiting-webhook (checkout confirmed, transaction row not yet linked)."
    },
    "SharedTypes.CurrencyCode": {
      "type": "string",
      "pattern": "^[a-z]{3}$",
      "description": "ISO 4217 currency code. Always lowercase (e.g. 'usd', 'eur')."
    },
    "SharedTypes.MoneyAmountValue": {
      "type": "number",
      "format": "decimal",
      "description": "Decimal money amount for financial values."
    }
  }
}