{
  "openapi": "3.1.0",
  "info": {
    "title": "Benji Pays Partner API",
    "description": "The Benji Pays Partner API is a JSON over HTTPS API. All endpoints live under `/v2`. Errors follow [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) and are served as `application/problem+json`.\n\nThis overview describes the cross-cutting behavior shared by every partner endpoint. Endpoint-specific schemas live with each operation.\n\n## Authentication\n\nPartner endpoints authenticate with an Auth0 M2M access token in the `Authorization` header:\n\n```\nAuthorization: Bearer <jwt>\n```\n\nTokens are obtained from Auth0 with the OAuth 2.0 client-credentials grant against the `https://api.benjipays.com` audience. The token's actor claim (`distributor`, `partner`, or `organization`) and OAuth scopes determine which routes the caller can reach.\n\nFailures return `401 Unauthorized` (missing/expired/invalid credentials) or `403 Forbidden` (wrong actor type or missing scope).\n\n## Request and Correlation IDs\n\nTwo header pairs help with tracing:\n\n| Header | Direction | Purpose |\n| --- | --- | --- |\n| `X-Request-ID` | request (optional) / response (always) | Unique identifier for one request. Generated as a UUID v4 when the client omits it. |\n| `X-Correlation-ID` | request (optional) / response (always) | Identifier that flows across service boundaries for distributed tracing. Generated as a UUID v4 when omitted. |\n\nBoth IDs are echoed on success and included as `requestId` / `correlationId` extensions on `application/problem+json` error responses.\n\nThese headers are auto-injected on every operation in this spec — do not redeclare them per route.\n\n## Idempotency\n\nPOST, PATCH, and PUT endpoints accept an `Idempotency-Key` header to make retries safe.\n\n- Format: 1–255 characters, alphanumeric only (`[a-zA-Z0-9]+`).\n- Scope: keys are scoped per actor (no cross-tenant collisions).\n- Cache: the first response for a given key is cached for 24 hours.\n- Replay: a duplicate request with the same key and the same body returns the cached response with `X-Idempotency-Replayed: true` only after credentials were resolved by the global authenticate middleware (API key or Auth0 JWT signature check) before the idempotency cache lookup.\n- Conflict: same key with a different body returns `409 Conflict`.\n- In-flight: a second request with the same key while the first is still being processed returns `429 Too Many Requests` with `Retry-After` and problem `type` `https://api.benjipays.com/problems/idempotency-processing` (distinct from rate-limit `…/rate-limit-exceeded`).\n\n`Idempotency-Key` is auto-injected on every POST/PATCH/PUT operation in this spec — do not redeclare it per route. Routes that intentionally opt out set `x-bp-skip-idempotency: true`.\n\nThe middleware fails open: if the cache layer is unavailable the request proceeds without idempotency protection.\n\n## Pagination\n\nList endpoints use offset-based pagination with two query parameters:\n\n| Parameter | Type | Default | Bounds |\n| --- | --- | --- | --- |\n| `limit` | integer | `20` | `1`–`1000` |\n| `offset` | integer | `0` | `≥ 0` |\n\nSome endpoints use different bounds (for example usage/billing and autoprocessing forecast). Check the per-operation schema.\n\nResponses follow this envelope:\n\n```json\n{\n  \"data\": [ /* items */ ],\n  \"pagination\": {\n    \"limit\": 20,\n    \"offset\": 0,\n    \"hasMore\": true,\n    \"nextOffset\": 20,\n    \"prevOffset\": null\n  }\n}\n```\n\nMany list endpoints also include `pagination.total` (count of matching items across all pages). Per-operation response schemas are authoritative.\n\nUse `hasMore` to decide whether to fetch another page and `nextOffset` for the next request rather than computing it on the client.\n\n## Dates and Times\n\nAll **response** timestamps are ISO-8601 strings in UTC (for example `2024-01-01T12:00:00.000Z`).\n\nDate-range **query** parameters support two input modes where the endpoint accepts them:\n\n| Input format | Interpretation |\n| --- | --- |\n| `YYYY-MM-DD` (calendar day) | Full day in **UTC**. Start = `00:00:00.000Z`, end = `23:59:59.999Z` on that date. Same start and end day returns the full UTC day. |\n| ISO-8601 UTC timestamp (e.g. `2024-07-02T07:00:00.000Z`) | Exact UTC bounds — for precise or reconciliation queries. |\n\nSome endpoints accept only one mode or a different shape (for example invoice `invoiceDateStart` / `dueDateStart` are calendar-day fields compared as dates; usage/billing use month rules). Timestamp range filters such as transactions `startDate`/`endDate` and emails `sentStart`/`sentEnd` support both modes above; each bound is optional. Check each parameter's OpenAPI description.\n\n## Rate Limits\n\nRate limits are sliding-window and run before authentication. A well-formed `x-api-key` (format peek) or a JWT with a decodable actor claim uses the authenticated limit; otherwise the IP limit applies:\n\n| Caller | Limit |\n| --- | --- |\n| Authenticated actor (distributor / partner / organization), or peek of well-formed `x-api-key` / JWT actor claim | 5 requests / second |\n| Unauthenticated (per IP) | 1 request / second |\n\nExcluded paths: `/healthz`, `/readiness`, and `/docs/*`.\n\nEvery response carries the current usage:\n\n| Header | Meaning |\n| --- | --- |\n| `X-RateLimit-Limit` | Maximum requests allowed in the window. |\n| `X-RateLimit-Remaining` | Requests remaining in the current window. |\n| `X-RateLimit-Reset` | Unix timestamp (seconds) when the window resets. |\n\nOn `429 Too Many Requests` the response also includes `Retry-After` (seconds to wait before retrying) and an RFC 7807 problem body.\n\n## Errors\n\nAll non-2xx responses use `application/problem+json` and follow RFC 7807:\n\n```json\n{\n  \"type\": \"https://api.benjipays.com/problems/<slug>\",\n  \"title\": \"<short title>\",\n  \"status\": 401,\n  \"detail\": \"<human-readable explanation>\",\n  \"instance\": \"/v2/<path>\",\n  \"requestId\": \"…\",\n  \"correlationId\": \"…\"\n}\n```\n\nCommon statuses:\n\n| Status | When |\n| --- | --- |\n| `400 Bad Request` | Validation error (see `errors[]` extension when present). |\n| `401 Unauthorized` | Missing, invalid, or expired credentials. |\n| `403 Forbidden` | Wrong actor type, missing OAuth scope, or insufficient mapping permission. |\n| `404 Not Found` | Unknown route or tenant-scoped resource not visible to caller. |\n| `409 Conflict` | Idempotency-key body conflict, or domain conflict. |\n| `429 Too Many Requests` | Rate limit exceeded, or idempotency in-flight (with `Retry-After`). |\n| `500 Internal Server Error` | Unexpected failure. Safe to retry idempotent requests. |\n\n`requestId` and `correlationId` are included in the body whenever the middleware has set them, so a single value identifies the failure across logs and support tickets.\n",
    "version": "2.0.0",
    "contact": {
      "name": "Benji Pays API Support",
      "email": "benji@benjipays.com"
    }
  },
  "servers": [
    {
      "url": "https://api-v2.benjipays.com",
      "description": "Development server"
    }
  ],
  "tags": [
    {
      "name": "Whoami",
      "description": "Authentication verification and testing endpoints"
    },
    {
      "name": "Plans",
      "description": "Billing plan management for distributors"
    },
    {
      "name": "Partners",
      "description": "Partner account management (MSPs, accountants, ISOs)"
    },
    {
      "name": "Organizations",
      "description": "Organization (end-customer) management under partners"
    },
    {
      "name": "Usage",
      "description": "Usage and consumption reporting for billing (real-time calculation)"
    },
    {
      "name": "Billing",
      "description": "Finalized billing data for invoicing (locked/completed months only)"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "x-speakeasy-retries": {
    "strategy": "backoff",
    "backoff": {
      "initialInterval": 500,
      "maxInterval": 60000,
      "maxElapsedTime": 3600000,
      "exponent": 1.5
    },
    "statusCodes": [
      "5XX"
    ],
    "retryConnectionErrors": true
  },
  "paths": {
    "/v2/whoami": {
      "get": {
        "summary": "Get current actor information",
        "description": "**Access:** Requires any authenticated actor (Auth0 JWT or organization API key)\n\nReturns authenticated actor details and permissions. Accepts either an Auth0 Bearer token or an organization-scoped `x-api-key`.",
        "tags": [
          "Whoami"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "includeDetails",
            "schema": {
              "description": "When \"true\", includes additional diagnostic information",
              "example": "false",
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "When \"true\", includes additional diagnostic information"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WhoamiResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication credentials",
            "content": {
              "application/problem+json": {
                "schema": {
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/whoami"
                  },
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/whoami",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  },
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v2/whoami/echo": {
      "post": {
        "summary": "Echo request body",
        "description": "**Access:** Requires any authenticated actor (DISTRIBUTOR, PARTNER, or ORGANIZATION)\n\nValidates and echoes back the request body. Requires JWT authentication.",
        "tags": [
          "Whoami"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500,
                    "description": "Message to echo back",
                    "example": "Hello, API!"
                  },
                  "metadata": {
                    "description": "Optional metadata",
                    "type": "object",
                    "properties": {
                      "source": {
                        "description": "Source of the message",
                        "example": "test-client",
                        "type": "string",
                        "maxLength": 100
                      },
                      "timestamp": {
                        "description": "ISO 8601 timestamp",
                        "example": "2024-01-01T00:00:00.000Z",
                        "type": "string",
                        "format": "date-time",
                        "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                      }
                    }
                  }
                },
                "required": [
                  "message"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EchoResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Validation error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Bad request. Validation error",
                    "instance": "/v2/whoami"
                  },
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/whoami"
                  },
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/whoami",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  },
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          }
        ]
      }
    },
    "/v2/usage": {
      "get": {
        "summary": "Get usage snapshot for a month",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nReturns usage data for all Organizations under the authenticated distributor for a specified month. Used by distributors (e.g., Sherweb) to show consumption in marketplace dashboards.\n\n**Important Notes:**\n- Always calculates for entire month (MTD if current month, full month if past)\n- endDate is validated but effectively ignored for calculation\n- NFR plans are represented as $0 plans, no separate flag\n- Each organization may have 1+ items: base plan SKU + one row per overage tier (BENJI-{PLAN}-OVERAGE-TIER{n})\n\n**Calculation:**\n- Uses existing billing.js helpers (getPlanTypeFromUser)\n- Queries results collection for transaction counts\n- Uses user.billing.details for plan info (priceRanges)\n- Integrates with autopay.isCompanyInFreeTrial() for trial status\n\nRequires JWT authentication and 'partners:usage:read' scope.",
        "tags": [
          "Usage"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "startDate",
            "schema": {
              "type": "string",
              "description": "Start date - must be the 1st of the month (YYYY-MM-01)",
              "example": "2026-01-01"
            },
            "required": true,
            "description": "Start date - must be the 1st of the month (YYYY-MM-01)"
          },
          {
            "in": "query",
            "name": "endDate",
            "schema": {
              "type": "string",
              "description": "End date - must be in the same month as startDate (YYYY-MM-DD). Note: Effectively ignored for calculation - always calculates for entire month (MTD if current month, full month if past)",
              "example": "2026-01-31"
            },
            "required": true,
            "description": "End date - must be in the same month as startDate (YYYY-MM-DD). Note: Effectively ignored for calculation - always calculates for entire month (MTD if current month, full month if past)"
          },
          {
            "in": "query",
            "name": "partnerId",
            "schema": {
              "description": "Optional filter by specific partner (MongoDB ObjectId)",
              "example": "6022f98854f2c41d7ef2b1fe",
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "description": "Optional filter by specific partner (MongoDB ObjectId)"
          },
          {
            "in": "query",
            "name": "organizationId",
            "schema": {
              "description": "Optional filter by specific organization (MongoDB ObjectId)",
              "example": "7033a09965b3d52e8fc3c2af",
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "description": "Optional filter by specific organization (MongoDB ObjectId)"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "description": "Maximum number of results to return (default: 100, max: 500)",
              "example": 100,
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "description": "Maximum number of results to return (default: 100, max: 500)"
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "description": "Number of results to skip for pagination (default: 0)",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "description": "Number of results to skip for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with usage snapshot",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO",
                      "quantity": 1,
                      "trial": false,
                      "planName": "pro",
                      "period": "2026-01"
                    },
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO-OVERAGE-TIER1",
                      "quantity": 100,
                      "trial": false,
                      "period": "2026-01"
                    },
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO-OVERAGE-TIER2",
                      "quantity": 45,
                      "trial": false,
                      "period": "2026-01"
                    }
                  ],
                  "pagination": {
                    "nextOffset": null,
                    "prevOffset": null,
                    "limit": 100,
                    "offset": 0,
                    "hasMore": false
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid date format or dates not in same month",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "startDate must be the 1st of the month (YYYY-MM-01)"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/usage",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "startDate must be the 1st of the month (YYYY-MM-01)",
                    "instance": "/v2/usage"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "startDate must be the 1st of the month (YYYY-MM-01)"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/usage",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/usage"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "startDate must be the 1st of the month (YYYY-MM-01)"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/usage",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Access requires distributor actor type",
                    "instance": "/v2/usage"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "startDate must be the 1st of the month (YYYY-MM-01)"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/usage",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/usage",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/billing": {
      "get": {
        "summary": "Get finalized billing data for a month",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nReturns finalized billing data for a completed month. Used by distributors for invoicing and reconciliation. Data is locked and should match what was actually billed.\n\n**Key Differences from Usage API:**\n- Usage API: Real-time calculation for dashboard visibility (can query current month)\n- Billing API: Finalized/locked data for invoicing (only completed months)\n\n**Availability:**\n- Period must be a completed month (not current or future month)\n- Data available after billing runs on 1st of month (~2-3am)\n- Returns 404 if billing not yet run for period\n\n**Implementation:**\n- Queries billingInvoices collection by apiParent.distributorExternalId and period\n- Optional filters: partnerId (apiParent.partnerId), organizationId (userId)\n- Offset-based pagination (limit, offset)\n- Returns finalized pricing (unitPrice, total) with apiParent (type, distributorExternalId, partnerExternalId, partnerId)\n\n**Note:** NFR plans are represented as $0 plans (unitPrice: 0), no separate flag.\n\nRequires JWT authentication and 'partners:billing:read' scope.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "period",
            "schema": {
              "type": "string",
              "description": "Month in YYYY-MM format (must be a completed month)",
              "example": "2026-01"
            },
            "required": true,
            "description": "Month in YYYY-MM format (must be a completed month)"
          },
          {
            "in": "query",
            "name": "partnerId",
            "schema": {
              "description": "Optional filter by partner ID",
              "example": "6022f98854f2c41d7ef2b1fe",
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "description": "Optional filter by partner ID"
          },
          {
            "in": "query",
            "name": "organizationId",
            "schema": {
              "description": "Optional filter by organization ID",
              "example": "7033a09965b3d52e8fc3c2af",
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "description": "Optional filter by organization ID"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "description": "Number of organizations per page (default: 50, max: 100). Each org produces 1 base plan row plus one row per overage tier.",
              "example": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "description": "Number of organizations per page (default: 50, max: 100). Each org produces 1 base plan row plus one row per overage tier."
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "description": "Number of organizations to skip for pagination (default: 0)",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "description": "Number of organizations to skip for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with finalized billing data",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO",
                      "quantity": 1,
                      "unitPrice": 119,
                      "total": 119,
                      "trial": false,
                      "planName": "pro",
                      "period": "2026-01"
                    },
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO-OVERAGE-TIER1",
                      "quantity": 100,
                      "unitPrice": 0.8,
                      "total": 80,
                      "trial": false,
                      "period": "2026-01"
                    },
                    {
                      "organizationId": "7033a09965b3d52e8fc3c2af",
                      "apiParent": {
                        "type": "partner",
                        "distributorExternalId": "sherweb",
                        "partnerExternalId": "acme-msp",
                        "partnerId": "6022f98854f2c41d7ef2b1fe"
                      },
                      "name": "Acme Corp",
                      "externalId": "ext_org_67890",
                      "sku": "BENJI-PRO-OVERAGE-TIER2",
                      "quantity": 45,
                      "unitPrice": 0.6,
                      "total": 27,
                      "trial": false,
                      "period": "2026-01"
                    }
                  ],
                  "pagination": {
                    "nextOffset": null,
                    "prevOffset": null,
                    "limit": 50,
                    "offset": 0,
                    "hasMore": false
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/BillingResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid period format or period is not completed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Billing data not yet available for period 2026-01"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/billing",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Period must be a completed month (not current or future month)",
                    "instance": "/v2/billing"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Billing data not yet available for period 2026-01"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/billing",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/billing"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Billing data not yet available for period 2026-01"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/billing",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Access requires distributor tier",
                    "instance": "/v2/billing"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Billing data not yet available for this period",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Billing data not yet available for period 2026-01"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/billing",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Billing data not yet available for period 2026-01. Billing runs on the 1st of each month (~2-3am).",
                    "instance": "/v2/billing"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Billing data not yet available for period 2026-01"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/billing",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/billing",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/plans": {
      "get": {
        "summary": "List plans for authenticated distributor",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nReturns a paginated list of plans visible to the authenticated distributor. Plans can be filtered by status and partnerId (for custom-priced plans).\n\n**Visibility:**\n- Distributors see plans with their distributorExternalId\n- Can optionally filter by partnerId for partner-specific custom pricing\n\nRequires JWT authentication and 'partners:plans:read' scope.",
        "tags": [
          "Plans"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "partnerId",
            "schema": {
              "description": "Optional filter for Partner-specific custom-priced plans",
              "example": "507f1f77bcf86cd799439012",
              "type": "string",
              "maxLength": 255
            },
            "description": "Optional filter for Partner-specific custom-priced plans"
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "description": "Optional filter by plan status",
              "example": "active",
              "type": "string",
              "enum": [
                "active",
                "deprecated"
              ]
            },
            "description": "Optional filter by plan status"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "description": "Number of results per page (default: 20, max: 100)",
              "example": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "description": "Number of results per page (default: 20, max: 100)"
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "description": "Number of results to skip for pagination (default: 0)",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "description": "Number of results to skip for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with paginated list of plans",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439011",
                      "distributorExternalId": "sherweb",
                      "name": "pro",
                      "basePrice": 29.99,
                      "baseAnnualPrice": 299.99,
                      "priceRanges": [
                        {
                          "from": 0,
                          "to": 100,
                          "rate": 0.25
                        },
                        {
                          "from": 101,
                          "to": 500,
                          "rate": 0.2
                        }
                      ],
                      "includedTransactions": 100,
                      "additionalInvoicePrice": 0.25,
                      "description": "Professional plan",
                      "planType": "pro",
                      "status": "active"
                    }
                  ],
                  "pagination": {
                    "hasMore": false,
                    "nextOffset": null,
                    "prevOffset": null,
                    "limit": 20,
                    "offset": 0
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ListPlansResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/plans"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Access requires distributor tier",
                    "instance": "/v2/plans"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/plans",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/plans/{planId}": {
      "get": {
        "summary": "Get a single plan by ID",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nReturns details for a specific plan by its MongoDB ObjectId. The plan must be visible to the authenticated distributor.\n\n**Visibility:**\n- Returns 404 if plan doesn't exist or doesn't belong to the distributor (prevents enumeration)\n\nRequires JWT authentication and 'partners:plans:read' scope.",
        "tags": [
          "Plans"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "path",
            "name": "planId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the plan",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the plan"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with plan details",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439011",
                    "distributorExternalId": "sherweb",
                    "name": "pro",
                    "basePrice": 29.99,
                    "baseAnnualPrice": 299.99,
                    "priceRanges": [
                      {
                        "from": 0,
                        "to": 100,
                        "rate": 0.25
                      },
                      {
                        "from": 101,
                        "to": 500,
                        "rate": 0.2
                      }
                    ],
                    "includedTransactions": 100,
                    "additionalInvoicePrice": 0.25,
                    "description": "Professional plan",
                    "planType": "pro",
                    "status": "active"
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/GetPlanResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/plans"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Access requires distributor tier",
                    "instance": "/v2/plans"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Plan not found or not visible to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Plan not found or not visible to this distributor",
                    "instance": "/v2/plans/507f1f77bcf86cd799439011"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/not-found"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Not Found"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 404
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Plan not found or not visible to this distributor"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/plans/507f1f77bcf86cd799439011",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/plans",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/partners": {
      "post": {
        "summary": "Create a new Partner",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nCreates a Partner entity (MSP, accountant, ISO) under the authenticated distributor. The authenticated distributor's external ID becomes the distributorExternalId for the new Partner.\n\n**Important:**\n- externalId must be unique per distributor\n- Status is automatically set to 'active'\n- Returns 409 Conflict if externalId already exists\n\nRequires JWT authentication and 'partners:accounts:create' scope.",
        "tags": [
          "Partners"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "name": "Acme MSP",
                "externalId": "dist-partner-12345",
                "country": "CA",
                "contact": {
                  "email": "contact@partner.com",
                  "name": "John Smith"
                }
              },
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Company/partner name",
                    "example": "Acme MSP"
                  },
                  "externalId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$",
                    "description": "External ID from distributor's system (must be unique per distributor)",
                    "example": "dist-partner-12345"
                  },
                  "country": {
                    "description": "ISO 3166-1 alpha-2 country code (e.g., CA, US, GB)",
                    "example": "CA",
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2,
                    "pattern": "^[A-Za-z]{2}$"
                  },
                  "contact": {
                    "description": "Primary contact information",
                    "type": "object",
                    "properties": {
                      "email": {
                        "type": "string",
                        "maxLength": 255,
                        "format": "email",
                        "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
                        "description": "Contact email address",
                        "example": "contact@partner.com"
                      },
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "description": "Contact name",
                        "example": "John Smith"
                      }
                    },
                    "required": [
                      "email",
                      "name"
                    ]
                  }
                },
                "required": [
                  "name",
                  "externalId"
                ],
                "description": "Create partner request body"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Partner created successfully",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "6022f98854f2c41d7ef2b1fe",
                    "distributorExternalId": "dist-123",
                    "name": "Acme MSP",
                    "externalId": "dist-partner-12345",
                    "country": "CA",
                    "status": "active",
                    "createdAt": "2024-01-01T00:00:00.000Z",
                    "contact": {
                      "email": "contact@partner.com",
                      "name": "John Smith"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/CreatePartnerResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Validation error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: name is required",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Wrong actor type or missing scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:accounts:create",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - ExternalId already exists for this distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Partner with externalId 'dist-partner-12345' already exists for this distributor",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          }
        ]
      },
      "get": {
        "summary": "List all partners for authenticated distributor",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nLists all Partners (MSP, accountant, ISO) under the authenticated distributor with pagination and optional filtering.\n\n**Features:**\n- Sorted alphabetically by name\n- Filter by status or externalId\n- Includes organization count for each partner\n\nRequires JWT authentication and 'partners:accounts:read' scope.",
        "tags": [
          "Partners"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "description": "Optional filter by partner status",
              "example": "active",
              "type": "string",
              "enum": [
                "active",
                "inactive",
                "suspended",
                "closed"
              ]
            },
            "description": "Optional filter by partner status"
          },
          {
            "in": "query",
            "name": "externalId",
            "schema": {
              "description": "Optional filter by external ID (exact match)",
              "example": "dist-partner-12345",
              "type": "string",
              "maxLength": 100
            },
            "description": "Optional filter by external ID (exact match)"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "description": "Number of results per page (default: 20, max: 100)",
              "example": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "description": "Number of results per page (default: 20, max: 100)"
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "description": "Number of results to skip for pagination (default: 0)",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "description": "Number of results to skip for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with paginated list of partners",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "id": "6022f98854f2c41d7ef2b1fe",
                      "distributorExternalId": "dist-123",
                      "name": "Acme MSP",
                      "externalId": "dist-partner-12345",
                      "country": "CA",
                      "status": "active",
                      "createdAt": "2024-01-01T00:00:00.000Z",
                      "contact": {
                        "email": "contact@partner.com",
                        "name": "John Smith"
                      },
                      "organizationCount": 5
                    }
                  ],
                  "pagination": {
                    "hasMore": false,
                    "nextOffset": null,
                    "prevOffset": null,
                    "limit": 20,
                    "offset": 0
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ListPartnersResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Wrong actor type or missing scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:accounts:create",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/partners/{partnerId}": {
      "get": {
        "summary": "Get a specific partner by ID",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nRetrieves details for a specific Partner by its MongoDB ObjectId. Only returns partners that belong to the authenticated distributor (enforces isolation).\n\n**Note:** \n- To search by externalId, use GET /v2/partners?externalId=xyz instead\n- Returns 404 if partner doesn't exist or doesn't belong to this distributor (prevents enumeration)\n\nRequires JWT authentication and 'partners:accounts:read' scope.",
        "tags": [
          "Partners"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "path",
            "name": "partnerId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the partner",
              "example": "6022f98854f2c41d7ef2b1fe"
            },
            "required": true,
            "description": "MongoDB ObjectId of the partner"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with partner details",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "6022f98854f2c41d7ef2b1fe",
                    "distributorExternalId": "dist-123",
                    "name": "Acme MSP",
                    "externalId": "dist-partner-12345",
                    "country": "CA",
                    "status": "active",
                    "createdAt": "2024-01-01T00:00:00.000Z",
                    "contact": {
                      "email": "contact@partner.com",
                      "name": "John Smith"
                    },
                    "organizationCount": 5
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/GetPartnerResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid ObjectId format",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: name is required",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Wrong actor type or missing scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:accounts:create",
                    "instance": "/v2/partners"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Partner not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or not accessible",
                    "instance": "/v2/partners/6022f98854f2c41d7ef2b1fe"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/conflict"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Conflict"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 409
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Partner with externalId 'dist-partner-12345' already exists"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations": {
      "get": {
        "summary": "List Organizations",
        "description": "**Access:** Requires DISTRIBUTOR or PARTNER actor type.\n\nLists Organizations with optional filtering and pagination.\n\n- **Distributor:** Returns all organizations under the distributor. Use `partnerId` to filter by a specific partner, or `directOnly=true` to return only distributor-direct organizations.\n- **Partner:** Returns only the partner's own organizations. The `partnerId` and `directOnly` query params are ignored.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "query",
            "name": "partnerId",
            "schema": {
              "description": "Filter by partner MongoDB ObjectId. Distributor callers only — returns organizations under the specified partner. Ignored for partner callers (already scoped to their own partner).",
              "example": "507f1f77bcf86cd799439011",
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$"
            },
            "description": "Filter by partner MongoDB ObjectId. Distributor callers only — returns organizations under the specified partner. Ignored for partner callers (already scoped to their own partner)."
          },
          {
            "in": "query",
            "name": "directOnly",
            "schema": {
              "description": "When true, only return distributor-direct organizations (apiParent.type = distributor). Cannot be combined with partnerId.",
              "example": "false",
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "When true, only return distributor-direct organizations (apiParent.type = distributor). Cannot be combined with partnerId."
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "description": "Filter by organization status",
              "example": "active",
              "type": "string",
              "enum": [
                "pending_activation",
                "active",
                "suspended",
                "closed"
              ]
            },
            "description": "Filter by organization status"
          },
          {
            "in": "query",
            "name": "closed",
            "schema": {
              "description": "Filter by closed flag (true = only closed, false = only active)",
              "example": "false",
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "Filter by closed flag (true = only closed, false = only active)"
          },
          {
            "in": "query",
            "name": "externalId",
            "schema": {
              "description": "Filter by organization's external ID",
              "example": "dist-org-12345",
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "description": "Filter by organization's external ID"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "description": "Maximum number of results to return (default: 20, max: 100)",
              "example": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "description": "Maximum number of results to return (default: 20, max: 100)"
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "description": "Number of results to skip for pagination (default: 0)",
              "example": 0,
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "description": "Number of results to skip for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with paginated list of organizations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListOrganizationsResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Invalid actor type or partner accessing another partner's organizations",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Partner not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new Organization",
        "description": "**Access:** Requires DISTRIBUTOR or PARTNER actor type.\n\nCreates an Organization (Benji Pays company). Supports three flows:\n- **Distributor direct** (no `partnerId` in body) — org owned directly by distributor\n- **Partner direct** (caller is a partner) — org owned by the calling partner\n- **Distributor on behalf of partner** (`partnerId` in body) — org owned by the specified partner\n\nRequires JWT authentication and `partners:organizations:create` scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Organization/company name",
                    "example": "Acme Corporation"
                  },
                  "planId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$",
                    "description": "Plan ID (MongoDB ObjectId) for billing",
                    "example": "507f1f77bcf86cd799439011"
                  },
                  "externalId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$",
                    "description": "External ID from distributor's system (for reconciliation)",
                    "example": "dist-org-12345"
                  },
                  "partnerId": {
                    "description": "Partner MongoDB ObjectId — required when a distributor creates on behalf of a partner. Ignored when the caller is a partner.",
                    "example": "507f1f77bcf86cd799439012",
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$"
                  },
                  "admin": {
                    "type": "object",
                    "properties": {
                      "email": {
                        "type": "string",
                        "maxLength": 255,
                        "format": "email",
                        "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
                        "description": "Admin email address",
                        "example": "admin@acmecorp.com"
                      },
                      "firstName": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100,
                        "description": "Admin first name",
                        "example": "John"
                      },
                      "lastName": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100,
                        "description": "Admin last name",
                        "example": "Smith"
                      }
                    },
                    "required": [
                      "email",
                      "firstName",
                      "lastName"
                    ],
                    "description": "Admin contact information"
                  }
                },
                "required": [
                  "name",
                  "planId",
                  "externalId",
                  "admin"
                ],
                "description": "Request body for creating an organization"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Organization created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateOrganizationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Validation error or invalid plan",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: Invalid planId",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Wrong actor type or missing scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Partner not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - ExternalId already exists for this distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization with externalId 'dist-org-12345' already exists",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          }
        ]
      }
    },
    "/v2/organizations/{organizationId}": {
      "get": {
        "summary": "Get single Organization by ID",
        "description": "**Access:** Requires DISTRIBUTOR or PARTNER actor type\n\nGets details for a specific Organization.\n\n- **Distributor:** Can access any organization under their distributor.\n- **Partner:** Can only access organizations under their own partner account.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response with organization details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetOrganizationResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Invalid actor type",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organizationId}/suspend": {
      "post": {
        "summary": "Suspend an Organization",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nSuspends an Organization by disabling access and billing. Used when a Partner (MSP) is not paying their distributor bill.\n\nRequires JWT authentication and 'partners:organizations:suspend' scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "description": "Optional request body for suspend operation",
                "type": "object",
                "properties": {
                  "reason": {
                    "description": "Optional reason for suspension",
                    "example": "Non-payment",
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization suspended successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationStatusResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Organization is already suspended",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization with externalId 'dist-org-12345' already exists",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organizationId}/activate": {
      "post": {
        "summary": "Activate an Organization",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nRe-activates a suspended Organization by enabling access and billing.\n\nRequires JWT authentication and 'partners:organizations:activate' scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "responses": {
          "200": {
            "description": "Organization activated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrganizationStatusResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Organization is already active",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization with externalId 'dist-org-12345' already exists",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organizationId}/close": {
      "post": {
        "summary": "Close an Organization",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nCloses an Organization by disabling access, billing, and marking as closed. This is a permanent state change (unlike suspend which is temporary).\n\n**Updates:**\n- `enabled: false`\n- `billing.enabled: false`\n- `closed: true`\n- `lastUpdated: new Date()`\n\n**Activity Log:**\n- Creates activity log entry with reason\n\n**Note:** Cannot close an already closed organization (returns 409).\n\nRequires JWT authentication and 'partners:organizations:close' scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "reason": "Contract ended"
              },
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "Reason for closing the organization",
                    "example": "Contract ended"
                  }
                },
                "required": [
                  "reason"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization closed successfully",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "7033a09965b3d52e8fc3c2af",
                    "status": "closed",
                    "closed": true,
                    "lastUpdated": "2026-01-31T12:00:00.000Z"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Organization identifier (same value as path `organizationId`)",
                          "example": "7033a09965b3d52e8fc3c2af"
                        },
                        "status": {
                          "type": "string",
                          "description": "Organization status",
                          "example": "closed"
                        },
                        "closed": {
                          "type": "boolean",
                          "description": "Whether organization is closed",
                          "example": true
                        },
                        "lastUpdated": {
                          "type": "string",
                          "description": "ISO 8601 timestamp when organization was last updated",
                          "example": "2026-01-31T12:00:00.000Z"
                        }
                      },
                      "required": [
                        "id",
                        "status",
                        "closed",
                        "lastUpdated"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid request body",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: Invalid planId",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Organization is already closed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "status": {
                      "type": "number"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "instance": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization is already closed",
                    "instance": "/v2/organizations/7033a09965b3d52e8fc3c2af/close"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organizationId}/plan": {
      "patch": {
        "summary": "Change organization plan",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nChanges the billing plan assigned to an Organization. Used when an MSP upgrades or downgrades a customer's subscription.\n\n**Workflow:**\n1. Validates organization belongs to authenticated distributor\n2. Validates new plan is visible to distributor (in their plan catalog)\n3. Checks that new plan is different from current plan\n4. Updates `billing.planId` and `billing.details` on organization\n5. Creates activity log entry with previous and new plan details\n\n**Billing Implications:**\n- Plan change takes effect immediately\n- Current month billed at new plan rate (no proration for now)\n- Usage/overages calculated against new plan's included transactions\n\n**Validations:**\n- Cannot change to the same plan (returns 409)\n- New plan must belong to distributor's catalog (returns 404 if not)\n- Organization must belong to distributor (returns 404 if not)\n\nRequires JWT authentication and 'partners:organizations:change-plan' scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "planId": "6022f98854f2c41d7ef2b1fe"
              },
              "schema": {
                "type": "object",
                "properties": {
                  "planId": {
                    "type": "string",
                    "pattern": "^[0-9a-fA-F]{24}$",
                    "description": "MongoDB ObjectId of the new plan to assign",
                    "example": "6022f98854f2c41d7ef2b1fe"
                  }
                },
                "required": [
                  "planId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Plan changed successfully",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "7033a09965b3d52e8fc3c2af",
                    "previousPlanId": "5011e87743e1c30c6de1a0ed",
                    "previousPlanName": "basic",
                    "planId": "6022f98854f2c41d7ef2b1fe",
                    "planName": "pro",
                    "changedAt": "2026-01-15T12:00:00.000Z"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Organization identifier (same value as path `organizationId`)",
                          "example": "7033a09965b3d52e8fc3c2af"
                        },
                        "previousPlanId": {
                          "type": "string",
                          "description": "MongoDB ObjectId of the previous plan",
                          "example": "5011e87743e1c30c6de1a0ed"
                        },
                        "previousPlanName": {
                          "type": "string",
                          "description": "Name of the previous plan",
                          "example": "basic"
                        },
                        "planId": {
                          "type": "string",
                          "description": "MongoDB ObjectId of the new plan",
                          "example": "6022f98854f2c41d7ef2b1fe"
                        },
                        "planName": {
                          "type": "string",
                          "description": "Name of the new plan",
                          "example": "pro"
                        },
                        "changedAt": {
                          "type": "string",
                          "description": "ISO 8601 timestamp when plan was changed",
                          "example": "2026-01-15T12:00:00.000Z"
                        }
                      },
                      "required": [
                        "id",
                        "previousPlanId",
                        "previousPlanName",
                        "planId",
                        "planName",
                        "changedAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid planId format",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: Invalid planId",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization or plan not found, or plan not visible to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "status": {
                      "type": "number"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "instance": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "examples": {
                    "org-not-found": {
                      "summary": "Organization not found",
                      "value": {
                        "type": "https://api.benjipays.com/problems/not-found",
                        "title": "Not Found",
                        "status": 404,
                        "detail": "Organization not found or does not belong to distributor",
                        "instance": "/v2/organizations/7033a09965b3d52e8fc3c2af/plan"
                      }
                    },
                    "plan-not-found": {
                      "summary": "Plan not found",
                      "value": {
                        "type": "https://api.benjipays.com/problems/not-found",
                        "title": "Not Found",
                        "status": 404,
                        "detail": "Plan not found or not visible to distributor",
                        "instance": "/v2/organizations/7033a09965b3d52e8fc3c2af/plan"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Organization is already on this plan",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "status": {
                      "type": "number"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "instance": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization is already on this plan",
                    "instance": "/v2/organizations/7033a09965b3d52e8fc3c2af/plan"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organizationId}/resend-invite": {
      "post": {
        "summary": "Resend admin invite for an Organization",
        "description": "**Access:** Requires DISTRIBUTOR actor type\n\nResends the admin onboarding invite email for an Organization. Deletes any existing incomplete invites and creates a new one.\n\n**Workflow:**\n1. Deletes existing incomplete invite(s) from loginInvites collection\n2. Creates and sends new invite using existing inviteUser() flow\n3. Creates activity log entry\n\n**Email:**\n- If `email` provided in request body, uses that email\n- Otherwise, uses organization's existing admin email\n\n**Requirements:**\n- Organization must be in `pending_activation` status\n- Cannot resend invite to already activated organization (returns 409)\n- Organization must belong to authenticated distributor\n\nRequires JWT authentication and 'partners:organizations:resend-invite' scope.",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/RequestIdHeader"
          },
          {
            "$ref": "#/components/parameters/CorrelationIdHeader"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyHeader"
          },
          {
            "in": "path",
            "name": "organizationId",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{24}$",
              "description": "MongoDB ObjectId of the organization",
              "example": "507f1f77bcf86cd799439011"
            },
            "required": true,
            "description": "MongoDB ObjectId of the organization"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "description": "Optional new email address for the admin invite",
                    "example": "newemail@acmecorp.com",
                    "type": "string",
                    "format": "email",
                    "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                  }
                }
              },
              "examples": {
                "with-email": {
                  "summary": "With new email address",
                  "value": {
                    "email": "newemail@acmecorp.com"
                  }
                },
                "without-email": {
                  "summary": "Use existing email",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invite resent successfully",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "7033a09965b3d52e8fc3c2af",
                    "email": "admin@acmecorp.com",
                    "sentAt": "2026-01-15T12:00:00.000Z"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Organization identifier (same value as path `organizationId`)",
                          "example": "7033a09965b3d52e8fc3c2af"
                        },
                        "email": {
                          "type": "string",
                          "format": "email",
                          "pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
                          "description": "Email address where invite was sent",
                          "example": "admin@acmecorp.com"
                        },
                        "sentAt": {
                          "type": "string",
                          "description": "ISO 8601 timestamp when invite was sent",
                          "example": "2026-01-15T12:00:00.000Z"
                        }
                      },
                      "required": [
                        "id",
                        "email",
                        "sentAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid email format",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/bad-request",
                    "title": "Bad Request",
                    "status": 400,
                    "detail": "Validation error: Invalid planId",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/unauthorized",
                    "title": "Unauthorized",
                    "status": 401,
                    "detail": "Invalid or missing authentication token",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - Distributor actor type required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/forbidden",
                    "title": "Forbidden",
                    "status": 403,
                    "detail": "Missing required scope: partners:organizations:create",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not Found - Organization not found or does not belong to distributor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/not-found",
                    "title": "Not Found",
                    "status": 404,
                    "detail": "Partner not found or does not belong to your distributor",
                    "instance": "/v2/partners/partner-123/organizations"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Organization is already activated",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "status": {
                      "type": "number"
                    },
                    "detail": {
                      "type": "string"
                    },
                    "instance": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "example": {
                    "type": "https://api.benjipays.com/problems/conflict",
                    "title": "Conflict",
                    "status": 409,
                    "detail": "Organization is already activated and cannot receive a new invite",
                    "instance": "/v2/organizations/7033a09965b3d52e8fc3c2af/resend-invite"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests - Rate limit exceeded",
            "content": {
              "application/problem+json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "Problem type URI",
                      "example": "https://api.benjipays.com/problems/bad-request"
                    },
                    "title": {
                      "type": "string",
                      "description": "Error title",
                      "example": "Bad Request"
                    },
                    "status": {
                      "type": "number",
                      "description": "HTTP status code",
                      "example": 400
                    },
                    "detail": {
                      "type": "string",
                      "description": "Error detail message",
                      "example": "Validation error"
                    },
                    "instance": {
                      "description": "Instance URI",
                      "example": "/v2/partners/partner-123/organizations",
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "title",
                    "status",
                    "detail"
                  ],
                  "additionalProperties": false,
                  "description": "Error response (RFC 7807 Problem Details)",
                  "example": {
                    "type": "https://api.benjipays.com/problems/rate-limit-exceeded",
                    "title": "Too Many Requests",
                    "status": 429,
                    "detail": "Rate limit exceeded. Please retry after the specified time.",
                    "instance": "/v2/partners/partner-123/organizations",
                    "retryAfterSeconds": 1,
                    "limit": 5
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "RequestIdHeader": {
        "name": "X-Request-ID",
        "in": "header",
        "required": false,
        "description": "Optional client-supplied unique ID for one request. The server generates a UUID v4 if omitted and always echoes the value in the response.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "CorrelationIdHeader": {
        "name": "X-Correlation-ID",
        "in": "header",
        "required": false,
        "description": "Optional ID that flows across service boundaries for distributed tracing. The server generates a UUID v4 if omitted and always echoes the value in the response.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "IdempotencyKeyHeader": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Optional client-supplied key that makes retries safe for POST/PATCH/PUT. Scoped per actor; cached for 24 hours. Replays return the cached response with `X-Idempotency-Replayed: true`. Same key with a different body returns 409. In-flight duplicates return 429 with `Retry-After`. See the Idempotency section in the API overview.",
        "schema": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9]+$",
          "minLength": 1,
          "maxLength": 255
        },
        "example": "a1b2c3d4e5f6"
      }
    },
    "schemas": {
      "WhoamiResponse": {
        "type": "object",
        "properties": {
          "actor": {
            "$ref": "#/components/schemas/Actor"
          },
          "permissions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "List of permissions granted to the actor",
            "example": [
              "partners:accounts:read",
              "partners:subscriptions:read"
            ]
          },
          "message": {
            "type": "string",
            "description": "Response message",
            "example": "hello from api /v2/whoami"
          },
          "jsIntegrationDemo": {
            "type": "string",
            "description": "JavaScript integration demo value",
            "example": "demo-value"
          },
          "formattedAmount": {
            "type": "string",
            "description": "Formatted currency amount",
            "example": "$123.46"
          },
          "requestTimestamp": {
            "description": "Request timestamp (included when includeDetails=true)",
            "example": "2024-01-01T00:00:00.000Z",
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
          },
          "apiVersion": {
            "description": "API version (included when includeDetails=true)",
            "example": "v2",
            "type": "string"
          }
        },
        "required": [
          "actor",
          "permissions",
          "message",
          "jsIntegrationDemo",
          "formattedAmount"
        ],
        "additionalProperties": false,
        "description": "Whoami response"
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Problem type URI",
            "example": "https://api.benjipays.com/problems/unauthorized"
          },
          "title": {
            "type": "string",
            "description": "Error title",
            "example": "Unauthorized"
          },
          "status": {
            "type": "number",
            "description": "HTTP status code",
            "example": 401
          },
          "detail": {
            "type": "string",
            "description": "Error detail message",
            "example": "Invalid or missing authentication token"
          },
          "instance": {
            "description": "Instance URI",
            "example": "/v2/whoami",
            "type": "string"
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "additionalProperties": false,
        "description": "Error response (RFC 7807 Problem Details)"
      },
      "EchoResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Response message",
            "example": "Echo response"
          },
          "echo": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500,
                "description": "Message to echo back",
                "example": "Hello, API!"
              },
              "metadata": {
                "description": "Optional metadata",
                "type": "object",
                "properties": {
                  "source": {
                    "description": "Source of the message",
                    "example": "test-client",
                    "type": "string",
                    "maxLength": 100
                  },
                  "timestamp": {
                    "description": "ISO 8601 timestamp",
                    "example": "2024-01-01T00:00:00.000Z",
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "message"
            ],
            "additionalProperties": false,
            "description": "Echoed request body"
          },
          "receivedAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
            "description": "ISO 8601 timestamp when request was received",
            "example": "2024-01-01T00:00:00.000Z"
          }
        },
        "required": [
          "message",
          "echo",
          "receivedAt"
        ],
        "additionalProperties": false,
        "description": "Echo response"
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageItem"
            },
            "description": "Array of usage items grouped by organization + SKU"
          },
          "pagination": {
            "type": "object",
            "properties": {
              "nextOffset": {
                "description": "Offset for next page (null if no more results)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "prevOffset": {
                "description": "Offset for previous page (null if first page)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "limit": {
                "type": "number",
                "description": "Number of items per page",
                "example": 100
              },
              "offset": {
                "type": "number",
                "description": "Current offset",
                "example": 0
              },
              "hasMore": {
                "type": "boolean",
                "description": "Whether more results are available",
                "example": false
              }
            },
            "required": [
              "nextOffset",
              "prevOffset",
              "limit",
              "offset",
              "hasMore"
            ],
            "additionalProperties": false,
            "description": "Pagination metadata"
          }
        },
        "required": [
          "data",
          "pagination"
        ],
        "additionalProperties": false,
        "description": "Usage snapshot response"
      },
      "BillingResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingItem"
            },
            "description": "Array of billing items grouped by organization and SKU"
          },
          "pagination": {
            "type": "object",
            "properties": {
              "nextOffset": {
                "description": "Offset for next page (null if no more pages)",
                "example": 50,
                "type": [
                  "number",
                  "null"
                ]
              },
              "prevOffset": {
                "description": "Offset for previous page (null if first page)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "limit": {
                "type": "number",
                "description": "Number of items per page",
                "example": 50
              },
              "offset": {
                "type": "number",
                "description": "Current offset",
                "example": 0
              },
              "hasMore": {
                "type": "boolean",
                "description": "Whether more results are available",
                "example": false
              }
            },
            "required": [
              "nextOffset",
              "prevOffset",
              "limit",
              "offset",
              "hasMore"
            ],
            "additionalProperties": false,
            "description": "Offset-based pagination metadata"
          }
        },
        "required": [
          "data",
          "pagination"
        ],
        "additionalProperties": false,
        "description": "Billing response with finalized billing data"
      },
      "ListPlansResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Plan"
            },
            "description": "Array of plans"
          },
          "pagination": {
            "type": "object",
            "properties": {
              "hasMore": {
                "type": "boolean",
                "description": "Whether more results are available",
                "example": false
              },
              "nextOffset": {
                "description": "Offset for next page (null if no more pages)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "prevOffset": {
                "description": "Offset for previous page (null if first page)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "limit": {
                "type": "number",
                "description": "Maximum number of results per page",
                "example": 20
              },
              "offset": {
                "type": "number",
                "description": "Number of results skipped",
                "example": 0
              }
            },
            "required": [
              "hasMore",
              "nextOffset",
              "prevOffset",
              "limit",
              "offset"
            ],
            "additionalProperties": false,
            "description": "Pagination metadata"
          }
        },
        "required": [
          "data",
          "pagination"
        ],
        "additionalProperties": false,
        "description": "Paginated list of plans"
      },
      "GetPlanResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Plan"
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Single plan details"
      },
      "CreatePartnerResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "description": "Partner identifier (same value as path `partnerId`)",
                "example": "6022f98854f2c41d7ef2b1fe"
              },
              "distributorExternalId": {
                "type": "string",
                "description": "Parent distributor external ID",
                "example": "dist-123"
              },
              "name": {
                "type": "string",
                "description": "Company/partner name",
                "example": "Acme MSP"
              },
              "externalId": {
                "type": "string",
                "description": "External ID from distributor's system",
                "example": "dist-partner-12345"
              },
              "country": {
                "description": "ISO 3166-1 alpha-2 country code",
                "example": "CA",
                "type": "string"
              },
              "status": {
                "type": "string",
                "description": "Partner status",
                "example": "active"
              },
              "createdAt": {
                "type": "string",
                "description": "ISO 8601 timestamp when partner was created",
                "example": "2024-01-01T00:00:00.000Z"
              },
              "contact": {
                "description": "Primary contact information",
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "description": "Contact email address",
                    "example": "contact@partner.com"
                  },
                  "name": {
                    "type": "string",
                    "description": "Contact name",
                    "example": "John Smith"
                  }
                },
                "required": [
                  "email",
                  "name"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "id",
              "distributorExternalId",
              "name",
              "externalId",
              "status",
              "createdAt"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Create partner response"
      },
      "ListPartnersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Partner"
            },
            "description": "Array of partners"
          },
          "pagination": {
            "type": "object",
            "properties": {
              "hasMore": {
                "type": "boolean",
                "description": "Whether more results are available",
                "example": false
              },
              "nextOffset": {
                "description": "Offset for next page (null if no more pages)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "prevOffset": {
                "description": "Offset for previous page (null if first page)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "limit": {
                "type": "number",
                "description": "Maximum number of results per page",
                "example": 20
              },
              "offset": {
                "type": "number",
                "description": "Number of results skipped",
                "example": 0
              }
            },
            "required": [
              "hasMore",
              "nextOffset",
              "prevOffset",
              "limit",
              "offset"
            ],
            "additionalProperties": false,
            "description": "Pagination metadata"
          }
        },
        "required": [
          "data",
          "pagination"
        ],
        "additionalProperties": false,
        "description": "Paginated list of partners"
      },
      "GetPartnerResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Partner"
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Single partner response"
      },
      "ListOrganizationsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrganizationListItem"
            },
            "description": "Array of organizations"
          },
          "pagination": {
            "type": "object",
            "properties": {
              "hasMore": {
                "type": "boolean",
                "description": "Whether more results are available",
                "example": true
              },
              "nextOffset": {
                "description": "Offset for next page (null if no more pages)",
                "example": 20,
                "type": [
                  "number",
                  "null"
                ]
              },
              "prevOffset": {
                "description": "Offset for previous page (null if first page)",
                "example": null,
                "type": [
                  "number",
                  "null"
                ]
              },
              "limit": {
                "type": "number",
                "description": "Maximum number of results per page",
                "example": 20
              },
              "offset": {
                "type": "number",
                "description": "Number of results skipped",
                "example": 0
              }
            },
            "required": [
              "hasMore",
              "nextOffset",
              "prevOffset",
              "limit",
              "offset"
            ],
            "additionalProperties": false,
            "description": "Pagination metadata"
          }
        },
        "required": [
          "data",
          "pagination"
        ],
        "additionalProperties": false,
        "description": "Paginated list of organizations"
      },
      "CreateOrganizationResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/CreateOrganizationData"
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Create organization response"
      },
      "GetOrganizationResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Organization"
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Single organization response"
      },
      "OrganizationStatusResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "description": "Organization identifier (same value as path `organizationId`)",
                "example": "507f1f77bcf86cd799439011"
              },
              "status": {
                "type": "string",
                "enum": [
                  "active",
                  "suspended"
                ],
                "description": "Organization status after operation",
                "example": "suspended"
              },
              "lastUpdated": {
                "type": "string",
                "format": "date-time",
                "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
                "description": "ISO 8601 timestamp of last update",
                "example": "2026-01-27T12:00:00.000Z"
              }
            },
            "required": [
              "id",
              "status",
              "lastUpdated"
            ],
            "additionalProperties": false,
            "description": "Organization status response"
          }
        },
        "required": [
          "data"
        ],
        "additionalProperties": false,
        "description": "Suspend/Activate organization response"
      },
      "Actor": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "distributor",
              "partner",
              "internal",
              "organization"
            ],
            "description": "Type of actor",
            "example": "partner"
          },
          "actorId": {
            "description": "Actor identifier",
            "example": "bp-actor-123",
            "type": "string"
          }
        },
        "required": [
          "type"
        ],
        "additionalProperties": false,
        "description": "Actor information for the authenticated caller"
      },
      "UsageItem": {
        "type": "object",
        "properties": {
          "organizationId": {
            "type": "string",
            "description": "MongoDB ObjectId of the organization",
            "example": "7033a09965b3d52e8fc3c2af"
          },
          "apiParent": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "distributor",
                  "partner"
                ],
                "description": "Parent type — distributor or partner",
                "example": "partner"
              },
              "distributorExternalId": {
                "type": "string",
                "description": "Distributor external ID",
                "example": "sherweb-prod"
              },
              "partnerExternalId": {
                "description": "Partner external ID (present for partner-type orgs)",
                "example": "partner-ext-123",
                "type": "string"
              },
              "partnerId": {
                "description": "Partner MongoDB ObjectId (present for partner-type orgs)",
                "example": "6022f98854f2c41d7ef2b1fe",
                "type": "string"
              }
            },
            "required": [
              "type",
              "distributorExternalId"
            ],
            "additionalProperties": false,
            "description": "API parent — who created the organization"
          },
          "name": {
            "type": "string",
            "description": "Organization name",
            "example": "Acme Corp"
          },
          "externalId": {
            "type": "string",
            "description": "External ID from distributor's system",
            "example": "ext_org_67890"
          },
          "sku": {
            "type": "string",
            "description": "SKU identifier — plan SKU (e.g., BENJI-PRO) for base plan, or BENJI-{PLAN}-OVERAGE-TIER{n} (e.g., BENJI-PRO-OVERAGE-TIER1) for each overage tier",
            "example": "BENJI-PRO"
          },
          "quantity": {
            "type": "number",
            "description": "Quantity — 1 for base plan, per-tier overage count for BENJI-{PLAN}-OVERAGE-TIER{n} rows",
            "example": 1
          },
          "trial": {
            "type": "boolean",
            "description": "Whether organization is in trial period",
            "example": false
          },
          "planName": {
            "description": "Plan name (included for base plan SKU, omitted for overage)",
            "example": "pro",
            "type": "string"
          },
          "period": {
            "type": "string",
            "description": "Period in YYYY-MM format",
            "example": "2026-01"
          }
        },
        "required": [
          "organizationId",
          "apiParent",
          "name",
          "externalId",
          "sku",
          "quantity",
          "trial",
          "period"
        ],
        "additionalProperties": false,
        "description": "Usage item for an organization"
      },
      "BillingItem": {
        "type": "object",
        "properties": {
          "organizationId": {
            "type": "string",
            "description": "MongoDB ObjectId of the organization",
            "example": "7033a09965b3d52e8fc3c2af"
          },
          "apiParent": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "distributor",
                  "partner"
                ],
                "description": "Parent type — distributor or partner",
                "example": "partner"
              },
              "distributorExternalId": {
                "type": "string",
                "description": "Distributor external ID",
                "example": "sherweb"
              },
              "partnerExternalId": {
                "description": "Partner external ID (present when type is partner)",
                "example": "acme-msp",
                "type": "string"
              },
              "partnerId": {
                "description": "Partner MongoDB ObjectId (present when type is partner)",
                "example": "6022f98854f2c41d7ef2b1fe",
                "type": "string"
              }
            },
            "required": [
              "type",
              "distributorExternalId"
            ],
            "additionalProperties": false,
            "description": "API parent — distributor and optional partner"
          },
          "name": {
            "type": "string",
            "description": "Organization name",
            "example": "Acme Corp"
          },
          "externalId": {
            "description": "External ID from distributor's system",
            "example": "ext_org_67890",
            "type": "string"
          },
          "sku": {
            "type": "string",
            "description": "SKU identifier — plan SKU (e.g., BENJI-PRO) for base plan, or BENJI-{PLAN}-OVERAGE-TIER{n} (e.g., BENJI-PRO-OVERAGE-TIER1) for each overage tier",
            "example": "BENJI-PRO"
          },
          "quantity": {
            "type": "number",
            "description": "Quantity for this SKU",
            "example": 1
          },
          "unitPrice": {
            "type": "number",
            "description": "Price per unit",
            "example": 119
          },
          "total": {
            "type": "number",
            "description": "Total price (quantity × unitPrice)",
            "example": 119
          },
          "trial": {
            "type": "boolean",
            "description": "Whether organization is on trial",
            "example": false
          },
          "planName": {
            "description": "Plan name (e.g., pro, starter)",
            "example": "pro",
            "type": "string"
          },
          "period": {
            "type": "string",
            "description": "Billing period (YYYY-MM)",
            "example": "2026-01"
          }
        },
        "required": [
          "organizationId",
          "apiParent",
          "name",
          "sku",
          "quantity",
          "unitPrice",
          "total",
          "trial",
          "period"
        ],
        "additionalProperties": false,
        "description": "Billing line item for an organization + SKU combination"
      },
      "Plan": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Plan identifier (same value as path `planId`)",
            "example": "507f1f77bcf86cd799439011"
          },
          "distributorExternalId": {
            "description": "Distributor external ID this plan is visible to",
            "example": "sherweb",
            "type": "string"
          },
          "partnerId": {
            "description": "Partner ID for partner-specific custom pricing",
            "example": "507f1f77bcf86cd799439012",
            "type": "string"
          },
          "name": {
            "type": "string",
            "description": "Plan name",
            "example": "pro"
          },
          "basePrice": {
            "type": "number",
            "description": "Base monthly price",
            "example": 29.99
          },
          "baseAnnualPrice": {
            "description": "Base annual price (discounted)",
            "example": 299.99,
            "type": "number"
          },
          "priceRanges": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "from": {
                  "type": "number",
                  "description": "Starting transaction count for this tier",
                  "example": 0
                },
                "to": {
                  "type": "number",
                  "description": "Ending transaction count for this tier",
                  "example": 100
                },
                "rate": {
                  "type": "number",
                  "description": "Rate per transaction in this tier",
                  "example": 0.25
                }
              },
              "required": [
                "from",
                "to",
                "rate"
              ],
              "additionalProperties": false,
              "description": "Price range for tiered pricing"
            },
            "description": "Tiered pricing ranges"
          },
          "includedTransactions": {
            "type": "number",
            "description": "Number of transactions included in base price",
            "example": 100
          },
          "additionalInvoicePrice": {
            "description": "Price per additional invoice beyond included",
            "example": 0.25,
            "type": "number"
          },
          "description": {
            "description": "Plan description",
            "example": "Professional plan with advanced features",
            "type": "string"
          },
          "planType": {
            "description": "Plan type identifier",
            "example": "pro",
            "type": "string"
          },
          "status": {
            "description": "Plan status",
            "example": "active",
            "type": "string",
            "enum": [
              "active",
              "deprecated"
            ]
          }
        },
        "required": [
          "id",
          "name",
          "basePrice",
          "priceRanges",
          "includedTransactions"
        ],
        "additionalProperties": false,
        "description": "Plan details"
      },
      "Partner": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Partner identifier (same value as path `partnerId`)",
            "example": "6022f98854f2c41d7ef2b1fe"
          },
          "distributorExternalId": {
            "type": "string",
            "description": "Parent distributor external ID",
            "example": "dist-123"
          },
          "name": {
            "type": "string",
            "description": "Company/partner name",
            "example": "Acme MSP"
          },
          "externalId": {
            "type": "string",
            "description": "External ID from distributor's system",
            "example": "dist-partner-12345"
          },
          "country": {
            "description": "ISO 3166-1 alpha-2 country code",
            "example": "CA",
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "Partner status",
            "example": "active"
          },
          "createdAt": {
            "type": "string",
            "description": "ISO 8601 timestamp when partner was created",
            "example": "2024-01-01T00:00:00.000Z"
          },
          "contact": {
            "description": "Primary contact information",
            "type": "object",
            "properties": {
              "email": {
                "type": "string",
                "description": "Contact email address",
                "example": "contact@partner.com"
              },
              "name": {
                "type": "string",
                "description": "Contact name",
                "example": "John Smith"
              }
            },
            "required": [
              "email",
              "name"
            ],
            "additionalProperties": false
          },
          "organizationCount": {
            "type": "number",
            "description": "Number of organizations under this partner",
            "example": 5
          }
        },
        "required": [
          "id",
          "distributorExternalId",
          "name",
          "externalId",
          "status",
          "createdAt",
          "organizationCount"
        ],
        "additionalProperties": false,
        "description": "Partner details"
      },
      "OrganizationListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Organization identifier (same value as path `organizationId`)",
            "example": "507f1f77bcf86cd799439011"
          },
          "apiParent": {
            "$ref": "#/components/schemas/ApiParent"
          },
          "name": {
            "type": "string",
            "description": "Organization name",
            "example": "Acme Corporation"
          },
          "externalId": {
            "type": "string",
            "description": "Distributor's external ID for this organization",
            "example": "dist-org-12345"
          },
          "planId": {
            "type": "string",
            "description": "MongoDB ObjectId of the billing plan",
            "example": "507f1f77bcf86cd799439013"
          },
          "status": {
            "type": "string",
            "description": "Organization status",
            "example": "pending_activation"
          },
          "closed": {
            "type": "boolean",
            "description": "Whether the organization is closed (derived from !enabled)",
            "example": false
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
            "description": "ISO 8601 timestamp when organization was created",
            "example": "2024-01-01T00:00:00.000Z"
          }
        },
        "required": [
          "id",
          "apiParent",
          "name",
          "externalId",
          "planId",
          "status",
          "closed",
          "createdAt"
        ],
        "additionalProperties": false,
        "description": "Organization list item"
      },
      "CreateOrganizationData": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Organization identifier (same value as path `organizationId`)",
            "example": "507f1f77bcf86cd799439011"
          },
          "apiParent": {
            "$ref": "#/components/schemas/ApiParent"
          },
          "name": {
            "type": "string",
            "description": "Organization name",
            "example": "Acme Corporation"
          },
          "planId": {
            "type": "string",
            "description": "MongoDB ObjectId of the billing plan",
            "example": "507f1f77bcf86cd799439013"
          },
          "status": {
            "type": "string",
            "description": "Organization status",
            "example": "pending_activation"
          },
          "createdAt": {
            "type": "string",
            "description": "ISO 8601 timestamp when organization was created",
            "example": "2024-01-01T00:00:00.000Z"
          },
          "freeTrialEndDate": {
            "description": "ISO 8601 timestamp when free trial ends",
            "example": "2024-02-01T00:00:00.000Z",
            "type": "string"
          }
        },
        "required": [
          "id",
          "apiParent",
          "name",
          "planId",
          "status",
          "createdAt"
        ],
        "additionalProperties": false,
        "description": "Create organization response data"
      },
      "Organization": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Organization identifier (same value as path `organizationId`)",
            "example": "507f1f77bcf86cd799439011"
          },
          "apiParent": {
            "$ref": "#/components/schemas/ApiParent"
          },
          "name": {
            "type": "string",
            "description": "Organization name",
            "example": "Acme Corporation"
          },
          "externalId": {
            "type": "string",
            "description": "Distributor's external ID for this organization",
            "example": "dist-org-12345"
          },
          "planId": {
            "type": "string",
            "description": "MongoDB ObjectId of the billing plan",
            "example": "507f1f77bcf86cd799439013"
          },
          "status": {
            "type": "string",
            "description": "Organization status",
            "example": "pending_activation"
          },
          "closed": {
            "type": "boolean",
            "description": "Whether the organization is closed (derived from !enabled)",
            "example": false
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
            "description": "ISO 8601 timestamp when organization was created",
            "example": "2024-01-01T00:00:00.000Z"
          },
          "planName": {
            "type": "string",
            "description": "Billing plan name",
            "example": "pro"
          },
          "freeTrialEndDate": {
            "type": "string",
            "description": "ISO 8601 timestamp when free trial ends, or empty string when unset",
            "example": "2024-02-01T00:00:00.000Z"
          }
        },
        "required": [
          "id",
          "apiParent",
          "name",
          "externalId",
          "planId",
          "status",
          "closed",
          "createdAt",
          "planName",
          "freeTrialEndDate"
        ],
        "additionalProperties": false,
        "description": "Organization details"
      },
      "ApiParent": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "distributor",
              "partner"
            ],
            "description": "Parent type — distributor or partner",
            "example": "partner"
          },
          "distributorExternalId": {
            "type": "string",
            "description": "Distributor external ID",
            "example": "sherweb"
          },
          "partnerExternalId": {
            "description": "Partner external ID (present when type is partner)",
            "example": "acme-msp",
            "type": "string"
          },
          "partnerId": {
            "description": "Partner MongoDB ObjectId (present when type is partner)",
            "example": "507f1f77bcf86cd799439012",
            "type": "string"
          }
        },
        "required": [
          "type",
          "distributorExternalId"
        ],
        "additionalProperties": false,
        "description": "API parent — who created the organization"
      }
    },
    "headers": {
      "XRequestId": {
        "description": "Echoes the request ID (incoming `X-Request-ID` header or server-generated UUID v4).",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "XCorrelationId": {
        "description": "Echoes the correlation ID for distributed tracing (incoming `X-Correlation-ID` header or server-generated UUID v4).",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "XIdempotencyReplayed": {
        "description": "Present and set to `true` only when a cached idempotent response is being replayed.",
        "schema": {
          "type": "string",
          "enum": [
            "true"
          ]
        }
      },
      "RetryAfter": {
        "description": "Number of seconds the client should wait before retrying. Sent with 429 responses (rate-limit exceeded or idempotency in-flight).",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      },
      "XRateLimitLimit": {
        "description": "Maximum requests allowed in the current sliding window.",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      },
      "XRateLimitRemaining": {
        "description": "Requests remaining in the current window.",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      },
      "XRateLimitReset": {
        "description": "Unix timestamp (seconds) when the current window resets.",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "responses": {
      "TooManyRequests": {
        "description": "Rate limit exceeded, or an idempotent request with the same key is still being processed. Retry after the duration indicated by `Retry-After`.",
        "headers": {
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          },
          "X-RateLimit-Limit": {
            "$ref": "#/components/headers/XRateLimitLimit"
          },
          "X-RateLimit-Remaining": {
            "$ref": "#/components/headers/XRateLimitRemaining"
          },
          "X-RateLimit-Reset": {
            "$ref": "#/components/headers/XRateLimitReset"
          },
          "X-Request-ID": {
            "$ref": "#/components/headers/XRequestId"
          },
          "X-Correlation-ID": {
            "$ref": "#/components/headers/XCorrelationId"
          }
        },
        "content": {
          "application/problem+json": {
            "schema": {
              "type": "object",
              "description": "RFC 7807 Problem Details for 429 responses.",
              "properties": {
                "type": {
                  "type": "string",
                  "format": "uri"
                },
                "title": {
                  "type": "string"
                },
                "status": {
                  "type": "integer",
                  "enum": [
                    429
                  ]
                },
                "detail": {
                  "type": "string"
                },
                "instance": {
                  "type": "string"
                },
                "requestId": {
                  "type": "string",
                  "format": "uuid"
                },
                "correlationId": {
                  "type": "string",
                  "format": "uuid"
                },
                "retryAfterSeconds": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "type",
                "title",
                "status"
              ]
            }
          }
        }
      }
    },
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Auth0 JWT token obtained via OAuth2 client credentials flow. Include the token in the Authorization header as: Bearer <token>"
      }
    }
  }
}
