openapi: 3.0.3
info:
  title: Repzo API - Payments
  version: 1.0.0
  description: OpenAPI specification for Repzo Payments endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /payments:
    get:
      summary: Find payments
      operationId: findPayments
      parameters:
        - in: query
          name: _id
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Payment ID(s) to filter by
        - in: query
          name: creator._id
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Creator ID(s) to filter by
        - in: query
          name: client_id
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Client ID(s) to filter by
        - in: query
          name: from_paytime
          schema:
            type: number
          description: Filter payments from this paytime (timestamp)
        - in: query
          name: to_paytime
          schema:
            type: number
          description: Filter payments to this paytime (timestamp)
        - in: query
          name: custom_status
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Custom status(es) to filter by
        - in: query
          name: payment_type
          schema:
            oneOf:
              - type: string
                enum: ["check", "cash"]
              - type: array
                items:
                  type: string
                  enum: ["check", "cash"]
          description: Payment type(s) to filter by
        - in: query
          name: creator
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Creator(s) to filter by
        - in: query
          name: clients
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Client(s) to filter by
        - in: query
          name: withPrintDetails
          schema:
            type: boolean
          description: Include print details in response
        - in: query
          name: from_updatedAt
          schema:
            type: number
          description: Filter payments updated from this timestamp
        - in: query
          name: serial_number.formatted
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
          description: Formatted serial number(s) to filter by
        - in: query
          name: populatedKeys
          schema:
            type: array
            items:
              type: string
              enum: ["custom_status", "teams", "route"]
          description: Keys to populate in the response
        - in: query
          name: from__id
          schema:
            type: string
          description: Starting ID for pagination
        - in: query
          name: to__id
          schema:
            type: string
          description: Ending ID for pagination
        - in: query
          name: sortBy
          schema:
            type: array
            items:
              type: object
              properties:
                field:
                  type: string
                  enum: ["_id"]
                type:
                  type: string
                  enum: ["asc", "desc"]
          description: Sort criteria
        - in: query
          name: page
          schema:
            type: number
            minimum: 1
          description: Page number for pagination
        - in: query
          name: per_page
          schema:
            type: number
            minimum: 1
            maximum: 100
          description: Number of items per page
      responses:
        "200":
          description: A list of payments
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentFindResult"
    post:
      summary: Create a payment
      operationId: createPayment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PaymentCreateBody"
      responses:
        "201":
          description: Payment created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentCreateResult"
  /payments/{id}:
    get:
      summary: Get a payment by ID
      operationId: getPayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - in: query
          name: withPrintDetails
          schema:
            type: boolean
          description: Include print details in response
        - in: query
          name: populatedKeys
          schema:
            type: array
            items:
              type: string
              enum: ["custom_status", "teams", "route"]
          description: Keys to populate in the response
      responses:
        "200":
          description: Payment details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentGetResult"
    put:
      summary: Update a payment
      operationId: updatePayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PaymentUpdateBody"
      responses:
        "200":
          description: Payment updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentUpdateResult"
components:
  schemas:
    PaymentFindResult:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Payment"
        meta:
          type: object
          properties:
            page:
              type: number
            per_page:
              type: number
            total:
              type: number
            pages:
              type: number
        absolute_total:
          type: number
        page_total:
          type: number
    PaymentCreateBody:
      type: object
      required:
        - amount
        - client_id
        - client_name
        - paytime
        - currency
        - payment_type
        - transaction_processed
        - sync_id
      properties:
        amount:
          type: number
        client_id:
          type: string
        client_name:
          type: string
        time:
          type: number
        serial_number:
          $ref: "#/components/schemas/SerialNumber"
        route:
          type: string
        paytime:
          type: string
        note:
          type: string
        currency:
          type: string
        payment_type:
          type: string
          enum: ["check", "cash"]
        transaction_processed:
          type: boolean
        check:
          $ref: "#/components/schemas/Check"
        LinkedTxn:
          type: object
          properties:
            Txn_serial_number:
              $ref: "#/components/schemas/SerialNumber"
            Txn_invoice_total:
              type: number
            TxnType:
              type: string
              enum: ["refund", "invoice"]
        client_geo_location:
          type: object
          properties:
            lat:
              type: number
            lng:
              type: number
        company_namespace:
          type: array
          items:
            type: string
        integration_meta:
          type: object
          additionalProperties: true
        sync_id:
          type: string
        custom_status:
          type: string
        visit_id:
          type: string
        teams:
          type: array
          items:
            type: string
    PaymentCreateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Payment"
    PaymentGetResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Payment"
    PaymentUpdateBody:
      type: object
      properties:
        integration_meta:
          type: object
          additionalProperties: true
    PaymentUpdateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Payment"
    Payment:
      type: object
      properties:
        _id:
          type: string
        status:
          type: string
          enum: ["consumed", "unconsumed", "partially_consumed"]
        remainder:
          type: number
        amount:
          type: number
        client_id:
          type: string
        client_name:
          type: string
        creator:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
        implemented_by:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
        transaction_processed:
          type: boolean
        time:
          type: number
        serial_number:
          $ref: "#/components/schemas/SerialNumber"
        route:
          type: string
        paytime:
          type: string
        note:
          type: string
        currency:
          type: string
        payment_type:
          type: string
          enum: ["check", "cash"]
        check:
          $ref: "#/components/schemas/Check"
        LinkedTxn:
          type: object
          properties:
            Txn_serial_number:
              $ref: "#/components/schemas/SerialNumber"
            Txn_invoice_total:
              type: number
            TxnType:
              type: string
              enum: ["refund", "invoice"]
        client_geo_location:
          type: object
          properties:
            lat:
              type: number
            lng:
              type: number
        company_namespace:
          type: array
          items:
            type: string
        integration_meta:
          type: object
          additionalProperties: true
        sync_id:
          type: string
        custom_status:
          type: string
        visit_id:
          type: string
        teams:
          type: array
          items:
            type: string
        paymentsData:
          type: object
          properties:
            amount:
              type: number
            paid:
              type: number
            balance:
              type: number
            payments:
              type: array
              items:
                $ref: "#/components/schemas/PaymentData"
        ending_balance:
          type: number
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        __v:
          type: number
    SerialNumber:
      type: object
      properties:
        formatted:
          type: string
        raw:
          type: number
    AdminCreator:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        type:
          type: string
          enum: ["admin"]
    RepCreator:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        type:
          type: string
          enum: ["rep"]
    Check:
      type: object
      properties:
        _id:
          type: string
        drawer_name:
          type: string
        bank:
          type: string
        bank_branch:
          type: string
        check_number:
          type: number
        check_date:
          type: string
        photo:
          type: string
        caption:
          type: string
        photo_meta:
          type: object
          properties:
            device_orientation:
              type: number
            height:
              type: number
            width:
              type: number
    PaymentData:
      type: object
      properties:
        payment_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        payment_id:
          type: string
        invoice_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        return_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        fullinvoice_id:
          type: string
        refund_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        refund_id:
          type: string
        adjustment_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        adjustment_id:
          type: string
        adjustment_account_id:
          type: string
        view_serial_number:
          $ref: "#/components/schemas/SerialNumber"
        type:
          type: string
          enum: ["invoice", "payment", "return_invoice", "refund", "adjustment"]
        amount:
          type: number
        account_index:
          type: number
        is_linked_txn:
          type: boolean
        is_original:
          type: boolean
      required:
        - amount
