> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flextell.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Add payment to a sale

> Requires `Pay:Sale`. Without `ViewAllSales:Sale` only the caller's own sales are accepted;
any other sale returns 404. On an installment sale, `installment_number` links the collection
to that installment; the collections linked to one installment cannot exceed its amount.



## OpenAPI

````yaml post /v1/sales/{id}/payments
openapi: 3.1.0
info:
  title: Flextell API
  version: 0.0.1
  description: >-
    Flextell REST API referansı. Kimlik doğrulama, scope ve istek kuralları için
    API sekmesindeki rehberlere bakın.
servers:
  - url: https://app.flextell.ai/api
    description: Üretim
security:
  - oauth2: []
  - bearer: []
paths:
  /v1/sales/{id}/payments:
    post:
      tags:
        - Sales
      summary: Add payment to a sale
      description: >-
        Requires `Pay:Sale`. Without `ViewAllSales:Sale` only the caller's own
        sales are accepted;

        any other sale returns 404. On an installment sale, `installment_number`
        links the collection

        to that installment; the collections linked to one installment cannot
        exceed its amount.
      operationId: sales.addPayment
      parameters:
        - name: id
          in: path
          required: true
          description: The sale identifier
          schema:
            type: integer
        - name: X-Tenant
          in: header
          required: true
          description: >-
            Tenant identifier. Send the Tenant ID in the `X-Tenant` header to
            scope API requests to a specific tenant.
          schema:
            type: number
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SalePaymentRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    type: object
                    properties:
                      sale_id:
                        type: string
                      remaining_balance:
                        type: string
                      transaction:
                        type: object
                        properties:
                          id:
                            type:
                              - string
                              - 'null'
                          type:
                            type:
                              - string
                              - 'null'
                          credit:
                            type:
                              - string
                              - 'null'
                          debit:
                            type:
                              - string
                              - 'null'
                          currency_id:
                            type:
                              - string
                              - 'null'
                          exchange_rate:
                            type:
                              - string
                              - 'null'
                          invoice_number:
                            type:
                              - string
                              - 'null'
                          description:
                            type:
                              - string
                              - 'null'
                          is_installment:
                            type: boolean
                          installment_number:
                            type:
                              - string
                              - 'null'
                          total_installments:
                            type:
                              - string
                              - 'null'
                          due_date:
                            type:
                              - string
                              - 'null'
                        required:
                          - id
                          - type
                          - credit
                          - debit
                          - currency_id
                          - exchange_rate
                          - invoice_number
                          - description
                          - is_installment
                          - installment_number
                          - total_installments
                          - due_date
                    required:
                      - sale_id
                      - remaining_balance
                      - transaction
                required:
                  - success
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '404':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error_code:
                    type: string
                    const: RESOURCE_NOT_FOUND
                  message:
                    type: string
                  errors:
                    type: 'null'
                  data:
                    type: 'null'
                required:
                  - success
                  - error_code
                  - message
                  - errors
                  - data
        '409':
          $ref: '#/components/responses/CustomerErasedException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '428':
          description: >-
            Mandatory setup is incomplete. Finish the setup wizard first;
            `data.next_step` names the step to continue with.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    examples:
                      - false
                  error_code:
                    type: string
                    enum:
                      - SETUP_REQUIRED
                    examples:
                      - SETUP_REQUIRED
                  message:
                    type: string
                    examples:
                      - Complete the required setup steps to continue.
                  data:
                    type: object
                    properties:
                      next_step:
                        type:
                          - string
                          - 'null'
                        examples:
                          - clinic_info
                    required:
                      - next_step
                required:
                  - success
                  - error_code
                  - message
                  - data
components:
  schemas:
    SalePaymentRequest:
      type: object
      properties:
        amount:
          type: number
          description: Monetary amount.
          minimum: 0.01
        currency_id:
          type:
            - integer
            - 'null'
          description: Currency of the payment; defaults to the sale currency.
        exchange_rate:
          type:
            - number
            - 'null'
          description: Currency exchange rate.
          minimum: 0
        transaction_date:
          type:
            - string
            - 'null'
          format: date-time
          description: Transaction date (YYYY-MM-DD).
        type:
          type:
            - string
            - 'null'
          description: The transaction type; defaults to a collection when omitted.
          enum:
            - collection
            - payment
            - null
        payment_method:
          $ref: '#/components/schemas/PaymentMethod'
          description: The payment method used for this collection or payment.
        invoice_number:
          type:
            - string
            - 'null'
          description: The invoice number the payment belongs to.
          maxLength: 255
        description:
          type:
            - string
            - 'null'
          description: The description.
          maxLength: 65535
        installment_number:
          type:
            - integer
            - 'null'
          description: >-
            The installment (1-based) of an installment sale this collection
            settles. Must exist in the sale's installment plan, and the
            collections linked to one installment cannot exceed its amount. Not
            allowed for payments.
          minimum: 1
        account_id:
          type:
            - integer
            - 'null'
          description: Account ID.
      required:
        - amount
        - payment_method
      title: SalePaymentRequest
    PaymentMethod:
      type: string
      enum:
        - bank_account
        - cash
        - transfer_cash
        - other
        - clinic_credit_card
        - credit_card
        - private_insurance
        - sgk
      title: PaymentMethod
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    CustomerErasedException:
      description: The patient record has been erased and is read-only
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                description: Always false for an error.
                examples:
                  - false
              error_code:
                type: string
                description: Machine-readable error code.
                examples:
                  - CUSTOMER_ERASED
              message:
                type: string
                description: Localized error message.
            required:
              - success
              - error_code
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://dev.flextell.ai/oauth/authorize
          tokenUrl: https://dev.flextell.ai/oauth/token
          scopes:
            '*': all
    bearer:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.