openapi: 3.1.0
info:
  title: BookMySeat API
  version: 1.0.0
  description: >-
    Catalog, seat availability, holds, partner confirmation, venue check-in, and
    operator publishing for BookMySeat inventory. All amounts are integer
    currency minor units. Partner keys are server-side secrets.
servers:
  - url: https://bookmyseat-tickets.glacialsundae16.chatgpt.site
    description: BookMySeat hosted Site
tags:
  - name: Public catalog
  - name: Customer
  - name: Partner
  - name: Operator
  - name: Venue
paths:
  /api/health:
    get:
      tags: [Public catalog]
      summary: Check which runtime capabilities are configured
      responses:
        '200':
          description: Worker and database are available
        '503':
          description: A required runtime resource is unavailable
  /api/events:
    get:
      tags: [Public catalog]
      summary: List published shows in a city
      parameters:
        - in: query
          name: city
          schema: { type: string }
      responses:
        '200':
          description: Published shows; empty array means none are on sale
          content:
            application/json:
              schema:
                type: object
                required: [events]
                properties:
                  events:
                    type: array
                    items: { $ref: '#/components/schemas/EventCard' }
  /api/events/{slug}:
    get:
      tags: [Public catalog]
      summary: Read published show details and cancellation policy
      parameters:
        - $ref: '#/components/parameters/Slug'
      responses:
        '200':
          description: Show details
        '404':
          $ref: '#/components/responses/Error'
  /api/events/{slug}/seats:
    get:
      tags: [Public catalog]
      summary: Read current seats and their availability
      parameters:
        - $ref: '#/components/parameters/Slug'
      responses:
        '200':
          description: Seat map snapshot
          content:
            application/json:
              schema:
                type: object
                properties:
                  seats:
                    type: array
                    items: { $ref: '#/components/schemas/Seat' }
  /api/events/{slug}/queue:
    get:
      tags: [Customer]
      summary: Read the signed-in customer’s place in the admission queue
      security: [{ CustomerSession: [] }]
      parameters:
        - $ref: '#/components/parameters/Slug'
      responses:
        '200': { description: Queue state; includes a token only while admitted }
        '401': { $ref: '#/components/responses/Error' }
    post:
      tags: [Customer]
      summary: Join the admission queue
      security: [{ CustomerSession: [] }]
      parameters:
        - $ref: '#/components/parameters/Slug'
      responses:
        '200': { description: Current place or admission token }
  /api/auth/google/status:
    get:
      tags: [Customer]
      summary: Check whether Google sign-in is configured
      responses:
        '200':
          description: Sign-in readiness without exposing credential values
          content:
            application/json:
              schema:
                type: object
                required: [enabled]
                properties:
                  enabled: { type: boolean }
  /api/auth/google/start:
    get:
      tags: [Customer]
      summary: Start Google OAuth sign-in
      parameters:
        - in: query
          name: return_to
          schema: { type: string }
          description: Same-origin application path to open after sign-in; unsafe paths fall back to /account.
      responses:
        '302': { description: Redirect to Google; state and PKCE verifier are held in a short-lived HttpOnly cookie. }
  /api/auth/google/callback:
    get:
      tags: [Customer]
      summary: Complete Google OAuth sign-in
      parameters:
        - in: query
          name: code
          required: true
          schema: { type: string }
        - in: query
          name: state
          required: true
          schema: { type: string }
      responses:
        '302': { description: Validate state, exchange the code with PKCE, and redirect to the saved same-origin path. On success, set a customer session cookie; on error, return to sign-in with an error code. }
  /api/auth/sign-out:
    post:
      tags: [Customer]
      summary: Clear the signed-in customer session cookie
      responses:
        '200': { description: Session cleared }
  /api/account:
    get:
      tags: [Customer]
      summary: Read the signed-in customer account
      security: [{ CustomerSession: [] }]
      responses:
        '200': { description: Customer email and account state }
        '401': { $ref: '#/components/responses/Error' }
  /api/holds:
    post:
      tags: [Customer]
      summary: Atomically hold a complete seat selection
      security: [{ CustomerSession: [] }]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - in: header
          name: X-BookMySeat-Admission
          schema: { type: string }
          description: Required only when this event has a waiting room enabled.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/HoldRequest' }
      responses:
        '201': { description: All requested seats held or none were held; a zero-total selection is booked immediately }
        '409': { $ref: '#/components/responses/Error' }
        '410': { $ref: '#/components/responses/Error' }
  /api/holds/active:
    get:
      tags: [Customer]
      summary: Resume the signed-in customer’s active hold after reload or in another tab
      security: [{ CustomerSession: [] }]
      parameters:
        - in: query
          name: event_id
          required: true
          schema: { type: string }
      responses:
        '200': { description: Active hold and its seat IDs, or null }
  /api/holds/{hold_id}:
    get:
      tags: [Customer]
      summary: Read an owned hold and its booking state
      security: [{ CustomerSession: [] }]
      parameters:
        - $ref: '#/components/parameters/HoldId'
      responses:
        '200': { description: Hold state and booking if confirmed }
        '404': { $ref: '#/components/responses/Error' }
    delete:
      tags: [Customer]
      summary: Release an owned active hold
      security: [{ CustomerSession: [] }]
      parameters:
        - $ref: '#/components/parameters/HoldId'
      responses:
        '200': { description: Hold released; already expired holds are idempotent }
  /api/payments/razorpay/order:
    post:
      tags: [Customer]
      summary: Create or resume the server-owned Razorpay order for an active hold
      security: [{ CustomerSession: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [hold_id]
              properties:
                hold_id: { type: string }
      responses:
        '200': { description: Checkout order and public Razorpay key ID }
        '503': { $ref: '#/components/responses/Error' }
  /api/payments/razorpay/verify:
    post:
      tags: [Customer]
      summary: Verify Checkout signature and captured payment through Razorpay
      security: [{ CustomerSession: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [hold_id, razorpay_order_id, razorpay_payment_id, razorpay_signature]
              properties:
                hold_id: { type: string }
                razorpay_order_id: { type: string }
                razorpay_payment_id: { type: string }
                razorpay_signature: { type: string }
      responses:
        '200': { description: Booking confirmed after provider status verification }
        '202': { description: Payment or late-capture refund reconciliation is pending }
        '400': { $ref: '#/components/responses/Error' }
  /api/webhooks/razorpay:
    post:
      tags: [Customer]
      summary: Receive signed Razorpay payment webhooks
      parameters:
        - in: header
          name: X-Razorpay-Signature
          required: true
          schema: { type: string }
        - in: header
          name: x-razorpay-event-id
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object }
      responses:
        '200': { description: Verified and processed or duplicate event }
        '202': { description: Verified event persisted for reconciliation }
        '400': { description: Invalid signature or body }
  /api/tickets:
    get:
      tags: [Customer]
      summary: List tickets for the signed-in customer, including signed QR payloads
      security: [{ CustomerSession: [] }]
      responses:
        '200': { description: Upcoming and past tickets }
        '401': { $ref: '#/components/responses/Error' }
  /api/admin/refunds/{payment_id}/retry:
    post:
      tags: [Operator]
      summary: Retry a pending or processing Razorpay refund with the same idempotency key
      security: [{ OperatorKey: [] }]
      parameters:
        - in: path
          name: payment_id
          required: true
          schema: { type: string }
      responses:
        '200': { description: Current refund status }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
  /api/v1/events:
    get:
      tags: [Partner]
      summary: List events assigned to this partner channel
      security: [{ PartnerKey: [] }]
      responses:
        '200': { description: Channel-scoped published event catalog }
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
  /api/v1/events/{event_id}/seats:
    get:
      tags: [Partner]
      summary: Read seat availability for an event assigned to this channel
      security: [{ PartnerKey: [] }]
      parameters:
        - in: path
          name: event_id
          required: true
          schema: { type: string }
      responses:
        '200': { description: Same authoritative seat IDs shared across channels }
        '404': { $ref: '#/components/responses/Error' }
  /api/v1/events/{slug}/queue:
    get:
      tags: [Partner]
      summary: Read this buyer’s channel-scoped queue state
      security: [{ PartnerKey: [] }]
      parameters:
        - $ref: '#/components/parameters/Slug'
        - in: query
          name: customer_ref
          required: true
          schema: { type: string, maxLength: 200 }
      responses:
        '200': { description: Queue state }
    post:
      tags: [Partner]
      summary: Place this buyer in the event queue
      security: [{ PartnerKey: [] }]
      parameters:
        - $ref: '#/components/parameters/Slug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [customer_ref]
              properties:
                customer_ref: { type: string, maxLength: 200 }
      responses:
        '200': { description: Queue position or admission pass }
  /api/v1/holds:
    post:
      tags: [Partner]
      summary: Create an atomic hold for a listed event
      security: [{ PartnerKey: [] }]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/HoldRequest'
                - type: object
                  required: [customer_ref]
                  properties:
                    customer_ref: { type: string, maxLength: 200 }
                    admission_token: { type: string }
      responses:
        '201': { description: Seat hold and expiry time }
        '404': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
  /api/v1/holds/{hold_id}:
    delete:
      tags: [Partner]
      summary: Release a hold owned by this channel
      security: [{ PartnerKey: [] }]
      parameters:
        - $ref: '#/components/parameters/HoldId'
      responses:
        '200': { description: Released or already terminal }
        '404': { $ref: '#/components/responses/Error' }
  /api/v1/holds/{hold_id}/confirm:
    post:
      tags: [Partner]
      summary: Confirm seats after the partner provider reports captured payment
      security: [{ PartnerKey: [] }]
      parameters:
        - $ref: '#/components/parameters/HoldId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [status, payment_reference, amount_minor, currency]
              properties:
                status: { const: captured }
                payment_reference: { type: string, maxLength: 160 }
                amount_minor: { type: integer, minimum: 0 }
                currency: { type: string, pattern: '^[A-Z]{3}$' }
      responses:
        '200': { description: Booking and one signed ticket QR per seat }
        '409': { $ref: '#/components/responses/Error' }
        '410': { description: Hold expired after payment capture; partner must refund }
  /api/v1/check-in:
    post:
      tags: [Venue]
      summary: Validate and redeem one signed ticket QR
      security: [{ VenueDevice: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [ticket_token]
              properties:
                ticket_token: { type: string }
      responses:
        '200': { description: First scan redeemed ticket }
        '409': { description: Ticket was already scanned }
        '410': { description: Ticket expired or was voided }
  /api/admin/events:
    post:
      tags: [Operator]
      summary: Create a real show and its seat map; optionally publish it
      security: [{ OperatorKey: [] }]
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/PublishEventRequest' }
      responses:
        '201': { description: Event and seats created in one transaction }
        '409': { $ref: '#/components/responses/Error' }
  /api/admin/channels:
    post:
      tags: [Operator]
      summary: Create an authorized distribution channel and issue a key once
      security: [{ OperatorKey: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [id, name]
              properties:
                id: { type: string, pattern: '^[a-z0-9][a-z0-9_-]{1,63}$' }
                name: { type: string, maxLength: 120 }
                scopes:
                  type: array
                  items: { type: string, enum: ["catalog:read", "inventory:read", "inventory:write", "hold:confirm"] }
      responses:
        '201': { description: Channel key returned one time }
        '409': { $ref: '#/components/responses/Error' }
  /api/admin/channels/{channel_id}/listings:
    post:
      tags: [Operator]
      summary: Allow a channel to sell a published event from its shared pool
      security: [{ OperatorKey: [] }]
      parameters:
        - in: path
          name: channel_id
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [event_id]
              properties:
                event_id: { type: string }
                external_listing_ref: { type: string }
      responses:
        '200': { description: Shared pool assigned to channel }
  /api/admin/venue-devices:
    post:
      tags: [Operator]
      summary: Issue a venue check-in device key once
      security: [{ OperatorKey: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [organizer_id, device_name]
              properties:
                organizer_id: { type: string }
                event_id: { type: string }
                device_name: { type: string, maxLength: 120 }
      responses:
        '201': { description: Venue device key returned once }
components:
  securitySchemes:
    CustomerSession:
      type: apiKey
      in: cookie
      name: bms_session
    PartnerKey:
      type: http
      scheme: bearer
      description: Server-side channel key, scope-limited and never sent to a browser.
    OperatorKey:
      type: http
      scheme: bearer
      description: Operator-only secret; store in hosting secrets.
    VenueDevice:
      type: http
      scheme: bearer
      description: Event/organizer-scoped venue device key.
  parameters:
    Slug:
      in: path
      name: slug
      required: true
      schema: { type: string }
    HoldId:
      in: path
      name: hold_id
      required: true
      schema: { type: string }
    IdempotencyKey:
      in: header
      name: Idempotency-Key
      required: true
      schema: { type: string, minLength: 8, maxLength: 128 }
  responses:
    Error:
      description: Error response
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code: { type: string }
            message: { type: string }
    EventCard:
      type: object
      properties:
        id: { type: string }
        slug: { type: string }
        title: { type: string }
        category: { type: [string, 'null'] }
        venue_name: { type: string }
        city: { type: string }
        starts_at: { type: integer, description: Unix seconds }
        currency: { type: string }
        min_price_minor: { type: [integer, 'null'] }
        available_count: { type: integer }
    Seat:
      type: object
      properties:
        id: { type: string }
        section_name: { type: string }
        row_label: { type: string }
        seat_number: { type: integer }
        price_minor: { type: integer }
        currency: { type: string }
        x: { type: number }
        y: { type: number }
        status: { type: string, enum: [available, held, sold] }
    HoldRequest:
      type: object
      required: [event_id, seat_map_version, seat_ids]
      properties:
        event_id: { type: string }
        seat_map_version: { type: integer }
        seat_ids:
          type: array
          minItems: 1
          maxItems: 10
          uniqueItems: true
          items: { type: string }
    PublishEventRequest:
      type: object
      required: [organizer, event, seats]
      properties:
        publish: { type: boolean, default: false }
        organizer:
          type: object
          required: [id, name]
          properties:
            id: { type: string }
            name: { type: string }
        event:
          type: object
          required: [slug, title, venue_name, city, starts_at, cancellation_policy]
          properties:
            slug: { type: string }
            title: { type: string }
            description: { type: string }
            category: { type: string }
            poster_url: { type: string, format: uri }
            venue_name: { type: string }
            venue_address: { type: string }
            city: { type: string }
            starts_at: { oneOf: [{ type: string, format: date-time }, { type: integer }] }
            ends_at: { oneOf: [{ type: string, format: date-time }, { type: integer }] }
            doors_at: { oneOf: [{ type: string, format: date-time }, { type: integer }] }
            sales_open_at: { oneOf: [{ type: string, format: date-time }, { type: integer }] }
            sales_close_at: { oneOf: [{ type: string, format: date-time }, { type: integer }] }
            cancellation_policy: { type: string }
            currency: { type: string, default: INR }
            service_fee_bps: { type: integer, minimum: 0, maximum: 2000 }
            gst_bps: { type: integer, minimum: 0, maximum: 3000 }
            hold_seconds: { type: integer, minimum: 60, maximum: 900 }
            queue_enabled: { type: boolean }
            concurrent_checkout_limit: { type: integer, minimum: 1, maximum: 10000 }
            inventory_mode: { type: string, enum: [central, allocated, listing_only] }
        seats:
          type: array
          minItems: 1
          maxItems: 10000
          items:
            type: object
            required: [id, section_name, row_label, seat_number, price_minor, x, y]
            properties:
              id: { type: string }
              section_name: { type: string }
              row_label: { type: string }
              seat_number: { type: integer }
              price_minor: { type: integer, minimum: 0 }
              currency: { type: string }
              x: { type: number, minimum: -100, maximum: 100 }
              y: { type: number, minimum: -100, maximum: 100 }
              z: { type: number }
              accessible: { type: boolean }
              seat_type: { type: string, enum: [standard, companion, wheelchair, standing] }
