{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/elocuenti-com/json-schema/elocuenti-com-purchase-confirmation-body-schema.json",
  "title": "PurchaseConfirmationBody",
  "description": "Send at least one of `order_id` (an order in Elocuenti) or `external_reference` (your own order number). `idempotency_key` is optional: without it the key is `order_id` (as text) or else `external_reference`, within your business, so a retry never writes to the buyer twice.",
  "x-generated": "2026-11-06",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/elocuenti-com-openapi.json#/components/schemas/PurchaseConfirmationBody",
  "type": "object",
  "properties": {
    "phone": {
      "type": "string",
      "minLength": 10,
      "description": "Customer phone in E.164 format.",
      "title": "Phone"
    },
    "template_name": {
      "type": "string",
      "minLength": 1,
      "description": "WhatsApp template name to send.",
      "title": "Template Name"
    },
    "template_params": {
      "description": "Optional template variables. Keys must match the template's `parameter_mapping` (e.g. `customer_name`, `order_id`) or be positional (\"1\", \"2\", ...). Merged with defaults (`customer_name`, `order_id`, `order_total`).",
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": true
        },
        {
          "type": "null"
        }
      ],
      "title": "Template Params"
    },
    "order_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "UUID of the confirmed order. Optional — omit for ticketing/marketplace flows that don't sync orders into Elocuenti.",
      "title": "Order Id"
    },
    "external_reference": {
      "description": "Caller's own ID for the order (any string). Used for dedup when no order_id is available.",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 255
        },
        {
          "type": "null"
        }
      ],
      "title": "External Reference"
    },
    "idempotency_key": {
      "description": "Explicit dedup key. Defaults to order_id (as text) or external_reference. To send AGAIN for an order that already has a row (e.g. to re-deliver a corrected link), pass a different key such as `<external_reference>-resend-1`: dedup is per (tenant, idempotency_key) only.",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 255
        },
        {
          "type": "null"
        }
      ],
      "title": "Idempotency Key"
    },
    "batch_id": {
      "description": "Optional caller-supplied batch identifier. Echoed verbatim into the structured logs so a whole send can be reconciled per batch.",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 128
        },
        {
          "type": "null"
        }
      ],
      "title": "Batch Id"
    },
    "order_total": {
      "description": "Order total; surfaced to templates as a formatted `order_total` variable.",
      "anyOf": [
        {
          "type": "number",
          "minimum": 0
        },
        {
          "type": "null"
        }
      ],
      "title": "Order Total"
    },
    "currency": {
      "description": "ISO 4217 currency code for order_total (e.g. COP, MXN).",
      "anyOf": [
        {
          "type": "string",
          "minLength": 3,
          "maxLength": 3
        },
        {
          "type": "null"
        }
      ],
      "title": "Currency"
    },
    "customer_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Customer Name"
    },
    "customer_email": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Customer Email"
    },
    "fallback_template": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Optional fallback template name if the primary is not found.",
      "title": "Fallback Template"
    },
    "from": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Optional. The business WhatsApp number to send from, in E.164 (e.g. `+573001234567`). Omit it to send from the business default. A number that is not one of the business's active numbers is refused with 422 `from_number_not_available`.",
      "title": "From"
    }
  },
  "required": [
    "phone",
    "template_name"
  ]
}