{
  "openapi": "3.0.3",
  "info": {
    "title": "Justlink Merchant API",
    "version": "1.0.0",
    "description": "Non-custodial Merchant API. Keys are bound to one creator wallet. createSession / cancelSession stay wallet transactions. Payment limits apply on prepare."
  },
  "servers": [{ "url": "/", "description": "Same origin as the Justlink app" }],
  "components": {
    "securitySchemes": {
      "BearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "jl_live_… (mainnet) or jl_test_… (testnet)"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "rate_limited",
                  "validation_error",
                  "limit_exceeded",
                  "conflict"
                ]
              },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/me": {
      "get": {
        "summary": "Current API key identity",
        "security": [{ "BearerApiKey": [] }],
        "responses": { "200": { "description": "creator, scopes, network" } }
      }
    },
    "/api/v1/sessions/prepare": {
      "post": {
        "summary": "Validate amount/splits and reserve daily payment-limit capacity",
        "security": [{ "BearerApiKey": [] }],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount"],
                "properties": {
                  "amount": { "type": "string", "description": "USDC decimal string" },
                  "recipients": { "type": "array", "items": { "type": "string" } },
                  "bps": { "type": "array", "items": { "type": "integer" } },
                  "expiry": { "description": "Unix seconds; 0 = never" },
                  "reserveId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "reserveId + createSessionArgs + chainId + router" },
          "400": { "description": "validation_error or limit_exceeded" }
        }
      }
    },
    "/api/v1/sessions": {
      "get": {
        "summary": "List session ids for the key wallet",
        "security": [{ "BearerApiKey": [] }],
        "responses": { "200": { "description": "sessionIds" } }
      },
      "post": {
        "summary": "Register meta after on-chain createSession",
        "security": [{ "BearerApiKey": [] }],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["sessionId", "title"],
                "properties": {
                  "sessionId": { "type": "string" },
                  "title": { "type": "string" },
                  "memo": { "type": "string" },
                  "webhookUrl": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Registered meta + payUrl" } }
      }
    },
    "/api/v1/sessions/{id}": {
      "get": {
        "summary": "Session meta + on-chain status",
        "security": [{ "BearerApiKey": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Session view" }, "404": { "description": "Not found" } }
      },
      "patch": {
        "summary": "Update title / memo / webhookUrl",
        "security": [{ "BearerApiKey": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Updated meta" } }
      }
    },
    "/api/v1/webhooks/deliveries": {
      "get": {
        "summary": "Recent webhook deliveries for the key wallet",
        "security": [{ "BearerApiKey": [] }],
        "responses": { "200": { "description": "deliveries" } }
      }
    },
    "/api/v1/sessions/{id}/webhooks/retry": {
      "post": {
        "summary": "Retry failed webhooks for an owned session",
        "security": [{ "BearerApiKey": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "requeued / delivered counts" } }
      }
    },
    "/api/v1/keys": {
      "post": {
        "summary": "List keys (wallet-signed; not Bearer)",
        "description": "Body: creator, issued, signature (EIP-191)",
        "responses": { "200": { "description": "keys without secrets" } }
      }
    },
    "/api/v1/keys/mint": {
      "post": {
        "summary": "Mint key (wallet-signed; secret returned once)",
        "responses": { "200": { "description": "secret shown once" } }
      }
    },
    "/api/v1/keys/revoke": {
      "post": {
        "summary": "Revoke key (wallet-signed)",
        "responses": { "200": { "description": "revokedAt" } }
      }
    }
  }
}
