{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chatcommerce360.com/ucp/schemas/shopping/b2b.json",
  "name": "com.chatcommerce360.shopping.b2b",
  "version": "2026-09-24",
  "title": "ChatCommerce360 B2B purchasing",
  "description": "B2B purchasing context for UCP checkout and order: purchase-order number, cost center, the buyer's tax-exemption certificate, and the buyer organization's approval policy and state.",
  "requires": {
    "protocol": { "min": "2026-08-25" },
    "capabilities": {
      "dev.ucp.shopping.checkout": { "min": "2026-08-25" },
      "dev.ucp.shopping.order": { "min": "2026-08-25" }
    }
  },
  "$defs": {
    "reference": {
      "type": "string",
      "pattern": "^[\\x20-\\x7E]{1,64}$",
      "description": "A buyer-supplied reference: 1-64 printable ASCII characters."
    },
    "tax_exemption": {
      "type": "object",
      "description": "Whether the buyer's tax-exemption certificate applies to this purchase. Set by the business; tax totals already reflect it.",
      "required": ["applied"],
      "properties": {
        "applied": { "type": "boolean" },
        "certificate": {
          "type": "object",
          "required": ["number", "kind"],
          "properties": {
            "number": { "type": "string", "description": "Certificate number on file." },
            "kind": { "type": "string", "description": "Well-known values: resale, nonprofit, government." },
            "region": { "type": "string", "description": "Jurisdiction the certificate covers; absent = all." },
            "valid_to": { "type": "string", "format": "date-time" }
          }
        }
      }
    },
    "checkout_approval": {
      "type": "object",
      "description": "The buyer organization's purchase-approval policy as it applies to this checkout.",
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["not_required", "required", "pending"],
          "description": "required: the total is over the buyer's threshold. pending: the order was placed and awaits approval."
        },
        "threshold": { "$ref": "https://ucp.dev/schemas/common/types/amount.json", "description": "Totals above this amount need approval." },
        "required_approvals": { "type": "integer", "minimum": 1 },
        "on_complete": {
          "type": "string",
          "enum": ["pending_approval", "escalate"],
          "description": "What completing does when approval is required: place the order pending approval, or escalate to the buyer on the storefront."
        }
      }
    },
    "order_approval": {
      "type": "object",
      "required": ["status"],
      "properties": {
        "status": { "type": "string", "enum": ["not_required", "pending", "approved", "rejected"] },
        "threshold": { "$ref": "https://ucp.dev/schemas/common/types/amount.json" },
        "required_approvals": { "type": "integer", "minimum": 1 },
        "approvals": { "type": "integer", "minimum": 0, "description": "Distinct approvals recorded so far." },
        "decided_at": { "type": "string", "format": "date-time" }
      }
    },
    "checkout_b2b": {
      "type": "object",
      "properties": {
        "po_number": { "$ref": "#/$defs/reference", "description": "Buyer purchase-order number.", "ucp_request": { "create": "optional", "update": "optional" } },
        "cost_center": { "$ref": "#/$defs/reference", "description": "Cost center / department the purchase is charged to.", "ucp_request": { "create": "optional", "update": "optional" } },
        "tax_exemption": { "$ref": "#/$defs/tax_exemption", "ucp_request": "omit" },
        "approval": { "$ref": "#/$defs/checkout_approval", "ucp_request": "omit" }
      }
    },
    "order_b2b": {
      "type": "object",
      "properties": {
        "po_number": { "$ref": "#/$defs/reference" },
        "cost_center": { "$ref": "#/$defs/reference" },
        "tax_exemption": { "$ref": "#/$defs/tax_exemption" },
        "approval": { "$ref": "#/$defs/order_approval" }
      }
    },
    "dev.ucp.shopping.checkout": {
      "title": "Checkout with B2B purchasing",
      "allOf": [
        { "$ref": "https://ucp.dev/schemas/shopping/checkout.json" },
        { "type": "object", "properties": { "b2b": { "$ref": "#/$defs/checkout_b2b" } } }
      ]
    },
    "dev.ucp.shopping.order": {
      "title": "Order with B2B purchasing",
      "allOf": [
        { "$ref": "https://ucp.dev/schemas/shopping/order.json" },
        { "type": "object", "properties": { "b2b": { "$ref": "#/$defs/order_b2b" } } }
      ]
    }
  }
}
