openapi: 3.0.3
info:
  title: Agentic Commerce API
  version: "1.0.0"
  description: |
    OpenAPI specification converted from the provided Postman collection.
servers:
  - url: http://localhost:9000
    description: Local server (from BACKEND_URL)
  - url: https://api.example.com
    description: Replace with your production BACKEND_URL
paths:
  /checkout_sessions:
    post:
      summary: Create Checkout Session
      description: Create a new checkout session.
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
        - $ref: '#/components/parameters/Signature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCheckoutSessionRequest'
            example:
              items:
                - id: variant_01K6CQ43RA0RSWW1BXM8C63YT6
                  quantity: 1
              fulfillment_address:
                name: John Smith
                line_one: US
                city: New York
                state: NY
                country: us
                postal_code: "12345"
              buyer:
                email: johnsmith@gmail.com
                first_name: John
                phone_number: "123"
      responses:
        '200':
          description: Checkout session created successfully.
  /checkout_sessions/{id}:
    get:
      summary: Get Checkout Session
      description: Retrieve a checkout session by ID.
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Checkout session retrieved successfully.
    post:
      summary: Update Checkout Session
      description: Update fields on a checkout session.
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
        - $ref: '#/components/parameters/Signature'
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCheckoutSessionRequest'
            example:
              fulfillment_option_id: so_01K6FCGVFMNNC5H43SB9NNNAJ3
      responses:
        '200':
          description: Checkout session updated successfully.
  /checkout_sessions/{id}/complete:
    post:
      summary: Complete Checkout Session
      description: Complete and pay for a checkout session.
      parameters:
        - $ref: '#/components/parameters/Signature'
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompleteCheckoutSessionRequest'
            example:
              buyer:
                first_name: John
                email: johnsmith@gmail.com
                phone_number: "123"
              payment_data:
                provider: stripe
                token: "123"
      responses:
        '200':
          description: Checkout session completed successfully.
  /checkout_sessions/{id}/cancel:
    post:
      summary: Cancel Checkout Session
      description: Cancel a checkout session.
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/RequestId'
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Checkout session canceled successfully.
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
      description: A unique key to ensure idempotent requests.
    RequestId:
      name: Request-Id
      in: header
      required: false
      schema:
        type: string
      description: A unique identifier for correlating requests.
    Signature:
      name: Signature
      in: header
      required: false
      schema:
        type: string
      description: Signature header used for request verification.
  schemas:
    CreateCheckoutSessionRequest:
      type: object
      required: [items, fulfillment_address, buyer]
      properties:
        items:
          type: array
          items:
            type: object
            required: [id, quantity]
            properties:
              id:
                type: string
                description: The product variant ID.
              quantity:
                type: integer
                minimum: 1
        fulfillment_address:
          type: object
          required: [name, line_one, city, state, country, postal_code]
          properties:
            name: { type: string }
            line_one: { type: string }
            city: { type: string }
            state: { type: string }
            country: { type: string }
            postal_code: { type: string }
        buyer:
          type: object
          required: [email]
          properties:
            email: { type: string, format: email }
            first_name: { type: string }
            phone_number: { type: string }
    UpdateCheckoutSessionRequest:
      type: object
      required: [fulfillment_option_id]
      properties:
        fulfillment_option_id:
          type: string
          description: Chosen fulfillment/shipping option ID.
    CompleteCheckoutSessionRequest:
      type: object
      required: [buyer, payment_data]
      properties:
        buyer:
          type: object
          properties:
            first_name: { type: string }
            email: { type: string, format: email }
            phone_number: { type: string }
        payment_data:
          type: object
          required: [provider, token]
          properties:
            provider:
              type: string
              description: Payment provider identifier (e.g., stripe).
            token:
              type: string
              description: Payment authorization token.
