{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ucp.dev/2026-08-25/schemas/shopping/discount.json",
  "name": "dev.ucp.shopping.discount",
  "title": "Discount Extension",
  "description": "Extends Cart and Checkout with discount support, including discount codes, automatic discounts, and eligibility-triggered provisional discounts.",
  "$defs": {
    "allocation": {
      "type": "object",
      "description": "Breakdown of how a discount amount was allocated to a specific target.",
      "required": [
        "path",
        "amount"
      ],
      "properties": {
        "path": {
          "type": "string",
          "description": "RFC 9535 JSONPath to the allocation target (e.g., '$.line_items[0]', '$.totals[?@.type == \"fulfillment\"]')."
        },
        "amount": {
          "$ref": "https://ucp.dev/2026-08-25/schemas/common/types/amount.json",
          "description": "Amount allocated to this target in ISO 4217 minor units."
        }
      }
    },
    "applied_discount": {
      "type": "object",
      "description": "A discount that was successfully applied.",
      "required": [
        "title",
        "amount"
      ],
      "properties": {
        "code": {
          "type": "string",
          "description": "The discount code. Omitted for automatic discounts."
        },
        "title": {
          "type": "string",
          "description": "Human-readable discount name (e.g., 'Summer Sale 20% Off')."
        },
        "amount": {
          "$ref": "https://ucp.dev/2026-08-25/schemas/common/types/amount.json",
          "description": "Total discount amount in ISO 4217 minor units."
        },
        "automatic": {
          "type": "boolean",
          "default": false,
          "description": "True if applied automatically by merchant rules (no code required)."
        },
        "method": {
          "type": "string",
          "enum": [
            "each",
            "across"
          ],
          "description": "Allocation method. 'each' = applied independently per item. 'across' = split proportionally by value."
        },
        "priority": {
          "type": "integer",
          "minimum": 1,
          "description": "Stacking order for discount calculation. Lower numbers applied first (1 = first)."
        },
        "provisional": {
          "type": "boolean",
          "default": false,
          "description": "True if this discount requires additional verification."
        },
        "eligibility": {
          "$ref": "https://ucp.dev/2026-08-25/schemas/common/types/reverse_domain_name.json",
          "description": "The eligibility claim accepted by the Business for this discount. Corresponds to a value from context.eligibility. Omitted for code-based and non-eligibility automatic discounts."
        },
        "allocations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allocation"
          },
          "description": "Breakdown of where this discount was allocated. Sum of allocation amounts equals total amount."
        }
      }
    },
    "discounts_object": {
      "type": "object",
      "description": "Discount codes input and applied discounts output.",
      "properties": {
        "codes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Discount codes to apply. Case-insensitive. Replaces previously submitted codes. Send empty array to clear."
        },
        "applied": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/applied_discount"
          },
          "description": "Discounts successfully applied (code-based and automatic).",
          "ucp_request": "omit"
        }
      }
    },
    "dev.ucp.shopping.cart": {
      "title": "Cart with Discount",
      "description": "Cart extended with discount capability.",
      "allOf": [
        {
          "$ref": "https://ucp.dev/2026-08-25/schemas/shopping/cart.json"
        },
        {
          "type": "object",
          "properties": {
            "discounts": {
              "$ref": "#/$defs/discounts_object",
              "ucp_request": {
                "create": "optional",
                "update": "optional"
              }
            }
          }
        }
      ]
    },
    "dev.ucp.shopping.checkout": {
      "title": "Checkout with Discount",
      "description": "Checkout extended with discount capability.",
      "allOf": [
        {
          "$ref": "https://ucp.dev/2026-08-25/schemas/shopping/checkout.json"
        },
        {
          "type": "object",
          "properties": {
            "discounts": {
              "$ref": "#/$defs/discounts_object",
              "ucp_request": {
                "create": "optional",
                "update": "optional",
                "complete": "omit"
              }
            }
          }
        }
      ]
    }
  },
  "version": "2026-08-25"
}