openapi: 3.0.3
info:
  title: Kaito Merchant API
  version: 2.0.0
  description: >
    Merchant services including payment acceptance, settlements, and financial
    reporting.


    **Payment Acceptance:** In-person payment acceptance supporting `nfc`
    (Tap-to-Pay), `qr` (QR code), `alias` (handle resolution), and
    `card_present` (chip/swipe).


    **Charge Flow:** Create merchant -> Create charge -> Display QR/NFC ->
    Confirm via polling or webhook.


    **Refunds:** Full or partial refunds via `/refunds`.


    **Banking & Settlements:** View settlement history via `/settlements`,
    account balances via `/balances`, and download reconciliation reports in
    CSV, XLSX, or JSON format. Query `/fees` for fee breakdown.
  termsOfService: https://developer.kai2.io/terms
  contact:
    name: Kaito Developer Support
    url: https://developer.kai2.io/support
    email: support@kai2.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
servers:
  - url: https://api.kai2.io
    description: Production
  - url: https://sandbox.api.kai2.io
    description: Sandbox
x-tagGroups:
  - name: Payment Acceptance
    tags:
      - Charges
      - Refunds
      - Merchants
  - name: Banking
    tags:
      - Settlements
      - Balances
      - Reconciliation
      - Fees
tags:
  - name: Charges
    description: Create and manage payment charges
  - name: Refunds
    description: Process refunds
  - name: Merchants
    description: Manage merchant accounts
  - name: Settlements
    description: View settlement history
  - name: Balances
    description: View account balances
  - name: Reconciliation
    description: Download reconciliation reports
  - name: Fees
    description: View fee breakdown
paths:
  /v1/charges:
    post:
      summary: Create merchant charge
      tags:
        - Charges
      description: |
        Creates a charge for in-person payment acceptance.

        **Payment methods:**
        - `nfc`: Returns NFC payload for Tap-to-Pay
        - `qr`: Returns QR code data and image URL
        - `alias`: Resolves alias and creates charge
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChargeCreateRequest'
      responses:
        '201':
          description: Charge created
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Charge'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
    get:
      summary: List charges
      tags:
        - Charges
      parameters:
        - in: query
          name: merchantId
          schema:
            type: string
        - in: query
          name: status
          schema:
            $ref: '#/components/schemas/ChargeStatus'
        - in: query
          name: createdAfter
          schema:
            type: string
            format: date-time
        - in: query
          name: createdBefore
          schema:
            type: string
            format: date-time
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: cursor
          schema:
            type: string
      responses:
        '200':
          description: Charges list
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Charge'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
  /v1/charges/{chargeId}:
    get:
      summary: Get charge
      tags:
        - Charges
      parameters:
        - name: chargeId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Charge details
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Charge'
        '404':
          $ref: '#/components/responses/NotFoundError'
    delete:
      summary: Cancel charge
      tags:
        - Charges
      description: Cancel a pending charge. Only works if status is `requires_payment`.
      parameters:
        - name: chargeId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Charge cancelled
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Charge'
  /v1/refunds:
    post:
      summary: Create refund
      tags:
        - Refunds
      description: Refund a charge (full or partial)
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RefundCreateRequest'
      responses:
        '201':
          description: Refund created
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Refund'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
    get:
      summary: List refunds
      tags:
        - Refunds
      parameters:
        - in: query
          name: chargeId
          schema:
            type: string
        - in: query
          name: status
          schema:
            $ref: '#/components/schemas/RefundStatus'
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: cursor
          schema:
            type: string
      responses:
        '200':
          description: Refunds list
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Refund'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
  /v1/merchants:
    post:
      summary: Create merchant
      tags:
        - Merchants
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MerchantCreateRequest'
      responses:
        '201':
          description: Merchant created
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Merchant'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
    get:
      summary: List merchants
      tags:
        - Merchants
      parameters:
        - in: query
          name: status
          schema:
            $ref: '#/components/schemas/MerchantStatus'
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: cursor
          schema:
            type: string
      responses:
        '200':
          description: Merchants list
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Merchant'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
  /v1/merchants/{merchantId}:
    get:
      summary: Get merchant
      tags:
        - Merchants
      parameters:
        - name: merchantId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Merchant details
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Merchant'
        '404':
          $ref: '#/components/responses/NotFoundError'
  /v1/settlements:
    get:
      summary: List settlements
      tags:
        - Settlements
      parameters:
        - in: query
          name: from
          schema:
            type: string
            format: date
        - in: query
          name: to
          schema:
            type: string
            format: date
        - in: query
          name: status
          schema:
            $ref: '#/components/schemas/SettlementStatus'
        - in: query
          name: currency
          schema:
            type: string
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: cursor
          schema:
            type: string
      responses:
        '200':
          description: Settlements list
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SettlementListResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
  /v1/settlements/{settlementId}:
    get:
      summary: Get settlement by ID
      tags:
        - Settlements
      parameters:
        - name: settlementId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Settlement details
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Settlement'
        '404':
          $ref: '#/components/responses/NotFoundError'
  /v1/balances:
    get:
      summary: Get balance accounts
      tags:
        - Balances
      responses:
        '200':
          description: Balance accounts
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/BalanceAccount'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
  /v1/reconciliation:
    get:
      summary: Download reconciliation report
      tags:
        - Reconciliation
      parameters:
        - in: query
          name: date
          required: true
          schema:
            type: string
            format: date
        - in: query
          name: format
          schema:
            $ref: '#/components/schemas/ReportFormat'
        - in: query
          name: timezone
          schema:
            type: string
            default: UTC
      responses:
        '200':
          description: Report file
          content:
            text/csv:
              schema:
                type: string
                format: binary
            application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
              schema:
                type: string
                format: binary
            application/json:
              schema:
                type: object
        '401':
          $ref: '#/components/responses/UnauthorizedError'
  /v1/fees:
    get:
      summary: Get fee summary
      tags:
        - Fees
      parameters:
        - in: query
          name: from
          required: true
          schema:
            type: string
            format: date
        - in: query
          name: to
          required: true
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Fee summary
          headers:
            X-Trace-Id:
              schema:
                $ref: '#/components/schemas/TraceId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeeSummary'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
