{
  "openapi": "3.1.0",
  "info": {
    "title": "KissMyApps Funnel Contract",
    "version": "1.3.0",
    "description": "Embedded or hosted checkout, billing email prefill, receipt-bound direct Stripe confirmation, and independent webhook normalization. BC Learn has no product app/backend yet. App access and purchase-claim APIs are not implemented or included in v1.3; see funnel-api.md section 7.1 for the future developer integration requirements."
  },
  "servers": [
    {
      "url": "https://bc-learn-partner-funnel.vercel.app"
    }
  ],
  "paths": {
    "/api/waitlist": {
      "post": {
        "operationId": "saveBcLearnEarlyAccessEmail",
        "summary": "Save the BC Learn email step before showing the paywall",
        "description": "Existing BC Learn lead-capture service, separate from the partner financial API. Saves to the existing Firestore waitlist and may send its configured welcome email. Does not create a partner account, payment, commission or entitlement. Only an HTTP-success {ok:true} response advances the copied funnel to its paywall. Email is excluded from partner analytics; the checkout step separately forwards billing email to Stripe. Existing endpoint abuse controls require production review.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "session_id": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "answers": {
                    "type": "object",
                    "properties": {
                      "speaking_goal": {
                        "type": "string",
                        "enum": [
                          "work_career",
                          "everyday_conversations",
                          "travel_living_abroad",
                          "study_interviews",
                          "confidence_fluency"
                        ]
                      },
                      "speaking_barrier": {
                        "type": "string",
                        "enum": [
                          "freeze",
                          "fear_mistakes",
                          "no_partner",
                          "pronunciation",
                          "fast_english"
                        ]
                      },
                      "preferred_format": {
                        "type": "string",
                        "enum": [
                          "live_groups",
                          "one_to_one",
                          "ai_guided",
                          "mixed"
                        ]
                      }
                    }
                  },
                  "context": {
                    "type": "object",
                    "properties": {
                      "timezone": {
                        "type": "string",
                        "maxLength": 64
                      },
                      "locale": {
                        "type": "string",
                        "maxLength": 32
                      },
                      "acquisition_source": {
                        "type": "string",
                        "maxLength": 64
                      },
                      "campaign": {
                        "type": "string",
                        "maxLength": 120
                      },
                      "keyword": {
                        "type": "string",
                        "maxLength": 120
                      },
                      "referrer": {
                        "type": "string",
                        "maxLength": 200
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email saved. The UI may show the paywall, not a payment-success state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "created"
                  ],
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "created": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Email invalid. Remain on email entry."
          },
          "502": {
            "description": "Email could not be saved. Remain on email entry and allow retry."
          },
          "503": {
            "description": "Existing waitlist store is not configured. Do not advance to checkout."
          }
        }
      }
    },
    "/api/partner/offer": {
      "post": {
        "operationId": "reviewOffer",
        "summary": "reviewOffer",
        "description": "Sets a signed HttpOnly 15-minute reviewed-offer cookie.",
        "security": [
          {
            "SameOrigin": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OfferInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "offer",
                    "checkout_enabled"
                  ],
                  "properties": {
                    "offer": {
                      "$ref": "#/components/schemas/Offer"
                    },
                    "checkout_enabled": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/partner/checkout": {
      "post": {
        "operationId": "startCheckout",
        "summary": "startCheckout",
        "description": "Exact-origin checkout with signed offer/receipt cookies. BC Learn requires customer_email and returns EmbeddedCheckout. Client secrets must never enter logs, storage or URLs.",
        "security": [
          {
            "SameOrigin": [],
            "QuoteCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ]
      }
    },
    "/api/partner/status": {
      "post": {
        "operationId": "readPaymentStatus",
        "summary": "readPaymentStatus",
        "description": "Verifies exact session, attempt, click, product and funnel. Pending ledger status triggers a direct Stripe session check. No worker wait, PII, ledger mutation or entitlement grant. Complete-but-unpaid remains pending.",
        "security": [
          {
            "SameOrigin": [],
            "ReceiptCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StatusInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/funnel-checkout-context": {
      "servers": [
        {
          "url": "https://mmyruzjemjecqyivhrgr.supabase.co/functions/v1"
        }
      ],
      "post": {
        "operationId": "readServerContext",
        "summary": "readServerContext",
        "description": "HMAC scope binds product and funnel. Body max 4096 bytes. Reject Origin header.",
        "security": [
          {
            "KeyId": [],
            "Timestamp": [],
            "Nonce": [],
            "Signature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContextInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "offer",
                        "request_id"
                      ],
                      "properties": {
                        "offer": {
                          "$ref": "#/components/schemas/Offer"
                        },
                        "request_id": {
                          "type": "string"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/Status"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/checkout-session": {
      "servers": [
        {
          "url": "https://mmyruzjemjecqyivhrgr.supabase.co/functions/v1"
        }
      ],
      "post": {
        "operationId": "createServerCheckout",
        "summary": "createServerCheckout",
        "description": "Server-authenticated checkout; UI mode is adapter-owned. Email is prefill only. Retries bind immutable mode, keyed email fingerprint and no-charge guard. Existing open sessions are retrieved, not recreated.",
        "security": [
          {
            "KeyId": [],
            "Timestamp": [],
            "Nonce": [],
            "Signature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "click_id",
                  "offer_key",
                  "offer_version"
                ],
                "properties": {
                  "click_id": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{16,128}$"
                  },
                  "offer_key": {
                    "type": "string",
                    "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
                  },
                  "offer_version": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 999999999
                  },
                  "require_no_payment": {
                    "type": "boolean",
                    "const": true,
                    "description": "Server-only guard. Uses the product-scoped 100%-off forever promotion; missing discount or nonzero Stripe total fails closed."
                  },
                  "ui_mode": {
                    "type": "string",
                    "enum": [
                      "hosted",
                      "embedded"
                    ],
                    "default": "hosted"
                  },
                  "customer_email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254,
                    "description": "Stripe billing prefill only, not identity or attribution evidence. Required by the BC Learn embedded adapter."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/HostedCheckout"
                    },
                    {
                      "$ref": "#/components/schemas/EdgeEmbeddedCheckout"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/browser-events": {
      "servers": [
        {
          "url": "https://mmyruzjemjecqyivhrgr.supabase.co/functions/v1"
        }
      ],
      "post": {
        "operationId": "recordBrowserEvent",
        "summary": "recordBrowserEvent",
        "description": "Origin must be in BROWSER_EVENT_ALLOWED_ORIGINS. Event ID and body stable on retries. Only non-commercial evidence.",
        "security": [
          {
            "SameOrigin": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BrowserEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/funnel-events": {
      "servers": [
        {
          "url": "https://mmyruzjemjecqyivhrgr.supabase.co/functions/v1"
        }
      ],
      "post": {
        "operationId": "recordTrustedFunnelEvent",
        "summary": "Record an allowlisted non-payment server event",
        "description": "Server HMAC only. Event name/properties must be in configured allowlists. Not payment truth.",
        "security": [
          {
            "KeyId": [],
            "Timestamp": [],
            "Nonce": [],
            "Signature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TrustedEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid HMAC",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin, scope or receipt rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Context unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Offer review or checkout conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Configuration or provider unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Offer": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "version",
          "name",
          "currency",
          "unit_amount_minor",
          "billing_mode",
          "interval",
          "interval_count"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "version": {
            "type": "integer",
            "minimum": 1,
            "maximum": 999999999
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$"
          },
          "unit_amount_minor": {
            "type": "integer",
            "minimum": 1,
            "maximum": 99999999
          },
          "billing_mode": {
            "const": "subscription"
          },
          "interval": {
            "enum": [
              "day",
              "week",
              "month",
              "year"
            ]
          },
          "interval_count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          }
        }
      },
      "Checkout": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/HostedCheckout"
          },
          {
            "$ref": "#/components/schemas/EmbeddedCheckout"
          }
        ]
      },
      "Status": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status",
          "request_id"
        ],
        "properties": {
          "status": {
            "enum": [
              "pending",
              "paid",
              "no_payment_required",
              "expired",
              "failed"
            ]
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "OfferInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "click_id"
        ],
        "properties": {
          "click_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16,128}$"
          }
        }
      },
      "CheckoutInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "click_id",
          "offer_key"
        ],
        "properties": {
          "click_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16,128}$"
          },
          "offer_key": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "customer_email": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "Stripe billing prefill only, not identity or attribution evidence. Required by the BC Learn embedded adapter."
          }
        }
      },
      "StatusInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "session_id"
        ],
        "properties": {
          "session_id": {
            "type": "string",
            "pattern": "^cs_live_[A-Za-z0-9_]{8,160}$"
          }
        }
      },
      "ContextInput": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "action",
              "click_id",
              "offer_key"
            ],
            "properties": {
              "action": {
                "const": "offer"
              },
              "click_id": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{16,128}$"
              },
              "offer_key": {
                "type": "string",
                "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "action",
              "click_id",
              "attempt_id",
              "session_id"
            ],
            "properties": {
              "action": {
                "const": "status"
              },
              "click_id": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{16,128}$"
              },
              "attempt_id": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{32,128}$"
              },
              "session_id": {
                "type": "string",
                "pattern": "^cs_live_[A-Za-z0-9_]{8,160}$"
              }
            }
          }
        ]
      },
      "BrowserEvent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "event_id",
          "event_name",
          "click_id",
          "occurred_at",
          "properties"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "format": "uuid"
          },
          "event_name": {
            "enum": [
              "landing_viewed",
              "funnel_started",
              "payment_viewed",
              "app_store_clicked"
            ]
          },
          "click_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16,128}$"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "properties": {
            "type": "object",
            "description": "Allowlisted non-identifying properties only; see browser-attribution.ts. Never include full URLs or email."
          }
        }
      },
      "EventReceipt": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "accepted",
          "event_id",
          "duplicate",
          "request_id"
        ],
        "properties": {
          "accepted": {
            "const": true
          },
          "event_id": {
            "type": "string",
            "format": "uuid"
          },
          "duplicate": {
            "type": "boolean"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "TrustedEvent": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "event_id",
          "event_name",
          "click_id",
          "occurred_at",
          "properties"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "format": "uuid"
          },
          "event_name": {
            "type": "string",
            "description": "Must be in FUNNEL_EVENT_ALLOWED_NAMES; not payment truth.",
            "pattern": "^[a-z][a-z0-9_.-]{0,99}$"
          },
          "click_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{16,128}$"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "properties": {
            "type": "object",
            "description": "Allowlisted non-identifying properties only; see browser-attribution.ts. Never include full URLs or email."
          }
        }
      },
      "HostedCheckout": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "checkout_url",
          "attempt_id",
          "expires_at",
          "request_id"
        ],
        "properties": {
          "checkout_url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://checkout\\.stripe\\.com/"
          },
          "attempt_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{32,128}$"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "EmbeddedCheckout": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ui_mode",
          "checkout_url",
          "client_secret",
          "session_id",
          "publishable_key",
          "attempt_id",
          "expires_at",
          "request_id"
        ],
        "properties": {
          "checkout_url": {
            "type": "null"
          },
          "attempt_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{32,128}$"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string"
          },
          "ui_mode": {
            "const": "embedded"
          },
          "client_secret": {
            "type": "string",
            "maxLength": 512,
            "description": "Ephemeral Stripe client secret. Component memory only; never store or log."
          },
          "session_id": {
            "type": "string",
            "pattern": "^cs_live_[A-Za-z0-9_]{8,160}$"
          },
          "publishable_key": {
            "type": "string",
            "pattern": "^pk_live_[A-Za-z0-9_]{16,256}$"
          }
        }
      },
      "EdgeEmbeddedCheckout": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ui_mode",
          "checkout_url",
          "client_secret",
          "session_id",
          "attempt_id",
          "expires_at",
          "request_id"
        ],
        "properties": {
          "checkout_url": {
            "type": "null"
          },
          "attempt_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{32,128}$"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string"
          },
          "ui_mode": {
            "const": "embedded"
          },
          "client_secret": {
            "type": "string",
            "maxLength": 512,
            "description": "Ephemeral Stripe client secret. Component memory only; never store or log."
          },
          "session_id": {
            "type": "string",
            "pattern": "^cs_live_[A-Za-z0-9_]{8,160}$"
          }
        }
      }
    },
    "securitySchemes": {
      "SameOrigin": {
        "type": "apiKey",
        "in": "header",
        "name": "Origin",
        "description": "Exact configured funnel origin; not a secret. Browser-events uses the backend origin allowlist."
      },
      "QuoteCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "kma_checkout_quote",
        "description": "HttpOnly signed claim; do not fabricate."
      },
      "ReceiptCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "kma_checkout_receipt",
        "description": "HttpOnly signed receipt; do not fabricate."
      },
      "KeyId": {
        "type": "apiKey",
        "in": "header",
        "name": "x-kma-key-id",
        "description": "HMAC-SHA256 over timestamp.nonce.exact_body, with a per-product/funnel secret; timestamp tolerance 300s."
      },
      "Timestamp": {
        "type": "apiKey",
        "in": "header",
        "name": "x-kma-timestamp",
        "description": "HMAC-SHA256 over timestamp.nonce.exact_body, with a per-product/funnel secret; timestamp tolerance 300s."
      },
      "Nonce": {
        "type": "apiKey",
        "in": "header",
        "name": "x-kma-nonce",
        "description": "HMAC-SHA256 over timestamp.nonce.exact_body, with a per-product/funnel secret; timestamp tolerance 300s."
      },
      "Signature": {
        "type": "apiKey",
        "in": "header",
        "name": "x-kma-signature",
        "description": "HMAC-SHA256 over timestamp.nonce.exact_body, with a per-product/funnel secret; timestamp tolerance 300s."
      }
    }
  }
}
