{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://temenos.com/schemas/temenos/payment-order.json",
  "title": "Temenos Payment Order",
  "description": "Schema for Temenos payment orders including domestic transfers, international SWIFT payments, SEPA credit transfers, and internal account transfers with full ISO 20022 support.",
  "type": "object",
  "required": ["paymentOrderId", "debitAccountId", "amount", "currency", "paymentType", "status"],
  "properties": {
    "paymentOrderId": {
      "type": "string",
      "description": "Unique payment order identifier assigned by the system"
    },
    "debitAccountId": {
      "type": "string",
      "description": "Identifier of the originating debit account"
    },
    "creditAccountId": {
      "type": "string",
      "description": "Identifier of the destination credit account for internal transfers"
    },
    "amount": {
      "type": "number",
      "description": "Payment amount in the specified currency",
      "minimum": 0.01
    },
    "currency": {
      "type": "string",
      "description": "Payment currency in ISO 4217 format",
      "pattern": "^[A-Z]{3}$"
    },
    "paymentType": {
      "type": "string",
      "description": "Classification of the payment type determining the clearing channel",
      "enum": [
        "INTERNAL",
        "DOMESTIC",
        "INTERNATIONAL",
        "SEPA_CREDIT",
        "INSTANT_SEPA",
        "SWIFT",
        "TARGET2",
        "CROSS_BORDER",
        "ACH"
      ]
    },
    "status": {
      "type": "string",
      "description": "Current processing status of the payment order",
      "enum": ["PENDING", "PROCESSING", "COMPLETED", "FAILED", "CANCELLED", "RETURNED"]
    },
    "valueDate": {
      "type": "string",
      "format": "date",
      "description": "Requested value date for the payment"
    },
    "executionDate": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Actual execution date when the payment was processed"
    },
    "reference": {
      "type": "string",
      "description": "Payment reference provided by the originator",
      "maxLength": 140
    },
    "endToEndId": {
      "type": "string",
      "description": "End-to-end identifier for ISO 20022 payment tracking",
      "maxLength": 35
    },
    "beneficiary": {
      "$ref": "#/$defs/Beneficiary"
    },
    "remittanceInformation": {
      "type": "string",
      "description": "Remittance information accompanying the payment",
      "maxLength": 140
    },
    "chargeBearer": {
      "type": "string",
      "description": "Charge allocation between originator and beneficiary",
      "enum": ["SHA", "OUR", "BEN"]
    },
    "clearingStatus": {
      "type": "string",
      "description": "Status within the clearing system"
    },
    "bookingStatus": {
      "type": "string",
      "description": "Account booking status",
      "enum": ["BOOKED", "PENDING", "REJECTED"]
    },
    "failureReason": {
      "type": ["string", "null"],
      "description": "Reason for payment failure if applicable"
    },
    "createdDate": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp when the payment order was created"
    },
    "lastUpdated": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp of the last status update"
    }
  },
  "$defs": {
    "Beneficiary": {
      "type": "object",
      "description": "Payment beneficiary details",
      "properties": {
        "name": {
          "type": "string",
          "description": "Beneficiary name",
          "maxLength": 140
        },
        "iban": {
          "type": "string",
          "description": "Beneficiary International Bank Account Number",
          "pattern": "^[A-Z]{2}[0-9]{2}[A-Z0-9]{4,30}$"
        },
        "bic": {
          "type": "string",
          "description": "Beneficiary bank BIC/SWIFT code",
          "pattern": "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$"
        },
        "accountNumber": {
          "type": "string",
          "description": "Beneficiary account number for non-IBAN payments"
        },
        "bankName": {
          "type": "string",
          "description": "Beneficiary bank name"
        },
        "address": {
          "type": "string",
          "description": "Beneficiary address"
        },
        "country": {
          "type": "string",
          "description": "Beneficiary country in ISO 3166-1 alpha-2 format",
          "pattern": "^[A-Z]{2}$"
        }
      }
    }
  }
}
