{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://payflow.kingdomcompny.com/api/schemas/Event.order.paid.json",
  "title": "Event.order.paid",
  "type": "object",
  "required": [
    "id",
    "type",
    "api_version",
    "created_at",
    "livemode",
    "data"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^evt_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "type": {
      "const": "order.paid"
    },
    "api_version": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$"
    },
    "livemode": {
      "type": "boolean"
    },
    "data": {
      "$ref": "#/$defs/OrderEventData"
    }
  },
  "$defs": {
    "OrderCustomer": {
      "type": "object",
      "required": [
        "id",
        "email",
        "name",
        "phone"
      ],
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "email": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "phone": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "OrderEventData": {
      "type": "object",
      "required": [
        "order",
        "customer",
        "locale",
        "items",
        "metadata"
      ],
      "properties": {
        "order": {
          "type": "object",
          "required": [
            "id",
            "reference",
            "status",
            "amount",
            "currency",
            "refunded_amount",
            "full_refund",
            "paid_at",
            "provider",
            "provider_reference"
          ],
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^ord_[0-9A-HJKMNP-TV-Z]{26}$"
            },
            "reference": {
              "type": "string"
            },
            "status": {
              "$ref": "#/$defs/OrderStatus"
            },
            "amount": {
              "type": "integer",
              "minimum": 0,
              "description": "Em subunidades da moeda (R 149,00 = 14900)."
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$",
              "description": "ISO 4217"
            },
            "refunded_amount": {
              "type": "integer",
              "minimum": 0,
              "description": "Em subunidades da moeda (R 149,00 = 14900)."
            },
            "full_refund": {
              "type": "boolean"
            },
            "paid_at": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "created_at": {
              "type": "string",
              "format": "date-time",
              "pattern": "Z$"
            },
            "provider": {
              "type": [
                "string",
                "null"
              ]
            },
            "provider_reference": {
              "type": [
                "string",
                "null"
              ]
            },
            "livemode": {
              "type": "boolean"
            }
          }
        },
        "customer": {
          "$ref": "#/$defs/OrderCustomer"
        },
        "locale": {
          "enum": [
            "en",
            "pt",
            "es"
          ]
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/OrderItem"
          }
        },
        "metadata": {
          "type": "object",
          "additionalProperties": {
            "type": [
              "string",
              "null"
            ]
          },
          "maxProperties": 51,
          "description": "Mapa de texto para texto, até 50 chaves. member_user_id vai sempre (null sem ref)."
        },
        "refund": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^re_[0-9A-HJKMNP-TV-Z]{26}$"
            },
            "amount": {
              "type": "integer",
              "minimum": 0,
              "description": "Em subunidades da moeda (R 149,00 = 14900)."
            },
            "reason": {
              "type": [
                "string",
                "null"
              ]
            },
            "created_at": {
              "type": "string",
              "format": "date-time",
              "pattern": "Z$"
            }
          }
        },
        "dispute": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^dp_[0-9A-HJKMNP-TV-Z]{26}$"
            },
            "reason": {
              "type": [
                "string",
                "null"
              ]
            },
            "amount": {
              "type": [
                "integer",
                "null"
              ]
            },
            "opened_at": {
              "type": "string",
              "format": "date-time",
              "pattern": "Z$"
            },
            "closed_at": {
              "type": "string",
              "format": "date-time",
              "pattern": "Z$"
            }
          }
        },
        "outcome": {
          "enum": [
            "won",
            "lost"
          ]
        }
      }
    },
    "OrderItem": {
      "type": "object",
      "required": [
        "product_id",
        "name",
        "quantity",
        "unit_amount"
      ],
      "properties": {
        "product_id": {
          "type": "string",
          "pattern": "^prod_[0-9A-HJKMNP-TV-Z]{26}$"
        },
        "sku": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": "string"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1
        },
        "unit_amount": {
          "type": "integer",
          "minimum": 0,
          "description": "Em subunidades da moeda (R 149,00 = 14900)."
        }
      }
    },
    "OrderStatus": {
      "enum": [
        "pending",
        "paid",
        "partially_refunded",
        "refunded",
        "disputed",
        "dispute_won",
        "dispute_lost"
      ]
    }
  }
}
