{
  "openapi": "3.1.0",
  "info": {
    "title": "Arilator MoR API",
    "version": "2026-11-01",
    "summary": "Merchant-of-record primitives: pricing, checkout, settlement, tax and exports.",
    "description": "Money is authoritative in the ledger. Mutating calls require an Idempotency-Key and pin Arilator-Version.",
    "contact": { "name": "Arilator support", "email": "support@arilator.com", "url": "https://docs.arilator.com" }
  },
  "servers": [
    { "url": "https://api.arilator.com", "description": "Partner API (public)" },
    { "url": "https://indevapi.arilator.com", "description": "Partner API (sandbox)" }
  ],
  "tags": [
    { "name": "Pricing", "description": "Quotes and the published rate card." },
    { "name": "Checkout", "description": "Sessions, hosted checkout and order confirmation." },
    { "name": "Settlement", "description": "Reserves, appeals, exports and the merchant console." }
  ],
  "security": [{ "partnerSession": [] }],
  "components": {
    "securitySchemes": {
      "partnerSession": { "type": "http", "scheme": "bearer", "description": "Partner session token from POST /api/v1/partner-manager/sessions." },
      "developerKey": { "type": "http", "scheme": "bearer", "description": "Store-scoped key sk-ari-<test|live>-…" }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": { "type": "string", "maxLength": 255 },
        "description": "Same key and body replays the stored response; same key with a different body returns 409."
      },
      "ApiVersion": {
        "name": "Arilator-Version",
        "in": "header",
        "required": false,
        "schema": { "type": "string", "enum": ["2026-11-01"] }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["message"],
        "properties": {
          "message": { "type": "string" },
          "code": { "type": "string", "description": "Machine-readable code for policy refusals, e.g. COUNTRY_NOT_SUPPORTED." },
          "requestId": { "type": "string" }
        }
      },
      "Money": { "type": "string", "description": "Decimal string with up to four places; never compare as a float.", "example": "29.0000" },
      "Quote": {
        "type": "object",
        "properties": {
          "plan": { "type": "string", "enum": ["STANDARD", "VOLUME", "ENTERPRISE"] },
          "band": { "type": "string", "enum": ["STANDARD", "HIGH_TICKET"] },
          "variableBps": { "type": "integer", "example": 390 },
          "fixedFee": { "type": "number", "example": 0.4 },
          "baseFee": { "type": "number", "example": 1.53 },
          "surchargeBps": { "type": "integer", "example": 0 },
          "feeAmount": { "type": "number", "example": 1.53 },
          "netAmount": { "type": "number", "example": 27.47 },
          "effectiveBps": { "type": "integer", "example": 528 }
        }
      },
      "CheckoutSession": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "enum": ["OPEN", "COMPLETED", "EXPIRED", "FAILED"] },
          "currency": { "type": "string" },
          "amount": { "$ref": "#/components/schemas/Money" },
          "expires_at": { "type": "string", "format": "date-time" }
        }
      },
      "PublicCheckout": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "merchant": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": ["string", "null"] },
          "status": { "type": "string", "enum": ["OPEN", "COMPLETED", "EXPIRED", "FAILED"] },
          "currency": { "type": "string" },
          "subtotal": { "type": "number" },
          "tax": {
            "type": "object",
            "properties": {
              "amount": { "type": "number" },
              "rateBps": { "type": "integer" },
              "taxType": { "type": "string" },
              "reverseCharge": { "type": "boolean" },
              "label": { "type": "string" }
            }
          },
          "total": { "type": "number" },
          "expiresAt": { "type": "string", "format": "date-time" }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "subtotal": { "$ref": "#/components/schemas/Money" },
          "tax_amount": { "$ref": "#/components/schemas/Money" },
          "total_charged": { "$ref": "#/components/schemas/Money" },
          "commission_amount": { "$ref": "#/components/schemas/Money" },
          "merchant_net": { "$ref": "#/components/schemas/Money" },
          "currency": { "type": "string" },
          "status": { "type": "string", "enum": ["PENDING", "PAID", "FAILED", "REFUNDED", "DISPUTED"] }
        }
      },
      "ReservePosition": {
        "type": "object",
        "properties": {
          "available": { "$ref": "#/components/schemas/Money" },
          "held": { "type": "array", "items": { "type": "object", "properties": { "currency": { "type": "string" }, "amount": { "$ref": "#/components/schemas/Money" } } } },
          "heldByReason": { "type": "array", "items": { "type": "object", "properties": { "reason": { "type": "string" }, "currency": { "type": "string" }, "amount": { "$ref": "#/components/schemas/Money" } } } },
          "scheduledReleases": { "type": "array", "items": { "type": "object", "properties": { "currency": { "type": "string" }, "releaseOn": { "type": "string", "format": "date" }, "amount": { "$ref": "#/components/schemas/Money" } } } },
          "policy": {
            "type": "object",
            "properties": {
              "reserveBps": { "type": "integer", "example": 1000 },
              "capBps": { "type": "integer", "example": 5000 },
              "holdDays": { "type": "integer", "example": 14 },
              "payoutsFrozen": { "type": "boolean", "const": false }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": { "description": "Validation failure or a policy refusal.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unauthorized": { "description": "Missing or invalid credential.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "The resource does not exist.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "ServiceUnavailable": { "description": "A required provider is not configured.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  },
  "paths": {
    "/v1/pricing/sheet": {
      "get": {
        "tags": ["Pricing"],
        "operationId": "getPricingSheet",
        "summary": "Read the published rate card, floors, surcharges and excluded markets.",
        "responses": { "200": { "description": "The published book.", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    },
    "/v1/pricing/quote": {
      "post": {
        "tags": ["Pricing"],
        "operationId": "quoteSale",
        "summary": "Quote the fee, net and effective rate for one sale before charging.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "method", "country"],
                "properties": {
                  "amount": { "type": "number", "description": "Pre-tax order value." },
                  "method": { "type": "string", "enum": ["CARD", "BANK_DEBIT"] },
                  "country": { "type": "string", "description": "Buyer billing country, ISO 3166-1 alpha-2." },
                  "currency": { "type": "string", "default": "USD" },
                  "cross_border": { "type": "boolean", "description": "Adds 1.5% when no local acquirer exists." },
                  "currency_mismatch": { "type": "boolean", "description": "Adds 0.6% for currency conversion." }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The quote.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Quote" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/v1/checkout/sessions": {
      "post": {
        "tags": ["Checkout"],
        "operationId": "createCheckoutSession",
        "summary": "Resolve the acquirer chain and open a checkout session.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["merchant_id", "country_code", "currency", "selected_mechanism", "amount"],
                "properties": {
                  "merchant_id": { "type": "string", "format": "uuid" },
                  "customer_id": { "type": "string", "format": "uuid" },
                  "country_code": { "type": "string" },
                  "currency": { "type": "string" },
                  "selected_mechanism": { "type": "string", "enum": ["CARD", "ACH", "SEPA", "BACS", "UPI"] },
                  "amount": { "type": "number" },
                  "title": { "type": "string", "description": "Shown to the buyer." },
                  "description": { "type": "string" },
                  "customer_email": { "type": "string", "format": "email" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The session and the resolved routing chain.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": { "$ref": "#/components/schemas/CheckoutSession" },
                    "routing": { "type": "object", "properties": { "chain": { "type": "array", "items": { "type": "string", "format": "uuid" } }, "reason": { "type": "string" } } },
                    "expiresAt": { "type": "string", "format": "date-time" },
                    "checkoutLatencyBudgetMs": { "type": "integer", "example": 300 }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" }
        }
      }
    },
    "/v1/checkout/sessions/{id}": {
      "get": {
        "tags": ["Checkout"],
        "operationId": "getCheckoutSession",
        "summary": "Read a session, including its status and expiry.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The session.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CheckoutSession" } } } },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/checkout/sessions/{id}/public": {
      "get": {
        "tags": ["Checkout"],
        "operationId": "getPublicCheckout",
        "summary": "The buyer-safe projection the hosted page renders.",
        "security": [],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "Merchant, line, tax and total.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PublicCheckout" } } } },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/checkout/sessions/{id}/hosted": {
      "post": {
        "tags": ["Checkout"],
        "operationId": "startHostedCheckout",
        "summary": "Create a checkout on the acquirer's domain and return the redirect URL.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["return_url"],
                "properties": {
                  "email": { "type": "string", "format": "email" },
                  "return_url": { "type": "string", "format": "uri", "description": "Must be an approved checkout return host." }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Redirect the buyer to url.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "url": { "type": "string", "format": "uri" }, "provider": { "type": "string" }, "mode": { "type": "string", "enum": ["test", "live"] }, "total": { "type": "number" }, "currency": { "type": "string" } } } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/checkout/sessions/{id}/complete": {
      "post": {
        "tags": ["Checkout"],
        "operationId": "completeHostedCheckout",
        "summary": "Confirm with the acquirer and write the order and ledger on payment.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["hosted_session_id"], "properties": { "hosted_session_id": { "type": "string" } } } } }
        },
        "responses": {
          "201": {
            "description": "The confirmed status, and the order when paid.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "enum": ["PAID", "PENDING", "EXPIRED"] }, "order": { "oneOf": [{ "$ref": "#/components/schemas/Order" }, { "type": "null" }] }, "alreadyCompleted": { "type": "boolean" } } } } }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "503": { "$ref": "#/components/responses/ServiceUnavailable" }
        }
      }
    },
    "/v1/ledger/reserves/{merchantId}": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "getReservePosition",
        "summary": "Available balance, held lots by reason, and scheduled releases.",
        "parameters": [{ "name": "merchantId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The reserve position.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ReservePosition" } } } },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/merchants/{id}/appeals": {
      "post": {
        "tags": ["Settlement"],
        "operationId": "openAppeal",
        "summary": "Appeal a restriction. A person answers inside 48 hours.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }, { "$ref": "#/components/parameters/IdempotencyKey" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["subject_type", "reason"], "properties": { "subject_type": { "type": "string", "enum": ["COMPLIANCE_SCAN", "KYB", "MERCHANT_STATUS", "PAYOUT_HOLD"] }, "reason": { "type": "string" } } } } }
        },
        "responses": { "201": { "description": "The appeal, with its decision deadline." }, "400": { "$ref": "#/components/responses/BadRequest" } }
      }
    },
    "/v1/merchants/{id}/export": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "exportMerchant",
        "summary": "One signed JSON bundle of catalogue, customers, orders, ledgers and tax.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": { "200": { "description": "arilator.export/1, optionally signed with X-Arilator-Export-Signature." } }
      }
    },
    "/v1/portal/overview": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "portalOverview",
        "summary": "Console overview: status, settlement summary, reserve policy, open appeals.",
        "responses": { "200": { "description": "The merchant's overview." }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    },
    "/v1/portal/reserves": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "portalReserves",
        "summary": "Console reserve view.",
        "responses": { "200": { "description": "Reserve position plus notes." }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    },
    "/v1/portal/appeals": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "portalAppeals",
        "summary": "List appeals with status, deadline and decision.",
        "responses": { "200": { "description": "Appeals." }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      },
      "post": {
        "tags": ["Settlement"],
        "operationId": "portalOpenAppeal",
        "summary": "Open an appeal from the console.",
        "responses": { "201": { "description": "The appeal." }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    },
    "/v1/portal/export": {
      "get": {
        "tags": ["Settlement"],
        "operationId": "portalExport",
        "summary": "Download the signed export from the console.",
        "responses": { "200": { "description": "arilator.export/1." }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    }
  }
}
