{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://aha.is/schemas/woocommerce-plugin/order-refund-cancel.request.schema.json",
  "title": "Aha -> plugin order refund or cancel",
  "description": "Body of POST wp-json/aha-is-for-woocommerce/v1/orders/refund-cancel. The request carries the hmac-spec headers, signed with the Connect order key, and X-Aha-Event-Id: refund_<aha_order_id>_<credit_memo_id> or cancel_<aha_order_id>. action refund creates a Woo refund record for refunded_total minus what Woo already refunded. action cancel only sets the cancelled status. status, when set, is applied unless the order is already completed, cancelled, refunded or failed (refunded may override completed).",
  "type": "object",
  "additionalProperties": false,
  "required": ["aha_order_id", "action", "status", "refunded_total", "credit_memo_id", "restock_items", "occurred_at"],
  "properties": {
    "aha_order_id": {
      "description": "The aha_order_id of an order that POST wp-json/aha-is-for-woocommerce/v1/orders created.",
      "type": "string",
      "minLength": 1,
      "maxLength": 64
    },
    "action": {
      "type": "string",
      "enum": ["refund", "cancel"]
    },
    "status": {
      "description": "Target Woo status, or null to keep the current status.",
      "type": ["string", "null"],
      "enum": ["refunded", "cancelled", null]
    },
    "refunded_total": {
      "description": "Order-cumulative refunded amount on Aha (offline + online), in the order currency.",
      "type": "number",
      "minimum": 0
    },
    "credit_memo_id": {
      "description": "Aha credit memo increment id, or null for a plain cancel.",
      "type": ["string", "null"],
      "maxLength": 64
    },
    "restock_items": {
      "description": "Lines whose stock goes back (back_to_stock on Aha).",
      "type": "array",
      "maxItems": 200,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["product_id", "qty"],
        "properties": {
          "product_id": { "type": "integer", "minimum": 1 },
          "variation_id": { "type": "integer", "minimum": 0 },
          "qty": { "description": "Greater than zero (the validator has no exclusiveMinimum; the controller skips qty <= 0).", "type": "number", "minimum": 0 }
        }
      }
    },
    "occurred_at": {
      "description": "ISO 8601 time when the event happened on Aha.",
      "type": "string",
      "format": "date-time"
    }
  }
}
