{
  "openapi": "3.0.3",
  "info": {
    "title": "Bruce Public API",
    "version": "1.0.0",
    "description": "Stablecoin checkout sessions and merchant webhooks for Bruce for Business. Authenticate with X-Api-Key: bk_live_… created in the Business hub."
  },
  "servers": [
    { "url": "https://api.bruce.money" }
  ],
  "security": [{ "ApiKeyAuth": [] }],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    },
    "schemas": {
      "FeeQuote": {
        "type": "object",
        "properties": {
          "source": { "type": "string", "enum": ["checkout", "invoice", "escrow", "p2p"] },
          "grossAmount": { "type": "string" },
          "feeAmount": { "type": "string" },
          "netAmount": { "type": "string" },
          "bps": { "type": "integer" },
          "currency": { "type": "string", "enum": ["USDC"] }
        }
      },
      "CheckoutSession": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "amount": { "type": "string" },
          "description": { "type": "string" },
          "status": { "type": "string" },
          "orderId": { "type": "string", "nullable": true },
          "shopDomain": { "type": "string", "nullable": true },
          "payUrl": { "type": "string", "format": "uri" },
          "fee": { "$ref": "#/components/schemas/FeeQuote" },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      }
    }
  },
  "paths": {
    "/api/v1/me": {
      "get": {
        "summary": "API key identity",
        "responses": {
          "200": { "description": "Org and scopes for the API key" }
        }
      }
    },
    "/api/v1/checkout-sessions": {
      "post": {
        "summary": "Create a checkout session",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "description"],
                "properties": {
                  "amount": { "type": "string", "example": "25.00" },
                  "description": { "type": "string" },
                  "redirectUrl": { "type": "string", "format": "uri" },
                  "webhookUrl": { "type": "string", "format": "uri" },
                  "orderId": { "type": "string" },
                  "shopDomain": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "checkoutSession": { "$ref": "#/components/schemas/CheckoutSession" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/checkout-sessions/{id}": {
      "get": {
        "summary": "Retrieve a checkout session",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Checkout session" },
          "404": { "description": "Not found" }
        }
      }
    },
    "/api/fees/quote": {
      "get": {
        "summary": "Quote platform fee (public)",
        "security": [],
        "parameters": [
          {
            "name": "source",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "enum": ["checkout", "invoice", "escrow", "p2p"] }
          },
          {
            "name": "amount",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "example": "100.00" }
          }
        ],
        "responses": {
          "200": { "description": "Fee quote" }
        }
      }
    }
  }
}