components:
  securitySchemes:
    oAuth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: https://auth.kai2.io/oauth2/token
          scopes:
            acceptance:write: Create charges, refunds, and merchants
            acceptance:read: Read charges, refunds, and merchants
            banking:read: Read settlements, balances, and reports
      description: OAuth2 client credentials. All requests must also be made over mTLS.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
      description: A unique key to make POST requests idempotent.
  responses:
    UnauthorizedError:
      description: Access token is missing or invalid.
    NotFoundError:
      description: The requested resource does not exist.
  schemas:
    TraceId:
      type: string
      description: Correlation id for troubleshooting
      example: trc_01JH8K5P3V9M2K5Q7W6J3Z1A9B
    Pagination:
      type: object
      properties:
        nextCursor:
          type: string
          nullable: true
          example: cursor_abc123
    ErrorResponse:
      type: object
      required:
        - error
        - traceId
      properties:
        traceId:
          $ref: '#/components/schemas/TraceId'
        error:
          type: object
          properties:
            code:
              type: string
              example: INVALID_REQUEST
            message:
              type: string
              example: Invalid merchant ID
            details:
              type: object
              additionalProperties: true
    Address:
      type: object
      properties:
        line1:
          type: string
        city:
          type: string
        state:
          type: string
        postalCode:
          type: string
        country:
          type: string
    PaymentMethodType:
      type: string
      enum:
        - nfc
        - qr
        - alias
        - card_present
      description: |
        - nfc: Tap-to-Pay via NFC
        - qr: QR code payment
        - alias: Alias/handle resolution
        - card_present: Card present (chip/swipe)
    ChargeStatus:
      type: string
      enum:
        - requires_payment
        - processing
        - succeeded
        - failed
        - cancelled
        - refunded
    QrData:
      type: object
      properties:
        data:
          type: string
          description: QR payload (for rendering)
        imageUrl:
          type: string
          format: uri
          description: Pre-rendered QR image URL
        expiresAt:
          type: string
          format: date-time
    PayerInfo:
      type: object
      properties:
        walletId:
          type: string
        displayName:
          type: string
    ChargeCreateRequest:
      type: object
      required:
        - merchantId
        - amount
        - currency
        - paymentMethod
      properties:
        merchantId:
          type: string
          example: mrc_01JH...
        amount:
          type: number
          example: 150
        currency:
          type: string
          example: GTQ
        paymentMethod:
          $ref: '#/components/schemas/PaymentMethodType'
        description:
          type: string
          nullable: true
          example: 'Purchase at Store #123'
        reference:
          type: string
          nullable: true
          description: External reference (POS transaction ID, order number)
        expiresIn:
          type: integer
          nullable: true
          description: Expiration time in seconds (default 300 for QR)
          example: 300
        metadata:
          type: object
          additionalProperties: true
          nullable: true
    Charge:
      type: object
      required:
        - chargeId
        - merchantId
        - amount
        - currency
        - status
        - paymentMethod
        - createdAt
      properties:
        chargeId:
          type: string
          example: chg_01JH...
        merchantId:
          type: string
        amount:
          type: number
        currency:
          type: string
        status:
          $ref: '#/components/schemas/ChargeStatus'
        paymentMethod:
          $ref: '#/components/schemas/PaymentMethodType'
        description:
          type: string
          nullable: true
        reference:
          type: string
          nullable: true
        qr:
          $ref: '#/components/schemas/QrData'
        payer:
          $ref: '#/components/schemas/PayerInfo'
        txHash:
          type: string
          nullable: true
        providerRef:
          type: string
          nullable: true
        createdAt:
          type: string
          format: date-time
        paidAt:
          type: string
          format: date-time
          nullable: true
    RefundReason:
      type: string
      enum:
        - duplicate
        - fraudulent
        - requested_by_customer
        - other
    RefundStatus:
      type: string
      enum:
        - pending
        - succeeded
        - failed
    RefundCreateRequest:
      type: object
      required:
        - chargeId
      properties:
        chargeId:
          type: string
        amount:
          type: number
          nullable: true
          description: Partial refund amount (full refund if omitted)
        reason:
          $ref: '#/components/schemas/RefundReason'
    Refund:
      type: object
      required:
        - refundId
        - chargeId
        - amount
        - status
        - createdAt
      properties:
        refundId:
          type: string
          example: rfd_01JH...
        chargeId:
          type: string
        amount:
          type: number
        currency:
          type: string
        status:
          $ref: '#/components/schemas/RefundStatus'
        reason:
          $ref: '#/components/schemas/RefundReason'
        createdAt:
          type: string
          format: date-time
    MerchantStatus:
      type: string
      enum:
        - active
        - suspended
        - pending_review
    MerchantCreateRequest:
      type: object
      required:
        - name
        - country
        - mcc
      properties:
        name:
          type: string
          example: Coffee Shop
        country:
          type: string
          example: GT
        mcc:
          type: string
          description: Merchant Category Code
          example: '5812'
        address:
          $ref: '#/components/schemas/Address'
        metadata:
          type: object
          additionalProperties: true
    Merchant:
      type: object
      required:
        - merchantId
        - name
        - country
        - mcc
        - status
        - createdAt
      properties:
        merchantId:
          type: string
          example: mrc_01JH...
        name:
          type: string
        country:
          type: string
        mcc:
          type: string
        status:
          $ref: '#/components/schemas/MerchantStatus'
        address:
          $ref: '#/components/schemas/Address'
        createdAt:
          type: string
          format: date-time
    SettlementStatus:
      type: string
      enum:
        - pending
        - processing
        - completed
        - failed
    BankAccountInfo:
      type: object
      properties:
        last4:
          type: string
          example: '1234'
        bankName:
          type: string
          example: Bank of America
    Settlement:
      type: object
      required:
        - settlementId
        - date
        - currency
        - gross
        - fees
        - net
        - status
      properties:
        settlementId:
          type: string
          example: stl_01JH...
        date:
          type: string
          format: date
        currency:
          type: string
          example: USD
        gross:
          type: number
          description: Total amount before fees
          example: 10000
        fees:
          type: number
          description: Total fees deducted
          example: 150
        net:
          type: number
          description: Amount settled (gross - fees)
          example: 9850
        status:
          $ref: '#/components/schemas/SettlementStatus'
        transactionCount:
          type: integer
          description: Number of transactions included
          example: 250
        bankAccount:
          $ref: '#/components/schemas/BankAccountInfo'
        settledAt:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
    SettlementSummary:
      type: object
      properties:
        totalGross:
          type: number
        totalFees:
          type: number
        totalNet:
          type: number
        count:
          type: integer
    SettlementListResponse:
      type: object
      required:
        - items
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Settlement'
        pagination:
          $ref: '#/components/schemas/Pagination'
        summary:
          $ref: '#/components/schemas/SettlementSummary'
    BalanceAccount:
      type: object
      required:
        - accountId
        - currency
        - available
        - pending
      properties:
        accountId:
          type: string
          example: bal_01JH...
        currency:
          type: string
          example: USD
        available:
          type: number
          description: Available for payout
          example: 50000
        pending:
          type: number
          description: Pending settlement
          example: 5000
        reserved:
          type: number
          nullable: true
          description: Reserved for disputes/chargebacks
          example: 500
        updatedAt:
          type: string
          format: date-time
    ReportFormat:
      type: string
      enum:
        - csv
        - xlsx
        - json
    FeeType:
      type: string
      enum:
        - processing
        - network
        - fx
        - payout
        - kaito
        - partner
    FeeBreakdown:
      type: object
      required:
        - type
        - amount
        - currency
      properties:
        type:
          $ref: '#/components/schemas/FeeType'
        amount:
          type: number
          example: 2.5
        currency:
          type: string
          example: USD
        description:
          type: string
          nullable: true
          example: Card processing fee (2.9% + $0.30)
    FeeSummary:
      type: object
      required:
        - from
        - to
        - currency
        - items
        - total
      properties:
        from:
          type: string
          format: date
        to:
          type: string
          format: date
        currency:
          type: string
        items:
          type: array
          items:
            $ref: '#/components/schemas/FeeBreakdown'
        total:
          type: number
security:
  - oAuth2: []
