> ## 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.

# Correct the account or payment method of a sale collection

> Send `account_id`, `payment_method` or both. A new account moves the collection and its paired
account-ledger row (same `batch_uuid`) in one database transaction, so the previous account's balance
drops and the new account's balance rises by the collection amount; a collection recorded without an
account gets its account-ledger row created. A new payment method is written to the collection and its
ledger row alike, which moves the amount between the sale's `payments` buckets. Amount, date and invoice
number never change. Only collections can be corrected, and the account must be active and use the
collection's currency. The response carries the updated transaction and the sale's payment figures
recomputed on the server.



## OpenAPI

````yaml /api-referansi/openapi.json put /v1/sales/{id}/transactions/{transactionId}
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}/transactions/{transactionId}:
    put:
      tags:
        - Sales
      summary: Correct the account or payment method of a sale collection
      description: >-
        Send `account_id`, `payment_method` or both. A new account moves the
        collection and its paired

        account-ledger row (same `batch_uuid`) in one database transaction, so
        the previous account's balance

        drops and the new account's balance rises by the collection amount; a
        collection recorded without an

        account gets its account-ledger row created. A new payment method is
        written to the collection and its

        ledger row alike, which moves the amount between the sale's `payments`
        buckets. Amount, date and invoice

        number never change. Only collections can be corrected, and the account
        must be active and use the

        collection's currency. The response carries the updated transaction and
        the sale's payment figures

        recomputed on the server.
      operationId: sales.updateTransaction
      parameters:
        - name: id
          in: path
          required: true
          description: The sale identifier
          schema:
            type: integer
        - name: transactionId
          in: path
          required: true
          description: The transaction 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:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaleTransactionUpdateRequest'
      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
                      payments:
                        type: object
                        properties:
                          cash:
                            type: number
                          credit_card:
                            type: number
                          bank_account:
                            type: number
                          other:
                            type: number
                          total_collected:
                            type: number
                        required:
                          - cash
                          - credit_card
                          - bank_account
                          - other
                          - total_collected
                      collections_by_account:
                        type: array
                        description: >-
                          Every collection on the sale summed per account, in
                          the sale's own currency, as on the transaction list.
                        items:
                          type: object
                          properties:
                            account_id:
                              type:
                                - integer
                                - 'null'
                            account_name:
                              type:
                                - string
                                - 'null'
                            amount:
                              type: number
                          required:
                            - account_id
                            - account_name
                            - amount
                      transaction:
                        $ref: '#/components/schemas/CustomerTransactionResource'
                    required:
                      - sale_id
                      - remaining_balance
                      - payments
                      - collections_by_account
                      - 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:
    SaleTransactionUpdateRequest:
      type: object
      properties:
        account_id:
          type: integer
          description: >-
            The account the collection was received into. Must be an active
            account of the tenant that uses the collection's currency. Required
            when `payment_method` is omitted.
        payment_method:
          $ref: '#/components/schemas/PaymentMethod'
          description: >-
            The payment method the collection was received with. Required when
            `account_id` is omitted.
      title: SaleTransactionUpdateRequest
    CustomerTransactionResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        tenant_id:
          type:
            - integer
            - 'null'
        batch_uuid:
          type:
            - string
            - 'null'
        customer_id:
          type:
            - integer
            - 'null'
        account_id:
          type:
            - integer
            - 'null'
        account:
          $ref: '#/components/schemas/RelatedAccountResource'
        sale_id:
          type:
            - integer
            - 'null'
        currency_id:
          type:
            - integer
            - 'null'
        currency:
          $ref: '#/components/schemas/RelatedCurrencyResource'
        exchange_rate:
          type: number
        debit:
          type: string
        credit:
          type: string
        amount:
          type: string
        transaction_date:
          type: string
          format: date-time
        type:
          type: string
        payment_method:
          type:
            - string
            - 'null'
        description:
          type:
            - string
            - 'null'
        invoice_number:
          type:
            - string
            - 'null'
        is_installment:
          type: boolean
        due_date:
          type:
            - string
            - 'null'
        installment_number:
          type:
            - integer
            - 'null'
        total_installments:
          type:
            - integer
            - 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - record_state
        - tenant_id
        - batch_uuid
        - customer_id
        - account_id
        - sale_id
        - currency_id
        - exchange_rate
        - debit
        - credit
        - amount
        - transaction_date
        - type
        - payment_method
        - description
        - invoice_number
        - is_installment
        - due_date
        - installment_number
        - total_installments
        - created_at
        - updated_at
      title: CustomerTransactionResource
    PaymentMethod:
      type: string
      enum:
        - bank_account
        - cash
        - transfer_cash
        - other
        - clinic_credit_card
        - credit_card
        - private_insurance
        - sgk
      title: PaymentMethod
    RecordStateResource:
      type: object
      properties:
        is_read_only:
          type: boolean
          description: >-
            True when every write on this record is refused; false does not
            imply the caller may write.
        reason_code:
          type:
            - string
            - 'null'
          description: >-
            Why the record is read-only (`CUSTOMER_ERASED`, or
            `LEAD_NOT_ASSIGNED` for a salesperson on another rep's lead), or
            null when it is not.
      required:
        - is_read_only
        - reason_code
      title: RecordStateResource
    RelatedAccountResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
      required:
        - id
        - name
      title: RelatedAccountResource
    RelatedCurrencyResource:
      type: object
      properties:
        id:
          type: integer
        code:
          type:
            - string
            - 'null'
        symbol:
          type:
            - string
            - 'null'
        name:
          type: string
      required:
        - id
        - code
        - symbol
        - name
      title: RelatedCurrencyResource
  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.