openapi: 3.1.0
info:
  title: Tango AR Inbound (Cash Receipt Confirmation) API
  version: "1.0"
  description: |
    Async REST API: client posts AR check confirmation records to Tango.
    Tango updates the Receivables tab and billing status. Status response shape
    differs slightly from other Tango APIs — `COMPLETED` results include a
    flat `errors[]` array for both successes and partial failures.
  x-direction: inbound
  x-source: Client System
  x-destination: Tango
servers:
  - url: https://api.tangoanalytics.com
    description: Production
  - url: https://testapi.tangoanalytics.com
    description: Test (SIT/UAT)
tags:
  - name: AR Receivables
  - name: Status
paths:
  /v1/leasemgmt/receivables:
    put:
      summary: Submit AR receivable confirmations (async)
      operationId: putARReceivablesBatch
      tags: [AR Receivables]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ARBatchRequest"
            examples:
              default:
                value:
                  records:
                    - lease_receivable_id: "92392"
                      invoice_id: "92392"
                      invoice_number: "98733"
                      receivable_status: "RECEIVED"
                      check_number: "2369"
                      check_date: "07/16/2020"
                      check_amount: "510.00"
                      applied_amount: "510.00"
                      late_fee_amount: "10.00"
                      last_late_fee_date: "07/16/2020"
      responses:
        "200":
          description: Accepted for async processing.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Poll processing status by gu_id
      operationId: getBatchStatus
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Status payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/StatusResponse"
components:
  securitySchemes:
    xClientHeader: { type: apiKey, in: header, name: x-client }
    xApiKeyHeader: { type: apiKey, in: header, name: x-api-key }
  parameters:
    XClient:
      name: x-client
      in: header
      required: true
      schema: { type: string }
    XApiKey:
      name: x-api-key
      in: header
      required: true
      schema: { type: string }
  schemas:
    ARBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/ARReceivableRecord"
    ARReceivableRecord:
      type: object
      required:
        - lease_receivable_id
        - receivable_status
        - check_number
        - check_date
        - check_amount
        - applied_amount
      properties:
        lease_receivable_id:
          type: number
          description: Tango unique billing identifier.
        invoice_id: { type: string }
        invoice_number: { type: string }
        receivable_status:
          type: string
          description: Charge status, e.g., `RECEIVED` / `PAID` / `VOID`.
          enum: [PAID, VOID]
        check_number: { type: string }
        check_date: { type: string, description: "MM/DD/YYYY." }
        check_amount: { type: number }
        applied_amount: { type: number }
        late_fee_amount:
          type: number
          description: |
            Required when sending a late-fee payload along with lease_receivable_id;
            see validation #11.
        last_late_fee_date:
          type: string
          description: "MM/DD/YYYY. Required when late_fee_amount is present."
    AcceptedResponse:
      type: object
      required: [status, gu_id]
      properties:
        status: { type: string, enum: [OK, Error] }
        status_message: { type: string }
        gu_id: { type: string, format: uuid }
    StatusResponse:
      oneOf:
        - type: object
          properties:
            status: { type: string, const: PROCESSING }
        - type: object
          required: [status]
          properties:
            status: { type: string, const: Completed }
            status_message: { type: string }
            errors:
              type: array
              items:
                type: object
                required: [record_key, errormessage]
                properties:
                  record_key: { type: string }
                  record_value: { type: string }
                  errormessage: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
