{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://comercioia.cl/ucp/schemas/tax_document/2026-10-30.json",
  "name": "cl.comercioia.shopping.tax_document",
  "version": "2026-10-30",
  "title": "Chilean Tax Document (boleta / factura)",
  "description": "OPEN PROPOSAL, ready to implement and open for comment. Not yet stable: fields may change before the first stable release. Lets the buyer choose a boleta or a factura at checkout (according to the operation and the buyer's tax status, subject to the legal requirements of the document) and returns the SII electronic tax documents (DTE) issued for the order. Amounts are integer CLP (CLP has no minor unit). Version 2026-10-30 adds the declaration of how the business documents its sales (issuance_model) and the electronic payment receipt as the document of a sale: under SII Res. Ex. 176/2020, which applies art. 54 of the Ley del IVA, the receipt of an electronic payment has the value of a boleta for all legal purposes. It only adds optional fields and prose to 2026-10-16. Spec: https://comercioia.cl/spec/#tax-document",
  "requires": {
    "protocol": { "min": "2026-08-25" },
    "capabilities": {
      "dev.ucp.shopping.checkout": { "min": "2026-08-25" },
      "dev.ucp.shopping.order": { "min": "2026-08-25" }
    }
  },
  "$defs": {
    "rut": {
      "type": "string",
      "pattern": "^[0-9]{1,8}-[0-9Kk]$",
      "description": "Chilean taxpayer ID (RUT) without dots, with a hyphen and the modulo 11 check digit, e.g. 76123456-0. Receivers MUST validate the check digit. The generic RUT 66666666-6 is used only in the cases the SII format allows, not in every boleta.",
      "examples": ["76123456-0", "66666666-6"]
    },
    "document_type": {
      "type": "integer",
      "description": "SII DTE type code: 33 factura electrónica, 34 factura exenta, 39 boleta electrónica, 41 boleta exenta, 52 guía de despacho, 56 nota de débito, 61 nota de crédito.",
      "examples": [39, 33, 41, 34]
    },
    "receiver": {
      "type": "object",
      "description": "Receiver of the document: the buying company on a factura, or the payer (who pays, who may differ from the buyer) on a boleta. Required for a factura, with rut, razon_social, giro, direccion and comuna. Required on a boleta for a sale covered by SII Res. Ex. 44/2025 whose value exceeds the 135 UF threshold, with at least the payer's rut and razon_social; on other boletas it is optional. Lengths follow the SII DTE and boleta formats.",
      "required": ["rut", "razon_social"],
      "properties": {
        "rut": {
          "$ref": "#/$defs/rut",
          "description": "The receiver's real RUT (SII RUTRecep). MUST NOT be the generic 66666666-6."
        },
        "razon_social": {
          "type": "string",
          "maxLength": 100,
          "description": "Legal name of a company or, for a person, their full name (nombres y apellidos). SII RznSocRecep."
        },
        "giro": { "type": "string", "maxLength": 40, "description": "Receiver's line of business as registered with the SII. Factura only." },
        "direccion": { "type": "string", "maxLength": 70 },
        "comuna": { "type": "string", "maxLength": 20 },
        "ciudad": { "type": "string", "maxLength": 20 },
        "email": { "type": "string", "format": "email", "description": "Address that receives the DTE." }
      }
    },
    "reference": {
      "type": "object",
      "description": "A document the tax document must reference, as a line of its SII reference zone (Referencia: TpoDocRef, FolioRef, FchRef, RazonRef). Up to 40 per document.",
      "required": ["type", "number"],
      "properties": {
        "type": {
          "type": "string",
          "pattern": "^([0-9]{1,3}|[A-Za-z]{1,3})$",
          "description": "SII TpoDocRef, as a string. A numeric value MUST be a code listed in the SII Formato DTE, e.g. 801 orden de compra, 802 nota de pedido, 803 contrato, 52 guía de despacho electrónica, 33 factura electrónica. An alphabetic value of up to 3 letters is not validated by the SII and may name a non-tax document outside that list, e.g. HES (hoja de entrada de servicios), which some buyers require. Buyers differ: others ask for the HES number under 801 or 802. Businesses MUST send the code the buyer asked for, unchanged.",
          "examples": ["801", "802", "803", "HES", "52"]
        },
        "number": {
          "type": "string",
          "minLength": 1,
          "maxLength": 18,
          "description": "SII FolioRef: the referenced document's number, exactly as the buyer issued it, with no added prefixes or characters. Alphanumeric only for non-tax documents (800 codes or alphabetic types); the folio of a tax document, such as a guía de despacho, is digits only.",
          "examples": ["4500195544", "OC-2026-0457", "1001266280"]
        },
        "date": {
          "type": "string",
          "format": "date",
          "description": "SII FchRef: date of the referenced document, YYYY-MM-DD. Mandatory on a factura; the boleta format has no reference date."
        },
        "reason": {
          "type": "string",
          "maxLength": 90,
          "description": "SII RazonRef: free text printed with the reference."
        }
      }
    },
    "payment_method": {
      "type": "integer",
      "description": "SII MedioPago of a boleta (Formato Boletas Electrónicas v4.2): 1 efectivo, 2 pago electrónico, 3 transferencia electrónica, 4 cheque, 5 otro. Mandatory and printed on a boleta for a sale covered by SII Res. Ex. 44/2025 whose value exceeds the 135 UF threshold. Businesses MUST treat unknown values as 5.",
      "examples": [2, 3, 1, 4, 5]
    },
    "tax_document_request": {
      "type": "object",
      "description": "The buyer's choice of tax document. When absent, the business issues the document it declares (issuance_model).",
      "properties": {
        "document_choice": {
          "type": "string",
          "description": "'boleta' (default) or 'factura', according to the operation and the buyer's tax status. The choice at checkout is subject to the legal requirements of the document. 'boleta' means not a factura: the consumer document. At a business whose issuance_model is payment_receipt, that document is the electronic payment receipt when the sale is paid electronically; a cash sale or a bank transfer between accounts still needs a boleta. Businesses MUST treat unknown values as 'boleta' and say so in messages[].",
          "examples": ["boleta", "factura"]
        },
        "receiver": { "$ref": "#/$defs/receiver" },
        "references": {
          "type": "array",
          "maxItems": 40,
          "items": { "$ref": "#/$defs/reference" },
          "description": "References the buyer requires on its document, typically a factura: purchase order, HES, contract or dispatch guide. Businesses MUST either print them or reject the checkout with a message; they MUST NOT silently drop them."
        },
        "payment_method": {
          "$ref": "#/$defs/payment_method",
          "description": "SII MedioPago the business will print on the boleta. Businesses derive it from the payment handler used and SHOULD echo it in responses when the boleta is for a sale covered by SII Res. Ex. 44/2025 whose value exceeds the 135 UF threshold; a platform MAY send it only when the buyer pays outside the negotiated payment handlers, e.g. cash on delivery."
        }
      },
      "if": {
        "properties": { "document_choice": { "const": "factura" } },
        "required": ["document_choice"]
      },
      "then": {
        "required": ["receiver"],
        "properties": {
          "receiver": { "required": ["rut", "razon_social", "giro", "direccion", "comuna"] },
          "references": { "items": { "required": ["date"] } }
        }
      }
    },
    "issued_document": {
      "type": "object",
      "description": "An SII electronic tax document issued for the order.",
      "required": ["type", "folio", "issuer_rut", "issued_at", "total"],
      "properties": {
        "type": { "$ref": "#/$defs/document_type" },
        "folio": { "type": "integer", "minimum": 1 },
        "issuer_rut": { "$ref": "#/$defs/rut" },
        "receiver_rut": {
          "$ref": "#/$defs/rut",
          "description": "The generic RUT 66666666-6 is used in the cases the SII format allows, for non-periodic, non-residential sales or services when the RUT is unknown and no applicable internal identifier exists. It is not a universal rule for every boleta. It is never used on a boleta for a sale covered by SII Res. Ex. 44/2025 whose value exceeds the 135 UF threshold."
        },
        "issued_at": { "type": "string", "format": "date-time" },
        "total": { "type": "integer", "minimum": 0, "description": "Total in integer CLP, VAT included." },
        "net": { "type": "integer", "minimum": 0 },
        "iva": { "type": "integer", "minimum": 0 },
        "exempt": { "type": "integer", "minimum": 0 },
        "payment_method": {
          "$ref": "#/$defs/payment_method",
          "description": "SII MedioPago printed on the boleta. Present on every boleta for a sale covered by SII Res. Ex. 44/2025 whose value exceeds the 135 UF threshold."
        },
        "references": {
          "type": "array",
          "maxItems": 40,
          "items": { "$ref": "#/$defs/reference" },
          "description": "References as printed in the issued document, in line order (NroLinRef)."
        },
        "issue_trigger": {
          "type": "string",
          "description": "Event that triggered issuance. In sales of goods, issuance is tied to their actual or symbolic delivery (DL 825 art. 55); for services, the boleta is issued when the remuneration is received or made available, and the factura follows the rules of its tax period. payment_confirmed can be an operational option but does not replace those rules. The business must configure the applicable event.",
          "examples": ["payment_confirmed", "dispatched", "delivered"]
        },
        "sii_track_id": { "type": "string", "description": "SII submission tracking ID." },
        "sii_status": {
          "type": "string",
          "description": "Latest known SII status of the document.",
          "examples": ["pending", "accepted", "accepted_with_objections", "rejected"]
        },
        "representation_url": {
          "type": "string",
          "format": "uri",
          "description": "https link to a printable representation (PDF or HTML) the buyer can keep."
        }
      }
    },
    "tax_document_config": {
      "type": "object",
      "description": "Business configuration of the extension: documents the shape of the config member of the tax_document entry in the business profile (capabilities). The capability entry does not enforce this $ref. The business declares it; it is not verified against the SII.",
      "properties": {
        "issuance_model": {
          "type": "string",
          "description": "The emission model the business declared to the SII. 'payment_receipt': the receipt of an electronic payment replaces the boleta for electronic payments (SII Res. Ex. 176/2020, applying art. 54 of the Ley del IVA); cash and bank transfers between accounts still need a boleta. 'always_boleta': the business issues a boleta for every sale, even when it receives an electronic payment. Issuing both documents for one sale duplicates the Registro de Ventas. Open vocabulary: receivers MUST treat unknown values as unknown and not assume a boleta.",
          "examples": ["payment_receipt", "always_boleta"]
        }
      }
    },
    "payment_receipt": {
      "type": "object",
      "description": "The electronic payment receipt that is the document of a sale at a business whose issuance_model is payment_receipt. It has the value of a boleta de ventas y servicios for all legal purposes (SII Res. Ex. 176/2020, which applies art. 54 of the Ley del IVA and whose terminal definition includes internet sales). It is not a DTE and has no folio. In the Registro de Ventas it is a line with SII code 48, which is not a DTE type. A refund is annulled through the payment terminal; a credit note (DTE 61) identifying the receipt is only the fallback. Whether a sale above 135 UF (SII Res. Ex. 44/2025) at a payment_receipt business must carry a boleta is left open by this version.",
      "required": ["operator", "amount_clp"],
      "properties": {
        "operator": {
          "type": "string",
          "description": "The payment operator that issued the receipt.",
          "examples": ["mercadopago"]
        },
        "authorization_code": {
          "type": "string",
          "description": "Authorization code of the electronic payment, as printed on the receipt.",
          "examples": ["1234567890"]
        },
        "legend": {
          "type": "string",
          "description": "The legend the receipt carries stating its legal value.",
          "examples": ["Válido como Boleta"]
        },
        "amount_clp": {
          "type": "integer",
          "minimum": 0,
          "description": "Total of the receipt in integer CLP."
        }
      }
    },
    "dev.ucp.shopping.checkout": {
      "title": "Checkout with Chilean tax document",
      "description": "Checkout extended with the buyer's boleta or factura choice.",
      "allOf": [
        { "$ref": "https://ucp.dev/2026-08-25/schemas/shopping/checkout.json" },
        {
          "type": "object",
          "properties": {
            "tax_document": {
              "$ref": "#/$defs/tax_document_request",
              "ucp_request": { "create": "optional", "update": "optional", "complete": "optional" }
            }
          }
        }
      ]
    },
    "dev.ucp.shopping.order": {
      "title": "Order with Chilean tax documents",
      "description": "Order extended with the SII documents issued for it.",
      "allOf": [
        { "$ref": "https://ucp.dev/2026-08-25/schemas/shopping/order.json" },
        {
          "type": "object",
          "properties": {
            "tax_documents": {
              "type": "array",
              "items": { "$ref": "#/$defs/issued_document" },
              "description": "SII documents issued for this order, in issue order."
            },
            "payment_receipt": {
              "$ref": "#/$defs/payment_receipt",
              "description": "Present when the document of the sale is the electronic payment receipt instead of a DTE. A receipt and a boleta for the same sale duplicate the Registro de Ventas."
            }
          }
        }
      ]
    }
  }
}
