{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.montran.com/schemas/payment.json",
  "title": "Montran Payment",
  "description": "A payment transaction processed through Montran's payment infrastructure. Aligned with ISO 20022 payment messaging standards including pain.001 (CustomerCreditTransferInitiation), pacs.008 (FIToFICustomerCreditTransfer), and pacs.002 (FIToFIPaymentStatusReport).",
  "type": "object",
  "required": [
    "paymentId",
    "paymentType",
    "debtorAccount",
    "creditorAccount",
    "amount",
    "currency",
    "status"
  ],
  "properties": {
    "paymentId": {
      "type": "string",
      "description": "Unique payment identifier assigned by the system"
    },
    "messageId": {
      "type": "string",
      "description": "Unique message identification assigned by the initiating party (ISO 20022 MsgId)"
    },
    "endToEndId": {
      "type": "string",
      "description": "End-to-end identification assigned by the initiating party, passed through the entire payment chain (ISO 20022 EndToEndId)"
    },
    "transactionId": {
      "type": "string",
      "description": "Unique transaction identification assigned by the first instructing agent (ISO 20022 TxId)"
    },
    "paymentType": {
      "type": "string",
      "description": "Type of payment transaction",
      "enum": [
        "credit-transfer",
        "direct-debit",
        "instant-payment",
        "cross-border",
        "cheque",
        "remittance",
        "request-to-pay"
      ]
    },
    "status": {
      "type": "string",
      "description": "Current payment processing status using ISO 20022 status codes",
      "enum": [
        "RCVD",
        "ACTC",
        "ACCP",
        "ACSP",
        "ACSC",
        "ACWC",
        "PDNG",
        "RJCT",
        "CANC",
        "RTND"
      ]
    },
    "statusReasonCode": {
      "type": "string",
      "description": "Reason code for rejection or return (ISO 20022 reason codes)"
    },
    "statusReasonDescription": {
      "type": "string",
      "description": "Human-readable description of the status reason"
    },
    "debtorName": {
      "type": "string",
      "description": "Name of the debtor (payer/originator)"
    },
    "debtorAccount": {
      "$ref": "#/$defs/AccountIdentification"
    },
    "debtorAgent": {
      "$ref": "#/$defs/FinancialInstitution"
    },
    "creditorName": {
      "type": "string",
      "description": "Name of the creditor (payee/beneficiary)"
    },
    "creditorAccount": {
      "$ref": "#/$defs/AccountIdentification"
    },
    "creditorAgent": {
      "$ref": "#/$defs/FinancialInstitution"
    },
    "amount": {
      "type": "number",
      "description": "Payment amount",
      "minimum": 0.01
    },
    "currency": {
      "type": "string",
      "description": "ISO 4217 currency code",
      "pattern": "^[A-Z]{3}$"
    },
    "requestedExecutionDate": {
      "type": "string",
      "format": "date",
      "description": "Requested execution date for the payment"
    },
    "settlementDate": {
      "type": "string",
      "format": "date",
      "description": "Actual or expected settlement date"
    },
    "clearingSystem": {
      "type": "string",
      "description": "Clearing and settlement mechanism used",
      "enum": [
        "SEPA",
        "TARGET2",
        "FEDWIRE",
        "CHIPS",
        "CHAPS",
        "FASTER_PAYMENTS",
        "TIPS",
        "RT1",
        "RTGS",
        "ACH",
        "SWIFT"
      ]
    },
    "remittanceInformation": {
      "type": "string",
      "description": "Remittance information or payment reference"
    },
    "chargeBearer": {
      "type": "string",
      "description": "Specifies which party bears the charges",
      "enum": [
        "DEBT",
        "CRED",
        "SHAR",
        "SLEV"
      ]
    },
    "serviceLevel": {
      "type": "string",
      "description": "Service level code (e.g., SEPA, URGP)"
    },
    "categoryPurpose": {
      "type": "string",
      "description": "Category purpose code for the payment"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp when the payment was created"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp of the last status update"
    }
  },
  "$defs": {
    "AccountIdentification": {
      "type": "object",
      "description": "Account identification using IBAN or proprietary account number",
      "properties": {
        "iban": {
          "type": "string",
          "description": "International Bank Account Number",
          "pattern": "^[A-Z]{2}[0-9]{2}[A-Z0-9]{4,30}$"
        },
        "accountNumber": {
          "type": "string",
          "description": "Proprietary account number"
        },
        "currency": {
          "type": "string",
          "description": "Account currency (ISO 4217)",
          "pattern": "^[A-Z]{3}$"
        }
      }
    },
    "FinancialInstitution": {
      "type": "object",
      "description": "Financial institution identification",
      "properties": {
        "bic": {
          "type": "string",
          "description": "Bank Identifier Code (SWIFT/BIC)",
          "pattern": "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$"
        },
        "name": {
          "type": "string",
          "description": "Name of the financial institution"
        },
        "clearingSystemMemberId": {
          "type": "string",
          "description": "Clearing system member identification"
        }
      }
    }
  }
}
