{
  "openapi": "3.1.0",
  "info": {
    "title": "Bridge Payments API",
    "version": "1.0.0",
    "description": "Production-ready payment backend for Pubflow. Accept payments with Stripe, PayPal, Polar, and Authorize.net. All API fields use snake_case.",
    "contact": {
      "name": "Pubflow Support",
      "email": "support@pubflow.com",
      "url": "https://pubflow.com"
    }
  },
  "servers": [],
  "tags": [
    {
      "name": "Authentication",
      "description": "Authentication and session management"
    },
    {
      "name": "Payments",
      "description": "Payment processing and management"
    },
    {
      "name": "Payment Methods",
      "description": "Manage saved payment methods"
    },
    {
      "name": "Customers",
      "description": "Customer management"
    },
    {
      "name": "Addresses",
      "description": "Billing and shipping addresses"
    },
    {
      "name": "Products",
      "description": "Public product listing API for active products"
    },
    {
      "name": "Subscriptions",
      "description": "Recurring subscription management"
    },
    {
      "name": "Organizations",
      "description": "Organization and team management"
    },
    {
      "name": "Webhooks",
      "description": "Webhook configuration and management"
    },
    {
      "name": "Guest Conversion",
      "description": "Convert guest checkout data to authenticated users"
    },
    {
      "name": "Health",
      "description": "System health and monitoring"
    },
    {
      "name": "Admin - Products",
      "description": "Admin product management with intelligent pricing"
    },
    {
      "name": "Admin - Sync",
      "description": "Admin bulk synchronization with payment providers"
    },
    {
      "name": "Admin - Subscriptions",
      "description": "Admin subscription analytics and management"
    },
    {
      "name": "Admin - Renewals",
      "description": "Admin subscription renewal system management"
    },
    {
      "name": "Admin - Module Hub",
      "description": "Admin Module Hub / plugins installer. Routes are mounted under /bridge-payment/admin/plugins/*. Supports native manifests and legacy plugin manifests, including SQL path token {dialect} resolved as postgresql.sql, mysql.sql, or sqlite.sql."
    },
    {
      "name": "Bridge Pages",
      "description": "Hosted HTML UI at `/pages/*` when `PAGES_ENABLED=true`. Not under `/bridge-payment`. `/pages/me` returns JSON (Flowless proxy)."
    },
    {
      "name": "Bridge Embeds",
      "description": "Iframe-friendly HTML widgets at `/embed/*` when `EMBED_ENABLED=true`. When `EMBED_CORS` is set, responses may include `Content-Security-Policy: frame-ancestors` from `CORS_ORIGINS`."
    },
    {
      "name": "Projects",
      "description": "Project management and invites. Mounted at `/bridge-payment/projects` when `PROJECTS_ENABLED=true`. Public `GET .../invites/:token` is rate-limited."
    },
    {
      "name": "Memberships",
      "description": "Membership tiers and entity memberships under `/bridge-payment/memberships` (always mounted)."
    },
    {
      "name": "Admin - Memberships",
      "description": "Admin membership and tier management under `/bridge-payment/admin/memberships`. Requires admin user session (same `X-Session-ID` pattern as other admin APIs)."
    },
    {
      "name": "Orders",
      "description": "Order records under `/bridge-payment/orders` when `ORDERS_ENABLED=true`. Supports user, organization, and project scoped filtering."
    },
    {
      "name": "Account Balance",
      "description": "Balance and credit ledger under `/bridge-payment/account-balance` when `ACCOUNT_BALANCE_ENABLED=true`, with optional auth/RBAC/rate limits."
    },
    {
      "name": "Cost Tracking",
      "description": "Product, order, and subscription cost analytics under `/bridge-payment/cost-tracking` when `COST_TRACKING_ENABLED=true`. Additional gates: `COST_TRACKING_REQUIRE_AUTH`, optional RBAC via `COST_TRACKING_ALLOWED_ROLES`, rate limits."
    },
    {
      "name": "Billing Schedules",
      "description": "Recurring billing schedules under `/bridge-payment/billing-schedules` when `BILLING_SCHEDULES_ENABLED=true`. Optional auth/RBAC/rate limits per environment."
    },
    {
      "name": "Invoices",
      "description": "Invoice resources under `/bridge-payment/invoices` when `INVOICES_RECEIPTS_ENABLED=true`. Session-authenticated."
    },
    {
      "name": "Receipts",
      "description": "Receipt resources under `/bridge-payment/receipts` when `INVOICES_RECEIPTS_ENABLED=true`. Feature gate, optional auth/RBAC/rate limits."
    }
  ],
  "paths": {
    "/bridge-payment/payments/intents": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Create Payment Intent",
        "description": "Create a new payment intent with intelligent pricing calculation. Supports both authenticated users and guest checkout. The system automatically calculates missing pricing fields (subtotal, tax, discount, total) based on provided values.",
        "operationId": "createPaymentIntent",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "subtotal_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Subtotal amount in cents (before tax and discounts). Optional if total_cents is provided.",
                    "example": 5000
                  },
                  "tax_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Tax amount in cents. Optional - can be calculated automatically.",
                    "example": 500
                  },
                  "discount_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Discount amount in cents. Optional.",
                    "example": 0
                  },
                  "total_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Total amount in cents (final amount to charge). Optional if subtotal_cents is provided.",
                    "example": 5500
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Three-letter ISO currency code (e.g., USD, EUR, MXN)",
                    "example": "USD"
                  },
                  "concept": {
                    "type": "string",
                    "description": "Human-readable payment concept (e.g., 'Monthly Subscription', 'Donation')",
                    "example": "Product Purchase"
                  },
                  "description": {
                    "type": "string",
                    "description": "Detailed payment description",
                    "example": "Purchase of premium subscription"
                  },
                  "provider_id": {
                    "type": "string",
                    "description": "Payment provider ID (stripe, paypal, polar, authorize_net). If not provided, uses default provider.",
                    "example": "stripe"
                  },
                  "payment_method_id": {
                    "type": "string",
                    "description": "Saved payment method ID to use for this payment",
                    "example": "pm_1234567890"
                  },
                  "organization_id": {
                    "type": "string",
                    "description": "Optional organization scope for this payment intent (access-checked)."
                  },
                  "project_id": {
                    "type": "string",
                    "description": "Optional project scope for this payment intent (project access is validated)."
                  },
                  "return_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL to redirect after payment completion",
                    "example": "https://example.com/payment/success"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Custom metadata to attach to the payment",
                    "example": {
                      "order_id": "ORD-123",
                      "customer_note": "Gift wrap"
                    }
                  },
                  "guest_data": {
                    "type": "object",
                    "description": "Guest user information (required for guest checkout, omit for authenticated users)",
                    "properties": {
                      "email": {
                        "type": "string",
                        "format": "email",
                        "description": "Guest email address",
                        "example": "guest@example.com"
                      },
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Guest full name",
                        "example": "John Doe"
                      },
                      "phone": {
                        "type": "string",
                        "description": "Guest phone number (optional)",
                        "example": "+1234567890"
                      }
                    },
                    "required": [
                      "email",
                      "name"
                    ]
                  },
                  "reference_code": {
                    "type": "string",
                    "description": "Machine-readable reference code for analytics",
                    "example": "donation_general"
                  },
                  "category": {
                    "type": "string",
                    "description": "High-level payment category",
                    "example": "donation"
                  },
                  "tags": {
                    "type": "string",
                    "description": "Comma-separated tags for categorization",
                    "example": "recurring,premium"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment intent created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "pay_1234567890"
                        },
                        "client_secret": {
                          "type": "string",
                          "example": "pi_xxx_secret_yyy"
                        },
                        "amount_cents": {
                          "type": "integer",
                          "example": 5500
                        },
                        "currency": {
                          "type": "string",
                          "example": "USD"
                        },
                        "status": {
                          "type": "string",
                          "example": "requires_payment_method"
                        },
                        "provider_id": {
                          "type": "string",
                          "example": "stripe"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request - validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "At least one pricing field must be provided"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payments": {
      "get": {
        "tags": [
          "Payments"
        ],
        "summary": "List Payments",
        "description": "Get a paginated list of payments with detailed information. Authenticated users see their own payments. Guest users with token see payments filtered by their email. Use the `include` parameter to fetch related data like payment method details for better performance and smaller responses.",
        "operationId": "listPayments",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "description": "Page number for pagination"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            },
            "description": "Number of items per page (max 50)"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "processing",
                "succeeded",
                "failed",
                "canceled"
              ]
            },
            "description": "Filter by payment status"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search by payment ID, email, or description"
          },
          {
            "name": "created_at_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter payments created after this date"
          },
          {
            "name": "created_at_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter payments created before this date"
          },
          {
            "name": "orderBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "created_at",
                "amount_cents",
                "status",
                "updated_at"
              ],
              "default": "created_at"
            },
            "description": "Field to order by"
          },
          {
            "name": "orderDir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            },
            "description": "Order direction"
          },
          {
            "name": "include",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of related resources to include in the response. **Available options:** `payment_method` (includes card brand, last 4 digits, expiry date, wallet type, etc.). **Example:** `?include=payment_method`. **Performance:** This parameter improves API efficiency by only fetching related data when explicitly requested, reducing response size and query time when payment method details are not needed.",
            "example": "payment_method"
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Guest token for accessing guest payments"
          }
        ],
        "responses": {
          "200": {
            "description": "List of payments retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "pay_1234567890",
                            "description": "Payment ID"
                          },
                          "subtotal_cents": {
                            "type": "integer",
                            "example": 5000,
                            "description": "Subtotal amount in cents"
                          },
                          "tax_cents": {
                            "type": "integer",
                            "example": 500,
                            "description": "Tax amount in cents"
                          },
                          "discount_cents": {
                            "type": "integer",
                            "example": 0,
                            "description": "Discount amount in cents"
                          },
                          "total_cents": {
                            "type": "integer",
                            "example": 5500,
                            "description": "Total amount in cents"
                          },
                          "amount_cents": {
                            "type": "integer",
                            "example": 5500,
                            "description": "Legacy field - equals total_cents"
                          },
                          "currency": {
                            "type": "string",
                            "example": "USD"
                          },
                          "status": {
                            "type": "string",
                            "example": "succeeded",
                            "enum": [
                              "pending",
                              "processing",
                              "succeeded",
                              "failed",
                              "canceled"
                            ]
                          },
                          "description": {
                            "type": "string",
                            "example": "Monthly subscription payment"
                          },
                          "concept": {
                            "type": "string",
                            "example": "Product Purchase"
                          },
                          "reference_code": {
                            "type": "string",
                            "example": "ORD-2024-001"
                          },
                          "category": {
                            "type": "string",
                            "example": "subscription"
                          },
                          "tags": {
                            "type": "string",
                            "example": "premium,monthly"
                          },
                          "provider_id": {
                            "type": "string",
                            "example": "stripe"
                          },
                          "payment_method_id": {
                            "type": "string",
                            "example": "pm_1234567890",
                            "description": "Payment method ID if used"
                          },
                          "payment_method": {
                            "type": "object",
                            "description": "Payment method details (only included when `include=payment_method` parameter is provided and payment_method_id exists). Omit the `include` parameter for faster responses when payment method details are not needed.",
                            "properties": {
                              "id": {
                                "type": "string",
                                "example": "pm_1234567890"
                              },
                              "payment_type": {
                                "type": "string",
                                "example": "card",
                                "enum": [
                                  "card",
                                  "bank_account",
                                  "paypal"
                                ]
                              },
                              "wallet_type": {
                                "type": "string",
                                "example": "apple_pay",
                                "enum": [
                                  "apple_pay",
                                  "google_pay",
                                  "samsung_pay"
                                ]
                              },
                              "card_brand": {
                                "type": "string",
                                "example": "visa",
                                "enum": [
                                  "visa",
                                  "mastercard",
                                  "amex",
                                  "discover"
                                ]
                              },
                              "last_four": {
                                "type": "string",
                                "example": "4242"
                              },
                              "expiry_month": {
                                "type": "string",
                                "example": "12"
                              },
                              "expiry_year": {
                                "type": "string",
                                "example": "2025"
                              },
                              "alias": {
                                "type": "string",
                                "example": "My Visa Card"
                              }
                            }
                          },
                          "is_guest_payment": {
                            "type": "boolean",
                            "example": false
                          },
                          "guest_email": {
                            "type": "string",
                            "example": "guest@example.com",
                            "description": "Only included for guest payments"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "completed_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "description": "Pagination metadata",
                      "properties": {
                        "page": {
                          "type": "integer",
                          "example": 1,
                          "description": "Current page number"
                        },
                        "limit": {
                          "type": "integer",
                          "example": 20,
                          "description": "Items per page"
                        },
                        "total": {
                          "type": "integer",
                          "example": 45,
                          "description": "Total number of payments"
                        },
                        "hasMore": {
                          "type": "boolean",
                          "example": true,
                          "description": "Whether there are more pages"
                        },
                        "orderBy": {
                          "type": "string",
                          "example": "created_at",
                          "description": "Field used for ordering"
                        },
                        "orderDir": {
                          "type": "string",
                          "example": "desc",
                          "enum": [
                            "asc",
                            "desc"
                          ],
                          "description": "Sort direction"
                        }
                      }
                    },
                    "user_context": {
                      "type": "object",
                      "description": "User context information",
                      "properties": {
                        "authenticated": {
                          "type": "boolean",
                          "example": true
                        },
                        "user_id": {
                          "type": "string",
                          "example": "usr_123"
                        },
                        "user_type": {
                          "type": "string",
                          "example": "customer"
                        },
                        "user_email": {
                          "type": "string",
                          "example": "user@example.com"
                        },
                        "search_method": {
                          "type": "string",
                          "example": "user_id",
                          "enum": [
                            "user_id",
                            "guest_email"
                          ]
                        }
                      }
                    }
                  },
                  "example": {
                    "success": true,
                    "data": [
                      {
                        "id": "pay_1234567890",
                        "subtotal_cents": 5000,
                        "tax_cents": 500,
                        "discount_cents": 0,
                        "total_cents": 5500,
                        "amount_cents": 5500,
                        "currency": "USD",
                        "status": "succeeded",
                        "description": "Monthly Premium Subscription",
                        "concept": "Subscription Payment",
                        "reference_code": "SUB-2024-001",
                        "category": "subscription",
                        "tags": "premium,monthly",
                        "provider_id": "stripe",
                        "payment_method_id": "pm_1234567890",
                        "payment_method": {
                          "id": "pm_1234567890",
                          "payment_type": "card",
                          "wallet_type": "apple_pay",
                          "card_brand": "visa",
                          "last_four": "4242",
                          "expiry_month": "12",
                          "expiry_year": "2025",
                          "alias": "My Visa Card"
                        },
                        "is_guest_payment": false,
                        "created_at": "2024-01-15T10:30:00Z",
                        "updated_at": "2024-01-15T10:30:15Z",
                        "completed_at": "2024-01-15T10:30:15Z"
                      },
                      {
                        "id": "pay_0987654321",
                        "subtotal_cents": 10000,
                        "tax_cents": 0,
                        "discount_cents": 1000,
                        "total_cents": 9000,
                        "amount_cents": 9000,
                        "currency": "USD",
                        "status": "succeeded",
                        "description": "One-time donation",
                        "concept": "Donation",
                        "reference_code": "DON-2024-042",
                        "category": "donation",
                        "tags": "one-time,general",
                        "provider_id": "stripe",
                        "payment_method_id": "pm_0987654321",
                        "payment_method": {
                          "id": "pm_0987654321",
                          "payment_type": "card",
                          "card_brand": "mastercard",
                          "last_four": "5555",
                          "expiry_month": "06",
                          "expiry_year": "2026",
                          "alias": "Personal Mastercard"
                        },
                        "is_guest_payment": false,
                        "created_at": "2024-01-10T14:20:00Z",
                        "updated_at": "2024-01-10T14:20:10Z",
                        "completed_at": "2024-01-10T14:20:10Z"
                      }
                    ],
                    "meta": {
                      "page": 1,
                      "limit": 20,
                      "total": 45,
                      "hasMore": true,
                      "orderBy": "created_at",
                      "orderDir": "desc"
                    },
                    "user_context": {
                      "authenticated": true,
                      "user_id": "usr_abc123",
                      "user_type": "customer",
                      "user_email": "user@example.com",
                      "search_method": "user_id"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payments/{id}": {
      "get": {
        "tags": [
          "Payments"
        ],
        "summary": "Get Payment by ID",
        "description": "Get detailed information about a specific payment. Users can only access their own payments. Guest users with token can access payments filtered by their email.",
        "operationId": "getPaymentById",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment ID",
            "example": "pay_1234567890"
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Guest token for accessing guest payment"
          }
        ],
        "responses": {
          "200": {
            "description": "Payment details retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "pay_1234567890",
                          "description": "Payment ID"
                        },
                        "subtotal_cents": {
                          "type": "integer",
                          "example": 5000,
                          "description": "Subtotal amount in cents"
                        },
                        "tax_cents": {
                          "type": "integer",
                          "example": 500,
                          "description": "Tax amount in cents"
                        },
                        "discount_cents": {
                          "type": "integer",
                          "example": 0,
                          "description": "Discount amount in cents"
                        },
                        "total_cents": {
                          "type": "integer",
                          "example": 5500,
                          "description": "Total amount in cents"
                        },
                        "amount_cents": {
                          "type": "integer",
                          "example": 5500,
                          "description": "Legacy field - equals total_cents"
                        },
                        "currency": {
                          "type": "string",
                          "example": "USD",
                          "description": "Currency code (ISO 4217)"
                        },
                        "status": {
                          "type": "string",
                          "example": "succeeded",
                          "enum": [
                            "pending",
                            "processing",
                            "succeeded",
                            "failed",
                            "canceled"
                          ],
                          "description": "Payment status"
                        },
                        "description": {
                          "type": "string",
                          "example": "Monthly subscription payment",
                          "description": "Human-readable payment description"
                        },
                        "concept": {
                          "type": "string",
                          "example": "Product Purchase",
                          "description": "Payment concept/purpose"
                        },
                        "reference_code": {
                          "type": "string",
                          "example": "ORD-2024-001",
                          "description": "External reference code"
                        },
                        "category": {
                          "type": "string",
                          "example": "subscription",
                          "description": "Payment category"
                        },
                        "tags": {
                          "type": "string",
                          "example": "premium,monthly",
                          "description": "Comma-separated tags"
                        },
                        "provider_id": {
                          "type": "string",
                          "example": "stripe",
                          "description": "Payment provider identifier"
                        },
                        "provider_payment_id": {
                          "type": "string",
                          "example": "pi_xxx",
                          "description": "Provider's payment ID"
                        },
                        "provider_intent_id": {
                          "type": "string",
                          "example": "pi_xxx",
                          "description": "Provider's payment intent ID"
                        },
                        "client_secret": {
                          "type": "string",
                          "example": "pi_xxx_secret_yyy",
                          "description": "Client secret for payment confirmation"
                        },
                        "payment_method_id": {
                          "type": "string",
                          "example": "pm_1234567890",
                          "description": "Payment method ID if used"
                        },
                        "payment_method": {
                          "type": "object",
                          "description": "Payment method details (included when payment_method_id is present)",
                          "properties": {
                            "id": {
                              "type": "string",
                              "example": "pm_1234567890"
                            },
                            "payment_type": {
                              "type": "string",
                              "example": "card",
                              "enum": [
                                "card",
                                "bank_account",
                                "paypal"
                              ]
                            },
                            "wallet_type": {
                              "type": "string",
                              "example": "apple_pay",
                              "enum": [
                                "apple_pay",
                                "google_pay",
                                "samsung_pay"
                              ]
                            },
                            "card_brand": {
                              "type": "string",
                              "example": "visa",
                              "enum": [
                                "visa",
                                "mastercard",
                                "amex",
                                "discover"
                              ]
                            },
                            "last_four": {
                              "type": "string",
                              "example": "4242"
                            },
                            "expiry_month": {
                              "type": "string",
                              "example": "12"
                            },
                            "expiry_year": {
                              "type": "string",
                              "example": "2025"
                            },
                            "alias": {
                              "type": "string",
                              "example": "My Visa Card"
                            }
                          }
                        },
                        "is_guest_payment": {
                          "type": "boolean",
                          "example": false,
                          "description": "Whether this is a guest payment"
                        },
                        "guest_email": {
                          "type": "string",
                          "example": "guest@example.com",
                          "description": "Guest email (only for guest payments)"
                        },
                        "metadata": {
                          "type": "object",
                          "description": "Custom metadata attached to payment"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time",
                          "description": "Payment creation timestamp"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time",
                          "description": "Last update timestamp"
                        },
                        "completed_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "Payment completion timestamp"
                        }
                      }
                    }
                  },
                  "example": {
                    "success": true,
                    "data": {
                      "id": "pay_1234567890",
                      "subtotal_cents": 5000,
                      "tax_cents": 500,
                      "discount_cents": 0,
                      "total_cents": 5500,
                      "amount_cents": 5500,
                      "currency": "USD",
                      "status": "succeeded",
                      "description": "Monthly Premium Subscription",
                      "concept": "Subscription Payment",
                      "reference_code": "SUB-2024-001",
                      "category": "subscription",
                      "tags": "premium,monthly",
                      "provider_id": "stripe",
                      "provider_payment_id": "pi_3QRxyz123456789",
                      "provider_intent_id": "pi_3QRxyz123456789",
                      "client_secret": "pi_3QRxyz123456789_secret_abc123",
                      "payment_method_id": "pm_1234567890",
                      "payment_method": {
                        "id": "pm_1234567890",
                        "payment_type": "card",
                        "wallet_type": "apple_pay",
                        "card_brand": "visa",
                        "last_four": "4242",
                        "expiry_month": "12",
                        "expiry_year": "2025",
                        "alias": "My Visa Card"
                      },
                      "is_guest_payment": false,
                      "metadata": {
                        "order_id": "ORD-123",
                        "customer_note": "Premium plan"
                      },
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-15T10:30:15Z",
                      "completed_at": "2024-01-15T10:30:15Z"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Payment not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "Payment not found"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payments/intents/{id}": {
      "put": {
        "tags": [
          "Payments"
        ],
        "summary": "Update Payment Intent",
        "description": "Update an existing payment intent before confirmation. Can only update pending payment intents.",
        "operationId": "updatePaymentIntent",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment intent ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "New amount in cents"
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "New currency code"
                  },
                  "description": {
                    "type": "string",
                    "description": "Updated description"
                  },
                  "setup_future_usage": {
                    "type": "string",
                    "enum": [
                      "on_session",
                      "off_session"
                    ],
                    "description": "Setup for future payments"
                  },
                  "customer_id": {
                    "type": "string",
                    "description": "Customer ID to associate"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Updated metadata"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment intent updated successfully"
          },
          "404": {
            "description": "Payment intent not found"
          }
        }
      }
    },
    "/bridge-payment/payments/intents/{id}/confirm": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Confirm Payment Intent",
        "description": "Confirm and process a payment intent. Optionally save the payment method for future use.",
        "operationId": "confirmPaymentIntent",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment intent ID"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "payment_method_id": {
                    "type": "string",
                    "description": "Payment method ID to use (from provider)"
                  },
                  "return_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL to redirect after payment (required for some payment methods)"
                  },
                  "save_payment_method": {
                    "type": "boolean",
                    "default": false,
                    "description": "Save payment method for future use"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment confirmed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "example": "succeeded"
                        },
                        "amount_cents": {
                          "type": "integer"
                        },
                        "currency": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payments/intents/{id}/sync": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Sync Payment Intent Status",
        "description": "Synchronize payment intent status with the payment provider. Used after frontend confirms payment with Stripe Payment Elements. Triggers email notifications and payment method saving.",
        "operationId": "syncPaymentIntent",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment intent ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Payment status synchronized successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "example": "succeeded"
                        },
                        "synced_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payment-methods": {
      "get": {
        "tags": [
          "Payment Methods"
        ],
        "summary": "List Payment Methods",
        "description": "Get a paginated list of payment methods. Supports guest token authentication for guest users.",
        "operationId": "listPaymentMethods",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "payment_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "credit_card",
                "debit_card",
                "bank_account",
                "paypal"
              ]
            }
          },
          {
            "name": "card_brand",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional organization scope for org payment methods (access-checked)."
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Guest token for accessing guest payment methods"
          }
        ],
        "responses": {
          "200": {
            "description": "List of payment methods retrieved successfully"
          }
        }
      },
      "post": {
        "tags": [
          "Payment Methods"
        ],
        "summary": "Create Payment Method (Token-based)",
        "description": "Create a new payment method using a payment method token from the frontend (Stripe Elements). This is the recommended secure method.",
        "operationId": "createPaymentMethod",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "payment_method_token",
                  "type",
                  "provider_id"
                ],
                "properties": {
                  "payment_method_token": {
                    "type": "string",
                    "description": "Payment method token from frontend (e.g., Stripe Elements)",
                    "example": "pm_1234567890"
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "credit_card",
                      "bank_account",
                      "paypal"
                    ],
                    "description": "Payment method type"
                  },
                  "wallet_type": {
                    "type": "string",
                    "enum": [
                      "apple_pay",
                      "google_pay",
                      "samsung_pay"
                    ],
                    "description": "Wallet type for digital wallet payments (optional)"
                  },
                  "provider_id": {
                    "type": "string",
                    "description": "Payment provider ID",
                    "example": "stripe"
                  },
                  "customer_id": {
                    "type": "string",
                    "description": "Customer ID to associate payment method with"
                  },
                  "organization_id": {
                    "type": "string",
                    "description": "Optional organization scope for the payment method (access-checked)."
                  },
                  "alias": {
                    "type": "string",
                    "description": "User-friendly name for the payment method",
                    "example": "My Visa Card"
                  },
                  "billing_address_id": {
                    "type": "string",
                    "description": "Existing billing address ID"
                  },
                  "billing_details": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string",
                        "format": "email"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "address": {
                        "type": "object",
                        "properties": {
                          "line1": {
                            "type": "string"
                          },
                          "line2": {
                            "type": "string"
                          },
                          "city": {
                            "type": "string"
                          },
                          "state": {
                            "type": "string"
                          },
                          "postal_code": {
                            "type": "string"
                          },
                          "country": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment method created successfully"
          }
        }
      }
    },
    "/bridge-payment/payment-methods/setup-intent": {
      "post": {
        "tags": ["Payment Methods"],
        "summary": "Create Payment Method Setup Intent",
        "description": "Creates a Stripe SetupIntent and returns its `client_secret`. Required for Apple Pay and Google Pay wallet flows.\n\n**Why this endpoint exists:**\nWhen using Stripe's PaymentRequest API, the native wallet sheet (Apple Pay / Google Pay) waits for Stripe to server-confirm the operation. Without calling `stripe.confirmCardSetup(client_secret, ...)` **before** `event.complete('success')`, the sheet stays in processing state and shows **\"Load failed\"**.\n\n**Auth policy — authenticated users only:**\nGuests and anonymous callers are rejected (401/403). SetupIntents are used to save payment methods for future use; guests have no persistent account to save to, and allowing unauthenticated access would allow unlimited Stripe API calls (DoS vector).\n\n**Customer handling:**\nThis endpoint does **not** auto-create Stripe customers. It performs a best-effort lookup — if the authenticated user already has a Stripe customer, the SetupIntent is attached to it. Customer creation happens in `POST /payment-methods` after the wallet flow completes.\n\n**Frontend contract (step order):**\n1. Call this endpoint → receive `client_secret`\n2. User taps wallet button → payment sheet opens\n3. User authenticates\n4. In `paymentmethod` event: `stripe.confirmCardSetup(client_secret, { payment_method: ev.paymentMethod.id })`\n5. `ev.complete('success')` → sheet closes\n6. Call `POST /payment-methods` to save the PM to Bridge",
        "operationId": "createPaymentMethodSetupIntent",
        "security": [
          { "SessionAuth": [] },
          { "BearerAuth": [] }
        ],

        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "enum": ["stripe"],
                    "default": "stripe",
                    "description": "Payment provider. Currently only `stripe` is supported."
                  }
                }
              },
              "example": {
                "provider_id": "stripe"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SetupIntent created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "setup_intent_id": {
                      "type": "string",
                      "description": "Stripe SetupIntent ID (for reference and logging).",
                      "example": "seti_1234567890abcdef"
                    },
                    "client_secret": {
                      "type": "string",
                      "description": "Pass to `stripe.confirmCardSetup()` in the frontend. Never log or expose this value.",
                      "example": "seti_1234567890abcdef_secret_xxxx"
                    }
                  },
                  "required": ["success", "setup_intent_id", "client_secret"]
                },
                "example": {
                  "success": true,
                  "setup_intent_id": "seti_1234567890abcdef",
                  "client_secret": "seti_1234567890abcdef_secret_xxxx"
                }
              }
            }
          },
          "400": {
            "description": "Provider not supported (non-Stripe provider requested)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "error": "Not Supported", "message": "SetupIntent is only supported for Stripe" }
              }
            }
          },
          "401": {
            "description": "Not authenticated — any valid authenticated session is required",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "error": "Unauthorized", "message": "Authentication required" }
              }
            }
          },
          "500": {
            "description": "Internal server error — Stripe API failure",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/payment-methods/{id}": {
      "get": {
        "tags": [
          "Payment Methods"
        ],
        "summary": "Get Payment Method by ID",
        "description": "Get detailed information about a specific payment method. Supports guest token authentication.",
        "operationId": "getPaymentMethodById",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payment method details retrieved successfully"
          },
          "404": {
            "description": "Payment method not found"
          }
        }
      },
      "put": {
        "tags": [
          "Payment Methods"
        ],
        "summary": "Update Payment Method",
        "description": "Update local payment method fields (alias, default status, billing address). Does not modify provider data.",
        "operationId": "updatePaymentMethod",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "is_default": {
                    "type": "boolean",
                    "description": "Set as default payment method"
                  },
                  "billing_address_id": {
                    "type": "string",
                    "nullable": true,
                    "description": "Update billing address ID"
                  },
                  "alias": {
                    "type": "string",
                    "nullable": true,
                    "description": "Update user-friendly name"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment method updated successfully"
          }
        }
      },
      "delete": {
        "tags": [
          "Payment Methods"
        ],
        "summary": "Delete Payment Method",
        "description": "Delete a payment method from both the provider and local database. Supports guest token authentication.",
        "operationId": "deletePaymentMethod",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payment method deleted successfully"
          }
        }
      }
    },
    "/bridge-payment/payment-methods/{id}/billing-address": {
      "patch": {
        "tags": ["Payment Methods"],
        "operationId": "patchPaymentMethodBillingAddress",
        "summary": "Link or unlink billing address (provider sync)",
        "description": "Dedicated route to set `billing_address_id` and sync resolved billing details to the provider when supported. Pass `null` to unlink. Provider sync is best-effort and non-fatal.",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["billing_address_id"],
                "properties": {
                  "billing_address_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true,
                    "description": "Address ID to link, or null to unlink"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Billing address linked/unlinked. Response may include provider sync status (for example, provider_synced)."
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Insufficient privileges or address ownership"
          },
          "404": {
            "description": "Payment method or address not found"
          }
        }
      }
    },
    "/bridge-payment/customers": {
      "get": {
        "tags": [
          "Customers"
        ],
        "summary": "List Customers",
        "description": "Get a paginated list of customers. Authenticated users see their own customers.",
        "operationId": "listCustomers",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of customers retrieved successfully"
          }
        }
      },
      "post": {
        "tags": [
          "Customers"
        ],
        "summary": "Create Customer",
        "description": "Create a new customer record with the payment provider and in the local database.",
        "operationId": "createCustomer",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "name"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Customer email address"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Customer full name"
                  },
                  "phone": {
                    "type": "string",
                    "nullable": true,
                    "description": "Customer phone number (optional)"
                  },
                  "provider_id": {
                    "type": "string",
                    "default": "stripe",
                    "description": "Payment provider ID"
                  },
                  "organization_id": {
                    "type": "string",
                    "description": "Optional organization scope for the customer (access-checked)."
                  },
                  "project_id": {
                    "type": "string",
                    "description": "Optional project scope for the customer."
                  },
                  "is_guest": {
                    "type": "boolean",
                    "default": false,
                    "description": "Whether this is a guest customer"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Customer created successfully"
          }
        }
      }
    },
    "/bridge-payment/customers/{id}": {
      "get": {
        "tags": [
          "Customers"
        ],
        "summary": "Get Customer by ID",
        "description": "Get detailed information about a specific customer.",
        "operationId": "getCustomerById",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer details retrieved successfully"
          },
          "404": {
            "description": "Customer not found"
          }
        }
      },
      "put": {
        "tags": [
          "Customers"
        ],
        "summary": "Update Customer",
        "description": "Update customer information in both the provider and local database.",
        "operationId": "updateCustomer",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "phone": {
                    "type": "string",
                    "nullable": true
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Customer updated successfully"
          }
        }
      },
      "delete": {
        "tags": [
          "Customers"
        ],
        "summary": "Delete Customer",
        "description": "Delete a customer from both the provider and local database.",
        "operationId": "deleteCustomer",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer deleted successfully"
          }
        }
      }
    },
    "/bridge-payment/addresses": {
      "get": {
        "tags": [
          "Addresses"
        ],
        "summary": "List Addresses",
        "description": "Get a paginated list of addresses. Supports guest token authentication. Scope filter supports organization_id; project_id is not supported on this endpoint.",
        "operationId": "listAddresses",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "address_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "billing",
                "shipping",
                "both"
              ]
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional organization scope for listing addresses (access-checked)."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "completeness",
            "in": "query",
            "description": "Filter by address completeness",
            "schema": {
              "type": "string",
              "enum": [
                "full",
                "partial",
                "any"
              ],
              "default": "any"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of addresses retrieved successfully"
          }
        }
      },
      "post": {
        "tags": [
          "Addresses"
        ],
        "summary": "Create Address",
        "description": "Create a new billing or shipping address.",
        "operationId": "createAddress",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "address_type",
                  "country"
                ],
                "properties": {
                  "address_type": {
                    "type": "string",
                    "enum": [
                      "billing",
                      "shipping",
                      "both"
                    ],
                    "description": "Type of address"
                  },
                  "organization_id": {
                    "type": "string",
                    "description": "Optional organization scope for this address (access-checked)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Recipient/contact name (required for full personal addresses)"
                  },
                  "line1": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Address line 1 (required for full addresses unless is_partial=true)"
                  },
                  "line2": {
                    "type": "string",
                    "description": "Address line 2 (optional)"
                  },
                  "city": {
                    "type": "string",
                    "minLength": 1,
                    "description": "City (required for full addresses unless is_partial=true)"
                  },
                  "state": {
                    "type": "string",
                    "description": "State/Province (optional)"
                  },
                  "postal_code": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Postal/ZIP code (required for full addresses unless is_partial=true)"
                  },
                  "country": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2,
                    "description": "2-letter ISO country code",
                    "example": "US"
                  },
                  "is_partial": {
                    "type": "boolean",
                    "default": false,
                    "description": "When true, allows partial addresses (country-only minimum)."
                  },
                  "is_business": {
                    "type": "boolean",
                    "default": false,
                    "description": "Marks this address as a business (B2B) address."
                  },
                  "business_name": {
                    "type": "string",
                    "description": "Legal business name. Required when is_business=true."
                  },
                  "tax_id": {
                    "type": "string",
                    "description": "Tax identifier value (jurisdiction specific)."
                  },
                  "tax_id_type": {
                    "type": "string",
                    "enum": [
                      "vat",
                      "ein",
                      "rfc",
                      "rnc",
                      "cnpj",
                      "cpf",
                      "gst",
                      "nit",
                      "cuit",
                      "nif",
                      "siren",
                      "kvk",
                      "other"
                    ],
                    "description": "Type/format of tax_id."
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone number (optional)"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Email address (optional)"
                  },
                  "alias": {
                    "type": "string",
                    "description": "User-friendly name for the address",
                    "example": "Home Address"
                  },
                  "is_default": {
                    "type": "boolean",
                    "default": false,
                    "description": "Set as default address"
                  },
                  "guest_email": {
                    "type": "string",
                    "format": "email",
                    "description": "Guest email (for guest users)"
                  },
                  "guest_name": {
                    "type": "string",
                    "description": "Guest name (for guest users)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Address created successfully"
          }
        }
      }
    },
    "/bridge-payment/addresses/{id}": {
      "get": {
        "tags": [
          "Addresses"
        ],
        "summary": "Get Address by ID",
        "description": "Get detailed information about a specific address. Supports guest token authentication.",
        "operationId": "getAddressById",
        "security": [
          {
            "SessionAuth": []
          },
          {
            "GuestToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Address details retrieved successfully"
          },
          "404": {
            "description": "Address not found"
          }
        }
      },
      "put": {
        "tags": [
          "Addresses"
        ],
        "summary": "Update Address",
        "description": "Update an existing address.",
        "operationId": "updateAddress",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "address_type": {
                    "type": "string",
                    "enum": [
                      "billing",
                      "shipping",
                      "both"
                    ]
                  },
                  "name": {
                    "type": "string"
                  },
                  "line1": {
                    "type": "string"
                  },
                  "line2": {
                    "type": "string"
                  },
                  "city": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string"
                  },
                  "postal_code": {
                    "type": "string"
                  },
                  "country": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 2
                  },
                  "is_partial": {
                    "type": "boolean",
                    "description": "Toggle between partial and full address validation mode."
                  },
                  "is_business": {
                    "type": "boolean",
                    "description": "Set true for B2B addresses."
                  },
                  "business_name": {
                    "type": "string",
                    "description": "Legal business name (required when is_business=true)."
                  },
                  "tax_id": {
                    "type": "string",
                    "description": "Business tax identifier value."
                  },
                  "tax_id_type": {
                    "type": "string",
                    "enum": [
                      "vat",
                      "ein",
                      "rfc",
                      "rnc",
                      "cnpj",
                      "cpf",
                      "gst",
                      "nit",
                      "cuit",
                      "nif",
                      "siren",
                      "kvk",
                      "other"
                    ],
                    "description": "Type/format of tax_id."
                  },
                  "phone": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "alias": {
                    "type": "string"
                  },
                  "is_default": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Address updated successfully"
          }
        }
      },
      "delete": {
        "tags": [
          "Addresses"
        ],
        "summary": "Delete Address",
        "description": "Delete an address. For guest users, requires guest_email query parameter for verification.",
        "operationId": "deleteAddress",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "guest_email",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "email"
            },
            "description": "Guest email for verification (required for guest users)"
          }
        ],
        "responses": {
          "200": {
            "description": "Address deleted successfully"
          }
        }
      }
    },
    "/bridge-payment/products": {
      "get": {
        "tags": [
          "Products"
        ],
        "summary": "List Products",
        "description": "Get a paginated list of active products. Supports filtering by category, product type, recurrence and search. Visibility/auth depends on PUBLIC_PRODUCT_LISTING and PRODUCT_LISTING_ENABLED.",
        "operationId": "listProducts",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by category"
          },
          {
            "name": "product_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "physical",
                "digital",
                "service",
                "subscription"
              ]
            },
            "description": "Filter by product type"
          },
          {
            "name": "is_recurring",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Filter recurring products"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search by product name/description"
          },
          {
            "name": "orderBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "name",
                "subtotal_cents",
                "created_at"
              ]
            }
          },
          {
            "name": "orderDir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of active products"
          },
          "401": {
            "description": "Authentication required when PUBLIC_PRODUCT_LISTING=false"
          }
        }
      }
    },
    "/bridge-payment/products/{id}": {
      "get": {
        "tags": [
          "Products"
        ],
        "summary": "Get Product by ID",
        "description": "Get an active product by ID. Returns 404 when not found or inactive. Visibility/auth depends on PUBLIC_PRODUCT_LISTING and PRODUCT_LISTING_ENABLED.",
        "operationId": "getProductById",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Product retrieved successfully"
          },
          "404": {
            "description": "Product not found"
          },
          "401": {
            "description": "Authentication required when PUBLIC_PRODUCT_LISTING=false"
          }
        }
      }
    },
    "/bridge-payment/subscriptions": {
      "get": {
        "tags": [
          "Subscriptions"
        ],
        "summary": "List Subscriptions",
        "description": "Get a paginated list of subscriptions for the authenticated user. Supports optional payment method expansion and optional project details expansion. You can filter by organization_id, project_id, or both together.",
        "operationId": "listSubscriptions",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "canceled",
                "past_due",
                "incomplete",
                "trialing",
                "paused"
              ]
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional organization scope for org subscriptions."
          },
          {
            "name": "project_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional project filter. Access is validated against project permissions."
          },
          {
            "name": "include_projects",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "When true, includes resolved project details in each subscription result."
          },
          {
            "name": "include_pm",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "When true, includes nested payment method details in each subscription result."
          }
        ],
        "responses": {
          "200": {
            "description": "List of subscriptions retrieved successfully"
          }
        }
      },
      "post": {
        "tags": [
          "Subscriptions"
        ],
        "summary": "Create Subscription",
        "description": "Create a new recurring subscription for a customer.",
        "operationId": "createSubscription",
        "security": [
          {
            "SessionAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "customer_id",
                  "payment_method_id"
                ],
                "properties": {
                  "customer_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Customer ID"
                  },
                  "product_id": {
                    "type": "string",
                    "description": "Product ID (optional for custom subscriptions)"
                  },
                  "payment_method_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Payment method ID"
                  },
                  "provider_id": {
                    "type": "string",
                    "default": "stripe",
                    "description": "Payment provider ID"
                  },
                  "organization_id": {
                    "type": "string",
                    "description": "Organization ID (optional)"
                  },
                  "price_cents": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Custom price in cents (for custom subscriptions)"
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Currency code (for custom subscriptions)"
                  },
                  "billing_interval": {
                    "type": "string",
                    "enum": [
                      "monthly",
                      "yearly",
                      "weekly",
                      "daily"
                    ],
                    "default": "monthly",
                    "description": "Billing interval"
                  },
                  "interval_multiplier": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 12,
                    "default": 1,
                    "description": "Interval multiplier (e.g., 3 for every 3 months)"
                  },
                  "trial_days": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Trial period in days"
                  },
                  "custom_price_cents": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Custom price override (even for product-based subscriptions)"
                  },
                  "custom_trial_days": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Custom trial days override"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "guest_data": {
                    "type": "object",
                    "properties": {
                      "email": {
                        "type": "string",
                        "format": "email"
                      },
                      "name": {
                        "type": "string",
                        "minLength": 1
                      }
                    },
                    "required": [
                      "email",
                      "name"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription created successfully"
          }
        }
      }
    },
    "/bridge-payment/subscriptions/{id}": {
      "get": {
        "tags": [
          "Subscriptions"
        ],
        "summary": "Get Subscription by ID",
        "description": "Get detailed information about a specific subscription. include_pm is supported on GET /bridge-payment/subscriptions (list) only.",
        "operationId": "getSubscriptionById",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription details retrieved successfully"
          },
          "404": {
            "description": "Subscription not found"
          }
        }
      },
      "put": {
        "tags": [
          "Subscriptions"
        ],
        "summary": "Update Subscription",
        "description": "Update subscription details (payment method, metadata).",
        "operationId": "updateSubscription",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "payment_method_id": {
                    "type": "string",
                    "description": "Update payment method"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription updated successfully"
          }
        }
      }
    },
    "/bridge-payment/subscriptions/{id}/billing-address": {
      "patch": {
        "tags": ["Subscriptions"],
        "operationId": "patchSubscriptionBillingAddress",
        "summary": "Link or unlink billing address on subscription",
        "description": "Stores `billing_address_id` on the subscription for renewals and invoicing. Pass `null` to unlink. Provider sync is best-effort and non-fatal.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["billing_address_id"],
                "properties": {
                  "billing_address_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription billing address updated. Response may include provider sync status (for example, provider_synced)."
          },
          "403": {
            "description": "Access denied"
          },
          "404": {
            "description": "Subscription or address not found"
          }
        }
      }
    },
    "/bridge-payment/subscriptions/{id}/cancel": {
      "post": {
        "tags": [
          "Subscriptions"
        ],
        "summary": "Cancel Subscription",
        "description": "Cancel a subscription. Can be set to cancel at period end or immediately.",
        "operationId": "cancelSubscription",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "cancel_at_period_end": {
                    "type": "boolean",
                    "default": true,
                    "description": "Cancel at the end of the current billing period"
                  },
                  "reason": {
                    "type": "string",
                    "description": "Cancellation reason (optional)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription canceled successfully"
          }
        }
      }
    },
    "/bridge-payment/convert-guest": {
      "post": {
        "summary": "Convert Guest to Authenticated User",
        "description": "Convert your guest checkout data (customers and payment methods) to your authenticated user account. After creating an account, use this endpoint to link your previous guest purchases to your new account. You can selectively convert specific items or bulk convert all your guest data.",
        "operationId": "convertGuest",
        "tags": [
          "Guest Conversion"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "guest_email"
                ],
                "properties": {
                  "guest_email": {
                    "type": "string",
                    "format": "email",
                    "description": "Your email address used for guest checkout. Must match your authenticated account email."
                  },
                  "customer_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Optional: Specific customer IDs to convert. If not provided, all guest customers will be converted."
                  },
                  "payment_method_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Optional: Specific payment method IDs to convert. If not provided, all guest payment methods will be converted."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guest data converted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "customers_converted": {
                          "type": "integer"
                        },
                        "payment_methods_converted": {
                          "type": "integer"
                        },
                        "total_converted": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/preview-guest/{email}": {
      "get": {
        "summary": "Preview Guest Data",
        "description": "Preview guest checkout data before converting to authenticated user. Shows all customers and payment methods associated with the guest email.",
        "operationId": "previewGuest",
        "tags": [
          "Guest Conversion"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "email",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "email"
            },
            "description": "Guest email address to preview"
          }
        ],
        "responses": {
          "200": {
            "description": "Guest data preview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "customers": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "payment_methods": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "total_items": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/my-guest-data": {
      "get": {
        "summary": "List My Guest Data",
        "description": "List all guest checkout data for the current authenticated user's email. Useful for showing users what guest data they can convert.",
        "operationId": "listMyGuestData",
        "tags": [
          "Guest Conversion"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "User's guest data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "customers": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "payment_methods": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "total_items": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/health": {
      "get": {
        "summary": "Basic Health Check",
        "description": "Public endpoint for basic service health status. Returns service name, version, and uptime.",
        "operationId": "getHealth",
        "tags": [
          "Health"
        ],
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "example": "healthy"
                        },
                        "service": {
                          "type": "string",
                          "example": "bridge-payments"
                        },
                        "version": {
                          "type": "string"
                        },
                        "uptime": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/health/detailed": {
      "get": {
        "summary": "Detailed Health Check",
        "description": "Admin-only endpoint with detailed system metrics including database, providers, and cache statistics.",
        "operationId": "getDetailedHealth",
        "tags": [
          "Health"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Detailed health information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "database": {
                          "type": "object"
                        },
                        "providers": {
                          "type": "object"
                        },
                        "flowless": {
                          "type": "object"
                        },
                        "cache": {
                          "type": "object"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/health/database": {
      "get": {
        "summary": "Database Health Check",
        "description": "Check database connection and performance metrics.",
        "operationId": "getDatabaseHealth",
        "tags": [
          "Health"
        ],
        "responses": {
          "200": {
            "description": "Database health status"
          }
        }
      }
    },
    "/bridge-payment/health/providers": {
      "get": {
        "summary": "Payment Providers Health",
        "description": "Admin-only endpoint to check health of all configured payment providers (Stripe, PayPal, etc.).",
        "operationId": "getProvidersHealth",
        "tags": [
          "Health"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Payment providers health status"
          }
        }
      }
    },
    "/bridge-payment/health/flowless": {
      "get": {
        "summary": "Flowless Bridge Health",
        "description": "Admin-only endpoint to check Flowless authentication bridge connection and cache statistics.",
        "operationId": "getFlowlessHealth",
        "tags": [
          "Health"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Flowless bridge health status"
          }
        }
      }
    },
    "/bridge-payment/admin/products": {
      "get": {
        "summary": "List Products (Admin)",
        "description": "Admin endpoint to list all products with advanced filtering, search, and pagination. Supports filtering by category, type, recurring status, active status, and full-text search. Results can be ordered by multiple fields.\n\n**Pagination Methods** (choose one):\n- **Page-based**: Use `page` parameter (1-based). Example: `page=2&limit=10` returns products 11-20\n- **Offset-based**: Use `offset` parameter. Example: `offset=20&limit=10` skips first 20 products\n- If both are provided, `page` takes priority\n- Default: `limit=20`, `page=1` (or `offset=0`)\n\n**Example Requests**:\n- Page-based: `?page=2&limit=10&product_type=subscription&is_active=true`\n- Offset-based: `?offset=20&limit=10&search=premium&orderBy=name&orderDir=asc`",
        "operationId": "adminListProducts",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "description": "Page number for pagination (1-based). Alternative to offset. If provided, takes priority over offset."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            },
            "description": "Number of products to return per page (default: 20)"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of products to skip for pagination (default: 0). Alternative to page parameter."
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by category ID"
          },
          {
            "name": "product_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "physical",
                "digital",
                "service",
                "subscription"
              ]
            },
            "description": "Filter by product type"
          },
          {
            "name": "is_recurring",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "Filter by recurring status (string 'true' or 'false')"
          },
          {
            "name": "is_active",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "Filter by active status (string 'true' or 'false')"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search term to filter products by name or description"
          },
          {
            "name": "orderBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "name",
                "subtotal_cents",
                "created_at",
                "updated_at"
              ]
            },
            "description": "Field to sort results by (default: created_at)"
          },
          {
            "name": "orderDir",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            },
            "description": "Sort direction: 'asc' for ascending, 'desc' for descending (default: desc)"
          }
        ],
        "responses": {
          "200": {
            "description": "List of products with pagination metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "product_type": {
                            "type": "string",
                            "enum": [
                              "physical",
                              "digital",
                              "service",
                              "subscription"
                            ]
                          },
                          "is_recurring": {
                            "type": "boolean"
                          },
                          "subtotal_cents": {
                            "type": "integer"
                          },
                          "tax_cents": {
                            "type": "integer"
                          },
                          "discount_cents": {
                            "type": "integer"
                          },
                          "total_cents": {
                            "type": "integer"
                          },
                          "currency": {
                            "type": "string"
                          },
                          "billing_interval": {
                            "type": "string"
                          },
                          "trial_days": {
                            "type": "integer"
                          },
                          "category_id": {
                            "type": "string"
                          },
                          "is_active": {
                            "type": "boolean"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "description": "Total number of products matching the filters"
                        },
                        "limit": {
                          "type": "integer",
                          "description": "Number of products per page"
                        },
                        "offset": {
                          "type": "integer",
                          "description": "Number of products skipped"
                        },
                        "page": {
                          "type": "integer",
                          "description": "Current page number (1-based)"
                        },
                        "pages": {
                          "type": "integer",
                          "description": "Total number of pages"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "success": true,
                  "data": [
                    {
                      "id": "prod_123",
                      "name": "Premium Subscription",
                      "description": "Monthly premium access",
                      "product_type": "subscription",
                      "is_recurring": true,
                      "subtotal_cents": 1999,
                      "tax_cents": 0,
                      "discount_cents": 0,
                      "total_cents": 1999,
                      "currency": "USD",
                      "billing_interval": "monthly",
                      "trial_days": 7,
                      "is_active": true,
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-15T10:30:00Z"
                    }
                  ],
                  "pagination": {
                    "total": 45,
                    "limit": 20,
                    "offset": 0,
                    "page": 1,
                    "pages": 3
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create Product (Admin)",
        "description": "Admin endpoint to create a new product with intelligent pricing. You can provide either subtotal_cents or total_cents, and the system will calculate the missing fields automatically.",
        "operationId": "adminCreateProduct",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "product_type"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "description": {
                    "type": "string"
                  },
                  "product_type": {
                    "type": "string",
                    "enum": [
                      "physical",
                      "digital",
                      "service",
                      "subscription"
                    ]
                  },
                  "is_recurring": {
                    "type": "boolean",
                    "default": false
                  },
                  "subtotal_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Subtotal in cents (before tax and discount)"
                  },
                  "tax_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "discount_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "total_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Total in cents (after tax and discount)"
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "default": "USD"
                  },
                  "billing_interval": {
                    "type": "string",
                    "enum": [
                      "daily",
                      "weekly",
                      "monthly",
                      "yearly"
                    ]
                  },
                  "interval_count": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 12,
                    "default": 1
                  },
                  "trial_days": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "category": {
                    "type": "string"
                  },
                  "is_active": {
                    "type": "boolean",
                    "default": true
                  },
                  "metadata": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Product created successfully"
          }
        }
      }
    },
    "/bridge-payment/admin/products/{id}": {
      "get": {
        "summary": "Get Product by ID (Admin)",
        "description": "Admin endpoint to get detailed information about a specific product.",
        "operationId": "adminGetProduct",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Product details"
          }
        }
      },
      "put": {
        "summary": "Update Product (Admin)",
        "description": "Admin endpoint to update an existing product. Supports intelligent pricing updates.",
        "operationId": "adminUpdateProduct",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "subtotal_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "tax_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "discount_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "total_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "is_active": {
                    "type": "boolean"
                  },
                  "metadata": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Product updated successfully"
          }
        }
      },
      "delete": {
        "summary": "Delete Product (Admin)",
        "description": "Admin endpoint to delete a product. This will also remove it from payment providers if synced.",
        "operationId": "adminDeleteProduct",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Product deleted successfully"
          }
        }
      }
    },
    "/bridge-payment/admin/products/{id}/sync": {
      "post": {
        "summary": "Sync Product with Provider (Admin)",
        "description": "Admin endpoint to synchronize a product with a payment provider (e.g., Stripe or Polar). Creates or updates the product in the provider's system.",
        "operationId": "adminSyncProduct",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "default": "stripe",
                    "enum": [
                      "stripe",
                      "paypal",
                      "polar",
                      "authorize_net"
                    ],
                    "description": "Target provider for the sync operation"
                  },
                  "force": {
                    "type": "boolean",
                    "default": false,
                    "description": "Force sync even if already synced"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Product synced successfully"
          }
        }
      }
    },
    "/bridge-payment/admin/products/{id}/sync-status": {
      "get": {
        "summary": "Get Product Sync Status (Admin)",
        "description": "Admin endpoint to check the synchronization status of a product with payment providers.",
        "operationId": "adminGetProductSyncStatus",
        "tags": [
          "Admin - Products"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Product ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Product sync status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "synced": {
                          "type": "boolean"
                        },
                        "provider_product_id": {
                          "type": "string"
                        },
                        "last_synced": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/sync/all": {
      "post": {
        "summary": "Sync All Products with All Providers (Admin)",
        "description": "Admin endpoint to bulk synchronize all products with all configured payment providers (including Polar when enabled). Supports dry run mode and selective syncing.",
        "operationId": "adminSyncAll",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "default": "stripe",
                    "enum": [
                      "stripe",
                      "paypal",
                      "polar",
                      "authorize_net"
                    ],
                    "description": "Optional single provider filter; omit to process all configured providers"
                  },
                  "force": {
                    "type": "boolean",
                    "default": false,
                    "description": "Force sync even if already synced"
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false,
                    "description": "Preview changes without applying them"
                  },
                  "updatePrices": {
                    "type": "boolean",
                    "default": false,
                    "description": "Update prices in provider"
                  },
                  "product_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Specific products to sync (optional)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bulk sync completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "results": {
                          "type": "object"
                        },
                        "summary": {
                          "type": "object",
                          "properties": {
                            "total": {
                              "type": "integer"
                            },
                            "successful": {
                              "type": "integer"
                            },
                            "failed": {
                              "type": "integer"
                            },
                            "created": {
                              "type": "integer"
                            },
                            "updated": {
                              "type": "integer"
                            },
                            "skipped": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/sync/provider/{providerId}": {
      "post": {
        "summary": "Sync All Products with Specific Provider (Admin)",
        "description": "Admin endpoint to bulk synchronize all products with a specific payment provider (e.g., Stripe or Polar).",
        "operationId": "adminSyncProvider",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "stripe",
                "paypal",
                "polar",
                "authorize_net"
              ]
            },
            "description": "Payment provider ID"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "force": {
                    "type": "boolean",
                    "default": false
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false
                  },
                  "updatePrices": {
                    "type": "boolean",
                    "default": false
                  },
                  "product_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provider sync completed"
          }
        }
      }
    },
    "/bridge-payment/admin/sync/status": {
      "get": {
        "summary": "Get Overall Sync Status (Admin)",
        "description": "Admin endpoint to get the overall synchronization status across all payment providers.",
        "operationId": "adminGetSyncStatus",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Overall sync status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "providers": {
                          "type": "object"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/sync/migrate-prices": {
      "post": {
        "summary": "Migrate Product Prices (Admin)",
        "description": "Admin endpoint to migrate prices for existing products and subscriptions. Supports dry run mode to preview changes before applying.",
        "operationId": "adminMigratePrices",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "new_price_cents"
                ],
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "default": "stripe"
                  },
                  "product_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Specific products to migrate (optional)"
                  },
                  "old_price_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "new_price_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "effective_date": {
                    "type": "string",
                    "format": "date-time",
                    "description": "When to apply the new price"
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Price migration completed or preview"
          }
        }
      }
    },
    "/bridge-payment/admin/sync/products": {
      "post": {
        "summary": "Sync Specific Products (Admin)",
        "description": "Admin endpoint to synchronize specific products with a payment provider. Useful for selective syncing instead of bulk operations.",
        "operationId": "adminSyncProducts",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "product_ids"
                ],
                "properties": {
                  "product_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1
                  },
                  "provider_id": {
                    "type": "string",
                    "default": "stripe"
                  },
                  "force": {
                    "type": "boolean",
                    "default": false
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false
                  },
                  "updatePrices": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Products synced successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "successful": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        },
                        "results": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "summary": {
                          "type": "object",
                          "properties": {
                            "created": {
                              "type": "integer"
                            },
                            "updated": {
                              "type": "integer"
                            },
                            "skipped": {
                              "type": "integer"
                            },
                            "failed": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/sync/health": {
      "get": {
        "summary": "Sync System Health Check (Admin)",
        "description": "Admin endpoint to check the health of the synchronization system and all payment provider connections.",
        "operationId": "adminGetSyncHealth",
        "tags": [
          "Admin - Sync"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Sync system health status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "overall_status": {
                          "type": "string",
                          "enum": [
                            "healthy",
                            "degraded"
                          ]
                        },
                        "providers": {
                          "type": "object"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/subscriptions/analytics": {
      "get": {
        "summary": "Subscription Analytics (Admin)",
        "description": "Admin endpoint to get comprehensive subscription analytics including MRR, churn rate, growth metrics, and revenue trends. Supports filtering by date range, provider, status, and billing interval.",
        "operationId": "adminGetSubscriptionAnalytics",
        "tags": [
          "Admin - Subscriptions"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "start_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Start date for analytics period"
          },
          {
            "name": "end_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "End date for analytics period"
          },
          {
            "name": "provider_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by payment provider"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by subscription status"
          },
          {
            "name": "billing_interval",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "daily",
                "weekly",
                "monthly",
                "yearly"
              ]
            },
            "description": "Filter by billing interval"
          },
          {
            "name": "group_by",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "day",
                "week",
                "month",
                "year"
              ],
              "default": "month"
            },
            "description": "Group analytics by time period"
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "summary": {
                          "type": "object",
                          "properties": {
                            "total_subscriptions": {
                              "type": "integer"
                            },
                            "active_subscriptions": {
                              "type": "integer"
                            },
                            "trial_subscriptions": {
                              "type": "integer"
                            },
                            "canceled_subscriptions": {
                              "type": "integer"
                            },
                            "total_mrr": {
                              "type": "number",
                              "description": "Monthly Recurring Revenue"
                            },
                            "average_subscription_value": {
                              "type": "number"
                            },
                            "churn_rate": {
                              "type": "number"
                            }
                          }
                        },
                        "by_interval": {
                          "type": "object"
                        },
                        "by_status": {
                          "type": "object"
                        },
                        "growth": {
                          "type": "object"
                        },
                        "top_products": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "revenue_trend": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/subscriptions/bulk-update": {
      "post": {
        "summary": "Bulk Update Subscriptions (Admin)",
        "description": "Admin endpoint to update multiple subscriptions at once. Supports updating metadata, cancellation settings, and trial periods. Can optionally sync changes with payment providers.",
        "operationId": "adminBulkUpdateSubscriptions",
        "tags": [
          "Admin - Subscriptions"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "subscription_ids",
                  "updates"
                ],
                "properties": {
                  "subscription_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1
                  },
                  "updates": {
                    "type": "object",
                    "properties": {
                      "metadata": {
                        "type": "object"
                      },
                      "cancel_at_period_end": {
                        "type": "boolean"
                      },
                      "trial_end": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  },
                  "provider_sync": {
                    "type": "boolean",
                    "default": true,
                    "description": "Sync changes with payment provider"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bulk update completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "successful": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        },
                        "results": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/subscriptions/migrate-prices": {
      "post": {
        "summary": "Migrate Subscription Prices (Admin)",
        "description": "Admin endpoint to migrate subscription prices. This is a complex operation that creates new prices in the payment provider and updates subscriptions. Supports dry run mode to preview changes.",
        "operationId": "adminMigrateSubscriptionPrices",
        "tags": [
          "Admin - Subscriptions"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "new_pricing"
                ],
                "properties": {
                  "subscription_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Specific subscriptions to migrate (optional)"
                  },
                  "old_pricing": {
                    "type": "object",
                    "properties": {
                      "subtotal_cents": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "tax_cents": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "discount_cents": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "total_cents": {
                        "type": "integer",
                        "minimum": 0
                      }
                    }
                  },
                  "new_pricing": {
                    "type": "object",
                    "required": [
                      "subtotal_cents",
                      "total_cents"
                    ],
                    "properties": {
                      "subtotal_cents": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "tax_cents": {
                        "type": "integer",
                        "minimum": 0,
                        "default": 0
                      },
                      "discount_cents": {
                        "type": "integer",
                        "minimum": 0,
                        "default": 0
                      },
                      "total_cents": {
                        "type": "integer",
                        "minimum": 0
                      }
                    }
                  },
                  "effective_date": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "provider_id": {
                    "type": "string",
                    "default": "stripe"
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Price migration completed or preview"
          }
        }
      }
    },
    "/bridge-payment/admin/subscriptions/health": {
      "get": {
        "summary": "Subscription System Health (Admin)",
        "description": "Admin endpoint to check the health of the subscription system including database, payment providers, subscription processing, and webhooks.",
        "operationId": "adminGetSubscriptionHealth",
        "tags": [
          "Admin - Subscriptions"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription system health status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "overall_status": {
                          "type": "string",
                          "enum": [
                            "healthy",
                            "degraded"
                          ]
                        },
                        "components": {
                          "type": "object",
                          "properties": {
                            "database": {
                              "type": "object"
                            },
                            "providers": {
                              "type": "object"
                            },
                            "subscription_processing": {
                              "type": "object"
                            },
                            "webhooks": {
                              "type": "object"
                            }
                          }
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/subscriptions/reports": {
      "get": {
        "summary": "Generate Subscription Reports (Admin)",
        "description": "Admin endpoint to generate various subscription reports including summary, revenue, and churn analysis.",
        "operationId": "adminGetSubscriptionReports",
        "tags": [
          "Admin - Subscriptions"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "summary",
                "revenue",
                "churn"
              ],
              "default": "summary"
            },
            "description": "Type of report to generate"
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription report",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "report": {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string"
                            },
                            "description": {
                              "type": "string"
                            },
                            "data": {
                              "type": "object"
                            }
                          }
                        },
                        "generated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/status": {
      "get": {
        "summary": "Get Renewal System Status (Admin)",
        "description": "Admin endpoint to get the current status of the automated renewal system including cron job status, processing statistics, and configuration.",
        "operationId": "adminGetRenewalStatus",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Renewal system status"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/trigger": {
      "post": {
        "summary": "Manually Trigger Renewal Processing (Admin)",
        "description": "Admin endpoint to manually trigger the renewal processing job. Useful for testing or forcing immediate processing.",
        "operationId": "adminTriggerRenewal",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Renewal processing triggered"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/pause": {
      "post": {
        "summary": "Pause Renewal Processing (Admin)",
        "description": "Admin endpoint to pause the automated renewal processing. Useful during maintenance or system updates.",
        "operationId": "adminPauseRenewal",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Renewal processing paused"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/resume": {
      "post": {
        "summary": "Resume Renewal Processing (Admin)",
        "description": "Admin endpoint to resume the automated renewal processing after it has been paused.",
        "operationId": "adminResumeRenewal",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Renewal processing resumed"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/pause-retries": {
      "post": {
        "summary": "Pause Retry Processing (Admin)",
        "description": "Admin endpoint to pause the automated retry processing for failed renewals.",
        "operationId": "adminPauseRetries",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Retry processing paused"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/resume-retries": {
      "post": {
        "summary": "Resume Retry Processing (Admin)",
        "description": "Admin endpoint to resume the automated retry processing for failed renewals.",
        "operationId": "adminResumeRetries",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Retry processing resumed"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/due": {
      "get": {
        "summary": "Get Subscriptions Due for Renewal (Admin)",
        "description": "Admin endpoint to get a list of subscriptions that are due for renewal. Useful for monitoring and troubleshooting.",
        "operationId": "adminGetDueRenewals",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            },
            "description": "Maximum number of results"
          }
        ],
        "responses": {
          "200": {
            "description": "List of subscriptions due for renewal"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/retries": {
      "get": {
        "summary": "Get Subscriptions in Retry Queue (Admin)",
        "description": "Admin endpoint to get a list of subscriptions in the retry queue after failed renewal attempts.",
        "operationId": "adminGetRetryQueue",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            },
            "description": "Maximum number of results"
          }
        ],
        "responses": {
          "200": {
            "description": "List of subscriptions in retry queue"
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/billing-configs": {
      "get": {
        "summary": "Get Billing Configurations (Admin)",
        "description": "Admin endpoint to get all billing configurations for the renewal system including retry settings and notification preferences.",
        "operationId": "adminGetBillingConfigs",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Billing configurations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "retry_attempts": {
                          "type": "integer"
                        },
                        "retry_intervals": {
                          "type": "array",
                          "items": {
                            "type": "integer"
                          }
                        },
                        "notification_settings": {
                          "type": "object"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/renewals/health": {
      "get": {
        "summary": "Renewal System Health Check (Admin)",
        "description": "Admin endpoint to check the health of the renewal system including cron jobs, database, and payment provider connections.",
        "operationId": "adminGetRenewalHealth",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Renewal system health status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "overall_status": {
                          "type": "string",
                          "enum": [
                            "healthy",
                            "degraded"
                          ]
                        },
                        "cron_jobs": {
                          "type": "object"
                        },
                        "database": {
                          "type": "object"
                        },
                        "providers": {
                          "type": "object"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin": {
      "get": {
        "summary": "Admin Dashboard Overview (Admin)",
        "description": "Admin endpoint that provides an overview of all available admin features and endpoints. Useful as a starting point for admin operations.",
        "operationId": "adminGetDashboard",
        "tags": [
          "Admin - Renewals"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Admin dashboard overview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "available_endpoints": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "features": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/status": {
      "get": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Get Module Hub bootstrap status (Admin)",
        "description": "Checks whether Module Hub tables exist in the database (`module_hub_registry`, `module_hub_events`).\n\n**Success envelope:** `{ data, user_context, meta }`.\n- When ready: `data.installed: true` and `data.tables` lists table names.\n- When missing: `data.installed: false` and `data.missing` lists required tables.\n\nRequires admin privileges (same as other `/bridge-payment/admin/*` routes).",
        "operationId": "adminGetModuleHubStatus",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Hub table status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Standard Module Hub JSON envelope",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "installed": {
                          "type": "boolean"
                        },
                        "tables": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "missing": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "user_context": {
                      "type": "object"
                    },
                    "meta": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/dry-run": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Dry-run Module Hub bootstrap (Admin)",
        "description": "Preview DDL plan to create Module Hub tables (and optional indexes) without executing.\n\n**Request body (optional):**\n- `include_indexes` (boolean, default `true`) — include index operations in the returned plan.\n\n**Success envelope:** `{ data, user_context, meta }` with `data.dry_run: true`, `data.module_hub_tables`, and `data.operations` (planned steps).",
        "operationId": "adminModuleHubBootstrapDryRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "include_indexes": {
                    "type": "boolean",
                    "default": true,
                    "description": "Include index creation in the bootstrap plan"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dry-run plan returned"
          },
          "400": {
            "description": "Invalid JSON or validation error (`code: VALIDATION_ERROR`, optional `fields`)"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/run": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Run Module Hub bootstrap (Admin)",
        "description": "Creates Module Hub tables (`module_hub_registry`, `module_hub_events`) and optional indexes.\n\n**Request body (optional):** same as dry-run — `include_indexes` (boolean, default `true`).\n\n**Success envelope:** `{ data, user_context, meta }` with `data.installed: true`, `data.tables`, `data.duration_ms`, and `data.include_indexes`.",
        "operationId": "adminModuleHubBootstrapRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "include_indexes": {
                    "type": "boolean",
                    "default": true,
                    "description": "Create indexes after tables"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bootstrap completed"
          },
          "400": {
            "description": "Invalid JSON or validation error"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "500": {
            "description": "Install failed (`code: INSTALL_FAILED`)"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins": {
      "get": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "List discoverable modules (Admin)",
        "description": "Scans `modules/*/manifest.json` and legacy `database/plugins/*/plugin.json`, resolves manifests, and returns each module’s metadata plus how many components are registered in `module_hub_registry` for the current database.\n\n**Success envelope:** `{ data, user_context, meta }`.\n- `data` is an array of `{ module_id, module_version, module_depends_on, components, installed_components }`.\n- `meta` includes pagination-style fields (`page`, `limit`, `total`, `hasMore`, etc.) aligned with other list endpoints.",
        "operationId": "adminListModuleHubModules",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Module list"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "500": {
            "description": "Failed to list modules (`code: INSTALL_FAILED`)"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/status": {
      "get": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Get module install status (Admin)",
        "description": "Returns manifest version, per-component install state, derived module status, and latest failure event (if any) for a module within a `runtime_scope`.\n\n**Query parameters:**\n- `runtime_scope` (optional, default `flowless-core`) — scope key for registry/events partitioning.\n\n**Path:** `module_id` must match `^[a-z0-9][a-z0-9-]*$`.\n\n**Success envelope:** `{ data, user_context, meta }` with `data.module_id`, `data.runtime_scope`, `data.module_version`, `data.status`, `data.components`, `data.latest_failure`.",
        "operationId": "adminGetModuleHubModuleStatus",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "description": "Module identifier (from manifest / directory name)",
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          },
          {
            "name": "runtime_scope",
            "in": "query",
            "required": false,
            "description": "Registry scope (default: flowless-core)",
            "schema": {
              "type": "string",
              "default": "flowless-core"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Module status"
          },
          "400": {
            "description": "Invalid module_id or runtime_scope"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "404": {
            "description": "Module not found (`code: MODULE_NOT_FOUND`)"
          },
          "500": {
            "description": "Failed to load status (`code: INSTALL_FAILED`)"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/registry": {
      "get": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Get module registry rows and recent events (Admin)",
        "description": "Returns all `module_hub_registry` rows for the module and the most recent `module_hub_events` rows (newest first).\n\n**Query parameters:**\n- `runtime_scope` (optional, default `flowless-core`)\n- `limit` (optional, default 50, max 200) — max events to return\n\n**Success envelope:** `{ data, user_context, meta }` with `data.registry`, `data.events`, and `meta` pagination hints.",
        "operationId": "adminGetModuleHubModuleRegistry",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          },
          {
            "name": "runtime_scope",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "default": "flowless-core"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum events to return (1–200)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Registry and events"
          },
          "400": {
            "description": "Invalid module_id or runtime_scope"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "500": {
            "description": "Failed to read registry (`code: INSTALL_FAILED`)"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/dry-run": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Dry-run module install or upgrade plan (Admin)",
        "description": "Computes ordered component plan (install / upgrade / repair / skip / drift) from the manifest and current registry, without executing SQL.\n\n**Request body (JSON, optional fields with defaults):**\n- `target`: `core` | `selected` | `all` (default `core`)\n- `components`: string[] — component ids when `target` is `selected`\n- `runtime_scope`: string (default `flowless-core`)\n- `skip_existing`: boolean (default `true`)\n- `repair_missing`: boolean (default `false`) — when true, checksum drift can be reconciled as `repair`\n- `verify_checksum`: boolean (default `true`)\n- `verbose`: boolean (default `false`)\n\n**Success:** `{ data, user_context, meta }` with `data.dry_run: true`, `data.plan`, `data.resolved_order`, `data.sql_preview`, etc.\n\n**Errors:** `409` with `code: MODULE_DEPENDENCY_ERROR` if a dependency module is not installed in the scope.",
        "operationId": "adminModuleHubInstallDryRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "target": {
                    "type": "string",
                    "enum": [
                      "core",
                      "selected",
                      "all"
                    ],
                    "default": "core",
                    "description": "Which manifest components to include in the plan"
                  },
                  "components": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Component ids when target is selected"
                  },
                  "runtime_scope": {
                    "type": "string",
                    "default": "flowless-core"
                  },
                  "skip_existing": {
                    "type": "boolean",
                    "default": true
                  },
                  "repair_missing": {
                    "type": "boolean",
                    "default": false
                  },
                  "verify_checksum": {
                    "type": "boolean",
                    "default": true
                  },
                  "verbose": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dry-run plan"
          },
          "400": {
            "description": "Invalid body or validation error"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "404": {
            "description": "Module not found"
          },
          "409": {
            "description": "Dependency missing, install locked, or dependency error"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/run": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Run module install or upgrade (Admin)",
        "description": "Executes SQL for each planned component, updates `module_hub_registry`, and appends `module_hub_events`. Same request body as dry-run.\n\n**Success:** `{ data, user_context, meta }` with `data.result` containing `installed`, `upgraded`, `repaired`, `skipped`, `failed`, `duration_ms`, plus `run_id`.\n- HTTP **200** when all operations succeed.\n- HTTP **207** when some components failed but others succeeded (partial result).\n\n**409:** `INSTALL_LOCKED` if a concurrent install lock is held.\n**409:** `MODULE_DEPENDENCY_ERROR` with `missing` array when dependencies are absent.",
        "operationId": "adminModuleHubInstallRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "target": {
                    "type": "string",
                    "enum": [
                      "core",
                      "selected",
                      "all"
                    ],
                    "default": "core"
                  },
                  "components": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "runtime_scope": {
                    "type": "string",
                    "default": "flowless-core"
                  },
                  "skip_existing": {
                    "type": "boolean",
                    "default": true
                  },
                  "repair_missing": {
                    "type": "boolean",
                    "default": false
                  },
                  "verify_checksum": {
                    "type": "boolean",
                    "default": true
                  },
                  "verbose": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Install completed with no failures"
          },
          "207": {
            "description": "Multi-status — some components failed (see data.result.failed)"
          },
          "400": {
            "description": "Invalid body or validation error"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "404": {
            "description": "Module not found"
          },
          "409": {
            "description": "Locked or dependency error"
          },
          "500": {
            "description": "Install failed"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/update/dry-run": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Dry-run module component updates (Admin)",
        "description": "Builds an update plan from manifest vs registry (non-core components with newer version or checksum drift), then reuses install dry-run semantics.\n\n**Request body (optional):**\n- `components`: string[] — limit to these component ids; if omitted, all non-core components eligible for update are considered\n- `runtime_scope` (default `flowless-core`)\n- `verify_checksum` (default `true`)\n- `verbose` (default `false`)",
        "operationId": "adminModuleHubUpdateDryRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "components": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "runtime_scope": {
                    "type": "string",
                    "default": "flowless-core"
                  },
                  "verify_checksum": {
                    "type": "boolean",
                    "default": true
                  },
                  "verbose": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Dry-run plan"
          },
          "400": {
            "description": "Invalid body"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "404": {
            "description": "Module not found"
          }
        }
      }
    },
    "/bridge-payment/admin/plugins/{module_id}/update": {
      "post": {
        "tags": [
          "Admin - Module Hub"
        ],
        "summary": "Run module component updates (Admin)",
        "description": "Applies the update plan (same body as update dry-run). Internally delegates to install/run with `repair_missing: true` for eligible components.\n\n**Responses:** Same semantics as `POST .../{module_id}/run` (200, 207, 4xx/5xx).",
        "operationId": "adminModuleHubUpdateRun",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "module_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]*$"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "components": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "runtime_scope": {
                    "type": "string",
                    "default": "flowless-core"
                  },
                  "verify_checksum": {
                    "type": "boolean",
                    "default": true
                  },
                  "verbose": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Update completed with no failures"
          },
          "207": {
            "description": "Partial failures"
          },
          "400": {
            "description": "Invalid body"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Admin access required"
          },
          "404": {
            "description": "Module not found"
          },
          "409": {
            "description": "Dependency or lock error"
          },
          "500": {
            "description": "Update failed"
          }
        }
      }
    },
    "/bridge-payment/organizations": {
      "get": {
        "summary": "List Organizations",
        "description": "Get all organizations where the authenticated user is a member. Returns organization details along with the user's role in each organization. Supports pagination for large organization lists.",
        "operationId": "listOrganizations",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "Page number for pagination",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page (max 100)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of organizations retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "org_abc123"
                          },
                          "name": {
                            "type": "string",
                            "example": "Acme Corporation"
                          },
                          "business_email": {
                            "type": "string",
                            "format": "email",
                            "example": "billing@acme.com"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "role": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "admin",
                              "billing",
                              "member"
                            ],
                            "example": "owner"
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "pagination": {
                          "type": "object",
                          "properties": {
                            "total": {
                              "type": "integer"
                            },
                            "page": {
                              "type": "integer"
                            },
                            "pageSize": {
                              "type": "integer"
                            },
                            "totalPages": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "summary": "Create Organization",
        "description": "Create a new organization. The authenticated user automatically becomes the owner. Guest users cannot create organizations. All fields except name are optional.",
        "operationId": "createOrganization",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Organization name (required)",
                    "example": "Acme Corporation"
                  },
                  "business_email": {
                    "type": "string",
                    "format": "email",
                    "description": "Business email address (optional)",
                    "example": "billing@acme.com"
                  },
                  "business_phone": {
                    "type": "string",
                    "maxLength": 50,
                    "description": "Business phone number (optional)",
                    "example": "+1-555-0123"
                  },
                  "tax_id": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Tax ID or EIN (optional)",
                    "example": "12-3456789"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Business address (optional)",
                    "example": "123 Main St, San Francisco, CA 94105"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "org_abc123"
                        },
                        "name": {
                          "type": "string",
                          "example": "Acme Corporation"
                        },
                        "owner_user_id": {
                          "type": "string",
                          "example": "user_xyz789"
                        },
                        "business_email": {
                          "type": "string",
                          "example": "billing@acme.com"
                        },
                        "business_phone": {
                          "type": "string",
                          "example": "+1-555-0123"
                        },
                        "tax_id": {
                          "type": "string",
                          "example": "12-3456789"
                        },
                        "address": {
                          "type": "string",
                          "example": "123 Main St, San Francisco, CA 94105"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Guest users cannot create organizations"
          }
        }
      }
    },
    "/bridge-payment/organizations/{id}": {
      "get": {
        "summary": "Get Organization",
        "description": "Get detailed information about a specific organization. User must be a member of the organization to access it. Returns 403 if not a member to prevent organization enumeration.",
        "operationId": "getOrganization",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Organization details retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "org_abc123"
                        },
                        "name": {
                          "type": "string",
                          "example": "Acme Corporation"
                        },
                        "owner_user_id": {
                          "type": "string",
                          "example": "user_xyz789"
                        },
                        "business_email": {
                          "type": "string",
                          "example": "billing@acme.com"
                        },
                        "business_phone": {
                          "type": "string",
                          "example": "+1-555-0123"
                        },
                        "tax_id": {
                          "type": "string",
                          "example": "12-3456789"
                        },
                        "address": {
                          "type": "string",
                          "example": "123 Main St, San Francisco, CA 94105"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "your_role": {
                          "type": "string",
                          "enum": [
                            "owner",
                            "admin",
                            "billing",
                            "member"
                          ],
                          "example": "owner"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied - not a member of this organization"
          }
        }
      },
      "put": {
        "summary": "Update Organization",
        "description": "Update organization details. Only the organization owner can update. All fields are optional - only provided fields will be updated.",
        "operationId": "updateOrganization",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Organization name",
                    "example": "Acme Corporation Ltd"
                  },
                  "business_email": {
                    "type": "string",
                    "format": "email",
                    "description": "Business email address",
                    "example": "accounting@acme.com"
                  },
                  "business_phone": {
                    "type": "string",
                    "maxLength": 50,
                    "description": "Business phone number",
                    "example": "+1-555-0199"
                  },
                  "tax_id": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Tax ID or EIN",
                    "example": "12-3456789"
                  },
                  "address": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Business address",
                    "example": "456 Market St, San Francisco, CA 94105"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Organization updated successfully"
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Only the organization owner can perform this action"
          }
        }
      },
      "delete": {
        "summary": "Delete Organization",
        "description": "Delete an organization permanently. Only the organization owner can delete. This will CASCADE delete all organization members and related resources. This action cannot be undone.",
        "operationId": "deleteOrganization",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Organization deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Organization deleted successfully"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Only the organization owner can perform this action"
          }
        }
      }
    },
    "/bridge-payment/organizations/{id}/members": {
      "get": {
        "summary": "List Organization Members",
        "description": "Get all members of an organization with their user details and roles. User must be a member of the organization to access this endpoint. Supports pagination and role filtering.",
        "operationId": "listOrganizationMembers",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number for pagination",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page (max 100)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "role",
            "in": "query",
            "description": "Filter by role",
            "schema": {
              "type": "string",
              "enum": [
                "owner",
                "admin",
                "billing",
                "member"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of members retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "orguser_123"
                          },
                          "user_id": {
                            "type": "string",
                            "example": "user_xyz789"
                          },
                          "role": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "admin",
                              "billing",
                              "member"
                            ],
                            "example": "owner"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "user_name": {
                            "type": "string",
                            "example": "John"
                          },
                          "user_last_name": {
                            "type": "string",
                            "example": "Doe"
                          },
                          "user_email": {
                            "type": "string",
                            "format": "email",
                            "example": "john@acme.com"
                          },
                          "user_picture": {
                            "type": "string",
                            "format": "uri",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "pagination": {
                          "type": "object",
                          "properties": {
                            "total": {
                              "type": "integer"
                            },
                            "page": {
                              "type": "integer"
                            },
                            "pageSize": {
                              "type": "integer"
                            },
                            "totalPages": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Access denied - not a member of this organization"
          }
        }
      },
      "post": {
        "summary": "Add Organization Member",
        "description": "Add a new member to the organization. Only the organization owner can add members. The user must exist in the system (identified by email) and will be automatically added if found. Cannot add users as 'owner' role.",
        "operationId": "addOrganizationMember",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "role"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Email of the user to add (must exist in the system)",
                    "example": "newmember@acme.com"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "billing",
                      "member"
                    ],
                    "description": "Role to assign (cannot be 'owner')",
                    "example": "billing"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Member added successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "orguser_789"
                        },
                        "organization_id": {
                          "type": "string",
                          "example": "org_abc123"
                        },
                        "user_id": {
                          "type": "string",
                          "example": "user_new123"
                        },
                        "role": {
                          "type": "string",
                          "example": "billing"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "message": {
                      "type": "string",
                      "example": "Member added successfully"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or user already a member"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Only the organization owner can perform this action"
          },
          "404": {
            "description": "User not found with this email"
          }
        }
      }
    },
    "/bridge-payment/organizations/{id}/members/{memberId}": {
      "put": {
        "summary": "Update Member Role",
        "description": "Update a member's role in the organization. Only the organization owner can update roles. Cannot change the owner's role or your own role. Role must be admin, billing, or member.",
        "operationId": "updateOrganizationMemberRole",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          },
          {
            "name": "memberId",
            "in": "path",
            "required": true,
            "description": "Member ID (organization_users.id)",
            "schema": {
              "type": "string",
              "example": "orguser_789"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "billing",
                      "member"
                    ],
                    "description": "New role to assign (cannot be 'owner')",
                    "example": "admin"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Member role updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "orguser_789"
                        },
                        "organization_id": {
                          "type": "string",
                          "example": "org_abc123"
                        },
                        "user_id": {
                          "type": "string",
                          "example": "user_new123"
                        },
                        "role": {
                          "type": "string",
                          "example": "admin"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "message": {
                      "type": "string",
                      "example": "Member role updated successfully"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid role"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Only the organization owner can perform this action, or cannot change owner role, or cannot change your own role"
          },
          "404": {
            "description": "Member not found"
          }
        }
      },
      "delete": {
        "summary": "Remove Organization Member",
        "description": "Remove a member from the organization. Only the organization owner can remove members. Cannot remove the owner or yourself (use leave endpoint instead).",
        "operationId": "removeOrganizationMember",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          },
          {
            "name": "memberId",
            "in": "path",
            "required": true,
            "description": "Member ID (organization_users.id)",
            "schema": {
              "type": "string",
              "example": "orguser_789"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Member removed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Member removed successfully"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Only the organization owner can perform this action, or cannot remove owner, or cannot remove yourself"
          },
          "404": {
            "description": "Member not found"
          }
        }
      }
    },
    "/bridge-payment/organizations/{id}/leave": {
      "post": {
        "summary": "Leave Organization",
        "description": "Leave an organization. Any member except the owner can leave. The owner must delete the organization instead of leaving it.",
        "operationId": "leaveOrganization",
        "tags": [
          "Organizations"
        ],
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Organization ID",
            "schema": {
              "type": "string",
              "example": "org_abc123"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully left the organization",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "You have left the organization successfully"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner cannot leave organization - delete the organization instead"
          },
          "404": {
            "description": "You are not a member of this organization"
          }
        }
      }
    },
    "/pages/me": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesMe",
        "summary": "Get current user (Flowless proxy)",
        "description": "Requires `PAGES_ENABLED`. Server-side proxy to Flowless (`/auth/me` or `/api/auth/validation`). Send `X-Session-ID`. Returns JSON (not HTML).",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Normalized user payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing session or unauthorized"
          },
          "503": {
            "description": "Auth service unavailable"
          }
        }
      }
    },
    "/pages/pay": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesPay",
        "summary": "Payment checkout page",
        "description": "Requires `PAGES_ENABLED`. Checkout UI; optional query: `amount`, `currency`, `concept`, `product_id`, `provider`, `customer_id`, `return_url`, `metadata` (JSON string).",
        "security": [],
        "responses": {
          "200": {
            "description": "Checkout HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/pages/login": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesLogin",
        "summary": "Session login page",
        "description": "Requires `PAGES_ENABLED`. Optional `redirect` query (default `/pages/portal`).",
        "security": [],
        "responses": {
          "200": {
            "description": "Login HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "postPagesLogin",
        "summary": "Email/password login (Flowless proxy)",
        "description": "Requires `PAGES_ENABLED`. Proxies to Flowless login; returns JSON with `session_id` and optional `user`.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Validation error"
          },
          "502": {
            "description": "Provider did not return session"
          },
          "503": {
            "description": "Auth service unavailable"
          }
        }
      }
    },
    "/pages/portal": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesPortal",
        "summary": "Customer portal (tabs)",
        "description": "Requires `PAGES_ENABLED`. Full portal HTML; client uses session cookie/query. May show org/project scope when organizations or projects are enabled.",
        "security": [],
        "responses": {
          "200": {
            "description": "Portal HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/pages/subscriptions": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesSubscriptions",
        "summary": "Subscriptions manager page",
        "description": "Requires `PAGES_ENABLED`. Standalone subscriptions HTML.",
        "security": [],
        "responses": {
          "200": {
            "description": "Subscriptions HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/pages/payment-methods": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesPaymentMethods",
        "summary": "Payment methods page",
        "description": "Requires `PAGES_ENABLED`. Standalone payment methods HTML.",
        "security": [],
        "responses": {
          "200": {
            "description": "Payment methods HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/pages/addresses": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesAddresses",
        "summary": "Addresses page",
        "description": "Requires `PAGES_ENABLED`. Standalone addresses HTML.",
        "security": [],
        "responses": {
          "200": {
            "description": "Addresses HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/pages/invoices": {
      "get": {
        "tags": [
          "Bridge Pages"
        ],
        "operationId": "getPagesInvoices",
        "summary": "Billing history page",
        "description": "Requires `PAGES_ENABLED`. Lists payments from `/bridge-payment/payments` in HTML (not invoice API).",
        "security": [],
        "responses": {
          "200": {
            "description": "Billing history HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/pay": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedPay",
        "summary": "Embed payment widget",
        "description": "Requires `EMBED_ENABLED`. Compact checkout; optional `organization_id` / `org_id` / `project_id`; styling via `bg`, `bg_dark`.",
        "security": [],
        "responses": {
          "200": {
            "description": "Embed pay HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/login": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedLogin",
        "summary": "Embed session login",
        "description": "Requires `EMBED_ENABLED`. Optional `redirect` query. Posts parent `postMessage` on success.",
        "security": [],
        "responses": {
          "200": {
            "description": "Embed login HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/portal": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedPortal",
        "summary": "Embed portal widget",
        "description": "Requires `EMBED_ENABLED`. Compact portal with subscriptions, payment methods, addresses tabs.",
        "security": [],
        "responses": {
          "200": {
            "description": "Embed portal HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/subscriptions": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedSubscriptions",
        "summary": "Embed subscriptions list",
        "description": "Requires `EMBED_ENABLED`. Query `manage=false` to hide cancel actions. Supports org/project scope query params.",
        "security": [],
        "responses": {
          "200": {
            "description": "Embed subscriptions HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/payment-methods": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedPaymentMethods",
        "summary": "Embed payment methods widget",
        "description": "Requires `EMBED_ENABLED`.",
        "security": [],
        "responses": {
          "200": {
            "description": "Embed payment methods HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/button": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedButton",
        "summary": "Embed pay button",
        "description": "Requires `EMBED_ENABLED`. Minimal widget; query `amount` (cents), `currency`, `concept`, `provider`, `label`.",
        "security": [],
        "responses": {
          "200": {
            "description": "Pay button HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/embed/payments": {
      "get": {
        "tags": [
          "Bridge Embeds"
        ],
        "operationId": "getEmbedPayments",
        "summary": "Embed payments history widget",
        "description": "Requires `EMBED_ENABLED`. Paginated payment list UI.",
        "security": [],
        "responses": {
          "200": {
            "description": "Payments list HTML",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string",
                  "description": "Full HTML document from Bridge UI"
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/projects/invites/{token}": {
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "getProjectInviteByToken",
        "summary": "Look up project invite (public)",
        "description": "Requires `PROJECTS_ENABLED`. Rate-limited public lookup. Returns limited invitation metadata.",
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invitation summary"
          },
          "404": {
            "description": "Invitation not found or expired"
          }
        }
      }
    },
    "/bridge-payment/projects": {
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "listProjects",
        "summary": "List projects for current user",
        "description": "Requires `PROJECTS_ENABLED` and session.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Projects list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Projects"
        ],
        "operationId": "createProject",
        "summary": "Create project",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "organization_id": {
                    "type": "string"
                  },
                  "billing_account_id": {
                    "type": "string"
                  },
                  "settings": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Validation error"
          },
          "403": {
            "description": "Organization access denied"
          }
        }
      }
    },
    "/bridge-payment/projects/{id}": {
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "getProjectById",
        "summary": "Get project",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Project with role hints"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/projects/{id}/invites": {
      "post": {
        "tags": [
          "Projects"
        ],
        "operationId": "createProjectInvite",
        "summary": "Invite project member",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "editor",
                      "viewer",
                      "member"
                    ],
                    "default": "member"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invitation created"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    },
    "/bridge-payment/projects/invites/{token}/accept": {
      "post": {
        "tags": [
          "Projects"
        ],
        "operationId": "acceptProjectInvite",
        "summary": "Accept project invite",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Member record",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/projects/{id}/members": {
      "get": {
        "tags": [
          "Projects"
        ],
        "operationId": "listProjectMembers",
        "summary": "List project members",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Members",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/projects/{id}/members/{userId}": {
      "patch": {
        "tags": [
          "Projects"
        ],
        "operationId": "updateProjectMemberRole",
        "summary": "Update project member role",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "admin",
                      "editor",
                      "viewer",
                      "member"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "400": {
            "description": "Cannot demote last owner"
          }
        }
      },
      "delete": {
        "tags": [
          "Projects"
        ],
        "operationId": "removeProjectMember",
        "summary": "Remove project member",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Removal confirmation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/tiers": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "listMembershipTiers",
        "summary": "List active membership tiers",
        "security": [],
        "responses": {
          "200": {
            "description": "Tier list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/tiers/{id}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "getMembershipTierById",
        "summary": "Get membership tier",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tier"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/memberships/users/me": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "listMyMemberships",
        "summary": "List current user's memberships",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/users/me/{id}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "getMyMembershipById",
        "summary": "Get current user's membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Membership"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/memberships/users/me/{id}/cancel": {
      "post": {
        "tags": [
          "Memberships"
        ],
        "operationId": "cancelMyMembership",
        "summary": "Cancel current user membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "too_expensive",
                      "not_using",
                      "switching_provider",
                      "missing_features",
                      "technical_issues",
                      "temporary_pause",
                      "duplicate_subscription",
                      "other"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled membership",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/users/{userId}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "listMembershipsForUser",
        "summary": "List memberships for user (ownership enforced)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/users/{userId}/{id}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "getMembershipForUser",
        "summary": "Get membership for user",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Membership"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/memberships/users/{userId}/{id}/cancel": {
      "post": {
        "tags": [
          "Memberships"
        ],
        "operationId": "cancelMembershipForUser",
        "summary": "Cancel membership for user",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "too_expensive",
                      "not_using",
                      "switching_provider",
                      "missing_features",
                      "technical_issues",
                      "temporary_pause",
                      "duplicate_subscription",
                      "other"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled membership",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/organizations/{organizationId}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "listOrganizationMemberships",
        "summary": "List organization memberships",
        "description": "Requires org permission `canManageSubscriptions` (via organization access middleware).",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/organizations/{organizationId}/{id}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "getOrganizationMembership",
        "summary": "Get organization membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Membership"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/memberships/organizations/{organizationId}/{id}/cancel": {
      "post": {
        "tags": [
          "Memberships"
        ],
        "operationId": "cancelOrganizationMembership",
        "summary": "Cancel organization membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "organizationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "too_expensive",
                      "not_using",
                      "switching_provider",
                      "missing_features",
                      "technical_issues",
                      "temporary_pause",
                      "duplicate_subscription",
                      "other"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled membership",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/access": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "verifyMembershipFeatureAccess",
        "summary": "Verify feature access for current user",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "feature",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Access result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/projects/{projectId}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "listProjectMemberships",
        "summary": "List memberships for project",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/memberships/projects/{projectId}/{id}": {
      "get": {
        "tags": [
          "Memberships"
        ],
        "operationId": "getProjectMembership",
        "summary": "Get project membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Membership"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/memberships/projects/{projectId}/{id}/cancel": {
      "post": {
        "tags": [
          "Memberships"
        ],
        "operationId": "cancelProjectMembership",
        "summary": "Cancel project membership",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "too_expensive",
                      "not_using",
                      "switching_provider",
                      "missing_features",
                      "technical_issues",
                      "temporary_pause",
                      "duplicate_subscription",
                      "other"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled membership",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/tiers": {
      "post": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminCreateMembershipTier",
        "summary": "Create membership tier",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/tiers/{id}": {
      "put": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminUpdateMembershipTier",
        "summary": "Update membership tier",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      },
      "delete": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminDeactivateMembershipTier",
        "summary": "Deactivate membership tier",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deactivated"
          }
        }
      }
    },
    "/bridge-payment/admin/memberships": {
      "get": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminListAllMemberships",
        "summary": "List all memberships (paginated)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/users/{userId}": {
      "get": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminListMembershipsForUser",
        "summary": "List memberships for user (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Memberships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminCreateUserMembership",
        "summary": "Create user membership (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/{id}": {
      "put": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminUpdateMembershipRecord",
        "summary": "Update membership record",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/{id}/extend": {
      "post": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminExtendMembership",
        "summary": "Extend membership by days",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "days"
                ],
                "properties": {
                  "days": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extended"
          },
          "404": {
            "description": "Membership not found"
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/analytics/overview": {
      "get": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminMembershipAnalyticsOverview",
        "summary": "Membership analytics overview",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Overview stats",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/admin/memberships/analytics/churn": {
      "get": {
        "tags": [
          "Admin - Memberships"
        ],
        "operationId": "adminMembershipAnalyticsChurn",
        "summary": "Membership churn analytics",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Churn stats",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/webhooks/external/config": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "getExternalWebhooksConfig",
        "summary": "Get external webhook configuration",
        "description": "Returns External Webhooks V2 config, including scan_max visibility and indexed webhook nodes. Related env vars: WEBHOOK_SCAN_MAX, WEBHOOK_X_ENABLED, WEBHOOK_X_EVENT_MODE (raw|canonical|both).",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "External webhook configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "enabled": {
                          "type": "boolean"
                        },
                        "scan_max": {
                          "type": "integer"
                        },
                        "webhooks": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "index": {
                                "type": "integer"
                              },
                              "enabled": {
                                "type": "boolean"
                              },
                              "url": {
                                "type": "string",
                                "format": "uri"
                              },
                              "event_mode": {
                                "type": "string",
                                "enum": [
                                  "raw",
                                  "canonical",
                                  "both"
                                ]
                              },
                              "events": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/webhooks/external/test": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "testExternalWebhook",
        "summary": "Send a test external webhook",
        "description": "Triggers a test dispatch to one or more configured external webhook destinations. Supports canonical and/or raw events including payment.*, subscription.*, customer.*, membership.*.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "index": {
                    "type": "integer",
                    "description": "Specific webhook index to test. If omitted, tests all enabled webhooks."
                  },
                  "event_mode": {
                    "type": "string",
                    "enum": [
                      "raw",
                      "canonical",
                      "both"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test dispatch completed"
          }
        }
      }
    },
    "/bridge-payment/webhooks/external/simulate": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "simulateExternalWebhook",
        "summary": "Simulate an external webhook event",
        "description": "Simulates webhook dispatch for integration testing with provider->canonical mapping. Supports raw and canonical event models, including payment.*, subscription.*, customer.*, membership.*.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "event"
                ],
                "properties": {
                  "event": {
                    "type": "string",
                    "description": "Event name to simulate (raw provider or canonical business event)."
                  },
                  "provider": {
                    "type": "string",
                    "description": "Provider context for the simulation",
                    "enum": [
                      "stripe",
                      "paypal",
                      "polar",
                      "authorize_net"
                    ]
                  },
                  "payload": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Custom payload to dispatch"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulation dispatched"
          }
        }
      }
    },
    "/bridge-payment/orders": {
      "get": {
        "tags": [
          "Orders"
        ],
        "operationId": "listOrders",
        "summary": "List orders",
        "description": "Lists orders for the authenticated user with optional organization/project filters.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "project_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Orders retrieved"
          }
        }
      },
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "createOrder",
        "summary": "Create order",
        "description": "Creates a new order with user/org/project ownership checks.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_cents"
                ],
                "properties": {
                  "user_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "organization_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "project_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "customer_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "default": "USD"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "pending",
                      "processing",
                      "completed",
                      "cancelled",
                      "refunded"
                    ],
                    "default": "pending"
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "nullable": true
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created"
          },
          "400": {
            "description": "Validation error"
          },
          "403": {
            "description": "Ownership/access violation"
          }
        }
      }
    },
    "/bridge-payment/orders/{id}": {
      "get": {
        "tags": [
          "Orders"
        ],
        "operationId": "getOrderById",
        "summary": "Get order by ID",
        "description": "Returns a single order with ownership validation.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order retrieved"
          },
          "403": {
            "description": "Access denied"
          },
          "404": {
            "description": "Order not found"
          }
        }
      }
    },
    "/bridge-payment/account-balance/me/balances": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "listMyBalances",
        "summary": "List my balances",
        "description": "Returns authenticated user balances with optional filters.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "reference_code",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "balance_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "general",
                "credits",
                "promotional",
                "refund"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "suspended",
                "expired",
                "closed"
              ]
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "project_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Balances retrieved"
          }
        }
      }
    },
    "/bridge-payment/account-balance/users/{user_id}/balances": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "adminListUserBalances",
        "summary": "List balances for specific user (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User balances retrieved"
          },
          "403": {
            "description": "Admin required"
          }
        }
      }
    },
    "/bridge-payment/account-balance/me/total": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "getMyBalanceTotal",
        "summary": "Get my total balance",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "USD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Total balance returned"
          }
        }
      }
    },
    "/bridge-payment/account-balance/users/{user_id}/total": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "adminGetUserBalanceTotal",
        "summary": "Get user total balance (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "USD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User total returned"
          },
          "403": {
            "description": "Admin required"
          }
        }
      }
    },
    "/bridge-payment/account-balance": {
      "post": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "createBalance",
        "summary": "Create balance",
        "description": "Creates an account balance ledger row with ownership checks.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "user_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "organization_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "project_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "customer_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "balance_type": {
                    "type": "string",
                    "enum": [
                      "general",
                      "credits",
                      "promotional",
                      "refund"
                    ],
                    "default": "general"
                  },
                  "balance_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "default": "USD"
                  },
                  "reference_code": {
                    "type": "string",
                    "nullable": true
                  },
                  "expires_at": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "suspended",
                      "expired",
                      "closed"
                    ],
                    "default": "active"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Balance created"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/bridge-payment/account-balance/{id}": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "getBalanceById",
        "summary": "Get balance by ID",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Balance retrieved"
          },
          "403": {
            "description": "Access denied"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/account-balance/{id}/credit": {
      "post": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "creditBalance",
        "summary": "Credit balance",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_cents"
                ],
                "properties": {
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Balance credited"
          }
        }
      }
    },
    "/bridge-payment/account-balance/{id}/debit": {
      "post": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "debitBalance",
        "summary": "Debit balance",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount_cents"
                ],
                "properties": {
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "description": {
                    "type": "string"
                  },
                  "allow_negative": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Balance debited"
          },
          "400": {
            "description": "Insufficient balance"
          }
        }
      }
    },
    "/bridge-payment/account-balance/{id}/transactions": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "listBalanceTransactions",
        "summary": "List balance transactions",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transactions retrieved"
          }
        }
      }
    },
    "/bridge-payment/account-balance/{id}/statistics": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "getBalanceStatistics",
        "summary": "Get balance statistics",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Statistics retrieved"
          }
        }
      }
    },
    "/bridge-payment/account-balance/expiring": {
      "get": {
        "tags": [
          "Account Balance"
        ],
        "operationId": "adminListExpiringBalances",
        "summary": "List expiring balances (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 7
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expiring balances returned"
          },
          "403": {
            "description": "Admin required"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/{product_id}/costs": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "listProductCosts",
        "summary": "List costs for product",
        "description": "Requires `COST_TRACKING_ENABLED`.",
        "security": [],
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cost rows",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/{product_id}/costs/active": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getActiveProductCost",
        "summary": "Get active product cost at date",
        "security": [],
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Active cost"
          },
          "404": {
            "description": "No active cost"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/{product_id}/costs/total": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getProductCostTotal",
        "summary": "Total product cost at date",
        "security": [],
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Totals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/costs": {
      "post": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "createProductCost",
        "summary": "Create product cost",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/costs/{id}": {
      "put": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "updateProductCost",
        "summary": "Update product cost row",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "delete": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "deleteProductCost",
        "summary": "Delete product cost",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/products/costs/{id}/close": {
      "post": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "closeProductCost",
        "summary": "Close product cost (set effective_until)",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Closed"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/orders/{order_id}/cost": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getOrderCostAnalysis",
        "summary": "Order cost analysis",
        "security": [],
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order cost"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/subscriptions/{subscription_id}/cost": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getSubscriptionCostAnalysis",
        "summary": "Subscription cost analysis",
        "security": [],
        "parameters": [
          {
            "name": "subscription_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription cost"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/analytics/profitability": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getCostAnalyticsProfitability",
        "summary": "Profitability statistics",
        "security": [],
        "parameters": [
          {
            "name": "start_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "end_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Profitability",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/analytics/low-margins": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getCostAnalyticsLowMargins",
        "summary": "Low margin orders",
        "security": [],
        "parameters": [
          {
            "name": "threshold",
            "in": "query",
            "schema": {
              "type": "number",
              "default": 10
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/analytics/losses": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getCostAnalyticsLosses",
        "summary": "Loss orders",
        "security": [],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/cost-tracking/analytics/top-profitable": {
      "get": {
        "tags": [
          "Cost Tracking"
        ],
        "operationId": "getCostAnalyticsTopProfitable",
        "summary": "Top profitable orders",
        "security": [],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/me": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listMyBillingSchedules",
        "summary": "Current user's schedules",
        "description": "Requires `BILLING_SCHEDULES_ENABLED`.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/users/{user_id}": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listBillingSchedulesForUser",
        "summary": "User's schedules (admin)",
        "description": "Admin-only in server.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/active": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listActiveBillingSchedules",
        "summary": "Active schedules (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/due": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listDueBillingSchedules",
        "summary": "Due schedules (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules": {
      "post": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "createBillingSchedule",
        "summary": "Create billing schedule",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "getBillingScheduleById",
        "summary": "Get schedule by ID",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedule"
          },
          "403": {
            "description": "Ownership"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "delete": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "deleteBillingSchedule",
        "summary": "Delete schedule",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}/pause": {
      "post": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "pauseBillingSchedule",
        "summary": "Pause schedule",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paused schedule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}/resume": {
      "post": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "resumeBillingSchedule",
        "summary": "Resume schedule",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resumed schedule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}/cancel": {
      "post": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "cancelBillingSchedule",
        "summary": "Cancel schedule",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled schedule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}/executions": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listBillingScheduleExecutions",
        "summary": "Execution history",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Executions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/{id}/statistics": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "getBillingScheduleStatistics",
        "summary": "Execution statistics",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/billing-schedules/executions/failed": {
      "get": {
        "tags": [
          "Billing Schedules"
        ],
        "operationId": "listFailedBillingExecutions",
        "summary": "Failed executions (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Executions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/invoices": {
      "get": {
        "tags": [
          "Invoices"
        ],
        "operationId": "listInvoices",
        "summary": "List invoices",
        "description": "Requires `INVOICES_RECEIPTS_ENABLED`. Optional filters: `organization_id`, `project_id` (project access verified).",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "project_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invoices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Invoices"
        ],
        "operationId": "createInvoice",
        "summary": "Create invoice",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/bridge-payment/invoices/{id}": {
      "get": {
        "tags": [
          "Invoices"
        ],
        "operationId": "getInvoiceById",
        "summary": "Get invoice",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invoice"
          },
          "403": {
            "description": "Ownership"
          }
        }
      }
    },
    "/bridge-payment/receipts/me": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "listMyReceipts",
        "summary": "List my receipts",
        "description": "Requires `INVOICES_RECEIPTS_ENABLED`. Optional `organization_id` or `project_id` filters.",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "organization_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "project_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts/users/{user_id}": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "listReceiptsForUser",
        "summary": "List receipts for user (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts/number/{receipt_number}": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "getReceiptByNumber",
        "summary": "Get receipt by receipt number",
        "description": "Prefer registering this route before generic `{id}` in implementations; server route order may vary.",
        "security": [],
        "parameters": [
          {
            "name": "receipt_number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/bridge-payment/receipts/{id}": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "getReceiptById",
        "summary": "Get receipt by ID",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt"
          },
          "403": {
            "description": "Ownership"
          }
        }
      },
      "delete": {
        "tags": [
          "Receipts"
        ],
        "operationId": "deleteReceipt",
        "summary": "Delete receipt",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts": {
      "post": {
        "tags": [
          "Receipts"
        ],
        "operationId": "createReceipt",
        "summary": "Create receipt",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/bridge-payment/receipts/{id}/send": {
      "post": {
        "tags": [
          "Receipts"
        ],
        "operationId": "sendReceipt",
        "summary": "Mark receipt as sent",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts/{id}/void": {
      "post": {
        "tags": [
          "Receipts"
        ],
        "operationId": "voidReceipt",
        "summary": "Void receipt",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts/unsent": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "listUnsentReceipts",
        "summary": "Unsent receipts (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/bridge-payment/receipts/analytics/revenue": {
      "get": {
        "tags": [
          "Receipts"
        ],
        "operationId": "getReceiptRevenueAnalytics",
        "summary": "Receipt revenue analytics (admin)",
        "security": [
          {
            "SessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "start_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "end_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "USD"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Totals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "SessionAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Session-ID",
        "description": "Session ID from Flowless authentication"
      },
      "GuestToken": {
        "type": "apiKey",
        "in": "query",
        "name": "token",
        "description": "Guest token for anonymous checkout"
      }
    },
    "schemas": {}
  }
}