{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/timbrix-mx/json-schema/timbrix-mx-invoice-response-dto-schema.json",
  "title": "InvoiceResponseDto",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/timbrix-mx-openapi.yaml#/components/schemas/InvoiceResponseDto",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Timbrix invoice record ID"
    },
    "uuid": {
      "type": "string",
      "description": "Folio fiscal UUID asignado por el SAT vía PAC"
    },
    "status": {
      "type": "string",
      "enum": [
        "vigente",
        "cancelado"
      ],
      "description": "Estado fiscal del CFDI registrado en Timbrix: vigente o cancelado. Antes de TIM-243 este campo era siempre \"valid\". Con una cancelación pendiente (cancellationStatus: pendiente) cuyo plazo de respuesta del receptor ya venció, el SAT pudo haberlo cancelado automáticamente; confírmalo en el portal del SAT."
    },
    "cancellationStatus": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "pendiente",
        "rechazada",
        "en_proceso"
      ],
      "description": "Latest cancellation attempt's status, only while the invoice is still vigente. null if never attempted or already cancelado. A pendiente past the receptor's response deadline may already be cancelado at the SAT. en_proceso: the cancellation was sent and its outcome is being confirmed with the SAT; don't treat the CFDI as vigente yet."
    },
    "cancellationDesynced": {
      "type": "boolean",
      "description": "true when a cancellation was accepted but the invoice status update failed to apply — indicates the invoice may already be cancelled at the SAT even though it still shows vigente here; needs manual reconciliation."
    },
    "type": {
      "type": "string",
      "enum": [
        "I",
        "E",
        "T",
        "P"
      ],
      "description": "I = Ingreso, E = Egreso, T = Traslado, P = Pago"
    },
    "series": {
      "type": "string"
    },
    "folioNumber": {
      "type": "string"
    },
    "total": {
      "type": "number"
    },
    "date": {
      "type": "string"
    },
    "createdAt": {
      "type": "string"
    },
    "environment": {
      "type": "string",
      "enum": [
        "sandbox",
        "production"
      ],
      "description": "Ambiente en el que se timbró el CFDI. Los CFDI de sandbox no tienen validez fiscal ante el SAT."
    },
    "channel": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "web",
        "api",
        "sdk",
        "cli",
        "mcp"
      ],
      "description": "Canal de origen declarado por el cliente con el header X-Timbrix-Client (api si no se envió). null para CFDI anteriores a este campo."
    },
    "rfcReceptor": {
      "type": "string",
      "description": "RFC del receptor del CFDI"
    },
    "relatedCfdis": {
      "description": "Relaciones de este CFDI (CfdisRelacionados). Con tipo 04 apunta al CFDI que sustituye.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/RelatedCfdiResponseDto"
      }
    },
    "substitutedBy": {
      "description": "CFDI cuya relación 04 apunta a este comprobante (sustitutos emitidos).",
      "type": "array",
      "items": {
        "$ref": "#/$defs/SubstituteSummaryResponseDto"
      }
    },
    "paymentMethod": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "PUE",
        "PPD"
      ],
      "description": "Método de pago; null en Traslado, Pago y facturas anteriores a este campo."
    },
    "balance": {
      "type": [
        "object",
        "null"
      ],
      "description": "Saldo pendiente de una factura PPD (total menos complementos de pago vigentes o en timbrado); null en las demás."
    },
    "payment": {
      "description": "Solo en complementos de pago (type P): el pago y las facturas que liquida.",
      "allOf": [
        {
          "$ref": "#/$defs/InvoicePaymentDto"
        }
      ]
    },
    "warnings": {
      "description": "Solo si hay advertencias de la lista 69-B del SAT (receptor Presunto). Un replay por idempotencyKey no las recalcula.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/Lista69bWarningDto"
      }
    }
  },
  "required": [
    "id",
    "uuid",
    "status",
    "cancellationStatus",
    "cancellationDesynced",
    "type",
    "series",
    "folioNumber",
    "total",
    "date",
    "xml",
    "createdAt",
    "environment",
    "channel",
    "rfcReceptor",
    "relatedCfdis",
    "substitutedBy",
    "paymentMethod",
    "balance"
  ],
  "$defs": {
    "InvoicePaymentDocumentDto": {
      "type": "object",
      "properties": {
        "invoiceUuid": {
          "type": "string"
        },
        "installment": {
          "type": "number"
        },
        "previousBalance": {
          "type": "number"
        },
        "amountPaid": {
          "type": "number"
        },
        "remainingBalance": {
          "type": "number"
        }
      },
      "required": [
        "invoiceUuid",
        "installment",
        "previousBalance",
        "amountPaid",
        "remainingBalance"
      ]
    },
    "InvoicePaymentDto": {
      "type": "object",
      "properties": {
        "date": {
          "type": "string"
        },
        "paymentForm": {
          "type": "string"
        },
        "currency": {
          "type": "string"
        },
        "exchange": {
          "type": "number"
        },
        "amount": {
          "type": "number"
        },
        "operationNumber": {
          "type": [
            "object",
            "null"
          ]
        },
        "documents": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/InvoicePaymentDocumentDto"
          }
        }
      },
      "required": [
        "date",
        "paymentForm",
        "currency",
        "exchange",
        "amount",
        "operationNumber",
        "documents"
      ]
    },
    "Lista69bWarningDto": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "RFC_69B_PRESUNTO",
            "RFC_69B_DEFINITIVO"
          ],
          "description": "RFC_69B_PRESUNTO: receptor Presunto. RFC_69B_DEFINITIVO: receptor Definitivo permitido porque el CFDI corrige o complementa uno ya timbrado a ese receptor."
        },
        "rfc": {
          "type": "string"
        },
        "role": {
          "type": "string",
          "enum": [
            "emisor",
            "receptor"
          ]
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "rfc",
        "role",
        "message"
      ]
    },
    "RelatedCfdiResponseDto": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "01",
            "02",
            "03",
            "04",
            "05",
            "06",
            "07"
          ],
          "description": "Clave de c_TipoRelacion (04 = sustitución)"
        },
        "uuids": {
          "description": "UUID de los CFDI relacionados",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "type",
        "uuids"
      ]
    },
    "SubstituteSummaryResponseDto": {
      "type": "object",
      "properties": {
        "uuid": {
          "type": "string"
        },
        "serie": {
          "type": "string"
        },
        "folio": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "vigente",
            "cancelado"
          ]
        }
      },
      "required": [
        "uuid",
        "serie",
        "folio",
        "status"
      ]
    }
  }
}