{
  "id": "payments.refund",
  "version": 1,
  "summary": "Refund money to a customer's original payment method.",
  "riskNote": "Money leaves the business. A second refund for the same order is the classic agent mistake.",
  "effects": [
    "money.out"
  ],
  "reversibility": {
    "kind": "compensable",
    "via": "payments.recharge"
  },
  "blastRadius": {
    "scope": "customer",
    "amountField": "amount",
    "maxAmount": 1000,
    "perWindow": {
      "count": 3,
      "windowSeconds": 3600
    }
  },
  "preconditions": [
    "order.exists",
    "order.paid",
    "refund.within_remaining",
    "refund.currency_matches",
    "refund.original_method"
  ],
  "idempotency": {
    "key": [
      "orderId",
      "amount"
    ],
    "windowSeconds": 86400
  },
  "approval": {
    "when": [
      "amount > 200"
    ]
  },
  "input": {
    "type": "object",
    "required": [
      "orderId",
      "amount",
      "currency",
      "destination",
      "reason"
    ],
    "additionalProperties": false,
    "properties": {
      "orderId": {
        "type": "string",
        "minLength": 1
      },
      "amount": {
        "type": "number",
        "exclusiveMinimum": 0
      },
      "currency": {
        "type": "string",
        "minLength": 3,
        "maxLength": 3
      },
      "destination": {
        "type": "string",
        "enum": [
          "original_method",
          "new_card"
        ]
      },
      "reason": {
        "type": "string",
        "minLength": 1
      }
    }
  }
}
