{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.zentpay.app/webhook-event.schema.json",
  "title": "ZentPay Webhook Event",
  "type": "object",
  "required": ["id", "type", "test", "createdAt", "app", "product", "payment", "delivery"],
  "properties": {
    "id": { "type": "string", "pattern": "^zevt_" },
    "type": {
      "type": "string",
      "enum": ["payment.delivered", "delivery.created", "payment.settled"],
      "description": "payment.delivered is the current fulfillment event. delivery.created is accepted for legacy webhook subscriptions. payment.settled is the later chain settlement event."
    },
    "test": { "type": "boolean" },
    "createdAt": { "type": "string", "format": "date-time" },
    "app": {
      "type": "object",
      "required": ["id", "slug", "name"],
      "properties": {
        "id": { "type": "string" },
        "slug": { "type": "string" },
        "name": { "type": "string" },
        "environment": { "type": "string" },
        "payTo": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    },
    "product": {
      "type": "object",
      "required": ["id", "slug", "name", "priceAtomic", "currency", "network"],
      "properties": {
        "id": { "type": "string" },
        "slug": { "type": "string" },
        "name": { "type": "string" },
        "priceAtomic": { "type": "string" },
        "currency": { "type": "string" },
        "network": { "type": "string" },
        "paymentPath": { "type": "string" }
      },
      "additionalProperties": true
    },
    "payment": {
      "type": "object",
      "required": ["mode", "settlementStatus"],
      "properties": {
        "mode": { "type": "string" },
        "simulated": { "type": "boolean" },
        "settlementStatus": { "type": "string" },
        "traceId": { "type": ["string", "null"] },
        "budgetSpender": { "type": ["string", "null"] },
        "payTo": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    },
    "delivery": {
      "type": "object",
      "required": ["deliveryId", "idempotencyKey", "status", "fulfilled"],
      "properties": {
        "deliveryId": { "type": "string", "pattern": "^ztdlv_" },
        "chargeId": { "type": ["string", "null"] },
        "idempotencyKey": { "type": "string" },
        "appId": { "type": ["string", "null"] },
        "productId": { "type": ["string", "null"] },
        "orderId": { "type": ["string", "null"] },
        "itemId": { "type": ["string", "null"] },
        "developerUserId": { "type": ["string", "null"] },
        "walletAddress": { "type": ["string", "null"] },
        "paymentMode": { "type": ["string", "null"] },
        "network": { "type": ["string", "null"] },
        "amount": { "type": ["string", "null"] },
        "payTo": { "type": ["string", "null"] },
        "status": { "type": "string" },
        "fulfilled": { "type": "boolean" },
        "settlementStatus": { "type": ["string", "null"] },
        "settlementTxHash": { "type": ["string", "null"] },
        "deliveredAt": { "type": ["string", "null"], "format": "date-time" }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
