{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/saturation-io/json-schema/saturation-io-payment-schema.json",
  "title": "Payment",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/saturation-io-openapi.yml#/components/schemas/Payment",
  "type": "object",
  "required": [
    "id",
    "workspaceId",
    "projectId",
    "paymentRequestId",
    "purchaseOrderId",
    "contactId",
    "budgetLineId",
    "status",
    "amount",
    "destinationAmount",
    "rail",
    "description",
    "memo",
    "notes",
    "scheduledFor",
    "expectedArrivalAt",
    "destination",
    "cancellationRequested",
    "needsSupport",
    "failureReason",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "#/$defs/Id"
    },
    "workspaceId": {
      "$ref": "#/$defs/Id"
    },
    "projectId": {
      "type": [
        "string",
        "null"
      ]
    },
    "paymentRequestId": {
      "type": [
        "string",
        "null"
      ]
    },
    "purchaseOrderId": {
      "type": [
        "string",
        "null"
      ]
    },
    "contactId": {
      "type": [
        "string",
        "null"
      ]
    },
    "budgetLineId": {
      "type": [
        "string",
        "null"
      ]
    },
    "status": {
      "$ref": "#/$defs/PaymentStatus"
    },
    "amount": {
      "$ref": "#/$defs/Money"
    },
    "destinationAmount": {
      "oneOf": [
        {
          "$ref": "#/$defs/Money"
        },
        {
          "type": "null"
        }
      ]
    },
    "rail": {
      "type": [
        "string",
        "null"
      ]
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "memo": {
      "type": [
        "string",
        "null"
      ]
    },
    "notes": {
      "type": [
        "string",
        "null"
      ]
    },
    "scheduledFor": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "expectedArrivalAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "destination": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "bankName",
            "accountType",
            "accountLast4",
            "network"
          ],
          "additionalProperties": false,
          "properties": {
            "bankName": {
              "type": [
                "string",
                "null"
              ]
            },
            "accountType": {
              "type": [
                "string",
                "null"
              ]
            },
            "accountLast4": {
              "type": [
                "string",
                "null"
              ]
            },
            "network": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "cancellationRequested": {
      "type": "boolean"
    },
    "needsSupport": {
      "type": "boolean"
    },
    "failureReason": {
      "type": [
        "string",
        "null"
      ]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "request": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentRequestBase"
        },
        {
          "type": "null"
        }
      ]
    },
    "purchaseOrder": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentPurchaseOrderLink"
        },
        {
          "type": "null"
        }
      ]
    },
    "transactions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PaymentTransactionLink"
      }
    },
    "contact": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentContactLink"
        },
        {
          "type": "null"
        }
      ]
    },
    "budgetLine": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentBudgetLineLink"
        },
        {
          "type": "null"
        }
      ]
    },
    "document": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentDocumentLink"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "$defs": {
    "Id": {
      "type": "string",
      "description": "A stable resource ID, such as `prj_…`, `txn_…`, or `doc_…`."
    },
    "Money": {
      "type": "object",
      "description": "An amount in integer minor units and its ISO-4217 currency.",
      "required": [
        "amount",
        "currency"
      ],
      "additionalProperties": false,
      "properties": {
        "amount": {
          "type": "integer",
          "format": "int64",
          "minimum": -4503599627370496,
          "maximum": 4503599627370496,
          "description": "Amount in the currency's smallest unit, such as cents. May be negative, and at most 2^52 either way."
        },
        "currency": {
          "type": "string",
          "description": "ISO-4217 currency code.",
          "minLength": 3,
          "maxLength": 3,
          "pattern": "^[A-Za-z]{3}$"
        }
      }
    },
    "PaymentBudgetLineLink": {
      "type": "object",
      "required": [
        "id",
        "accountId",
        "description",
        "type"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "accountId": {
          "type": [
            "string",
            "null"
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "PaymentContactLink": {
      "type": "object",
      "required": [
        "id",
        "name",
        "displayTitle",
        "company",
        "email",
        "type"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "displayTitle": {
          "type": [
            "string",
            "null"
          ]
        },
        "company": {
          "type": [
            "string",
            "null"
          ]
        },
        "email": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "PaymentDocumentLink": {
      "type": "object",
      "required": [
        "id",
        "projectId",
        "name",
        "mimeType",
        "status",
        "size",
        "classification"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": "string"
        },
        "mimeType": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string"
        },
        "size": {
          "type": "integer"
        },
        "classification": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "PaymentPurchaseOrderLink": {
      "type": "object",
      "required": [
        "id",
        "projectId",
        "number",
        "name",
        "status"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "number": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string"
        }
      }
    },
    "PaymentRequestBase": {
      "type": "object",
      "description": "A request to pay a person or company.",
      "required": [
        "id",
        "workspaceId",
        "projectId",
        "purchaseOrderId",
        "contactId",
        "budgetLineId",
        "amount",
        "description",
        "memo",
        "dueDate",
        "method",
        "status",
        "submittedAt",
        "approvedAt",
        "rejectedAt",
        "completedAt",
        "createdAt",
        "updatedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "workspaceId": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "purchaseOrderId": {
          "type": [
            "string",
            "null"
          ]
        },
        "contactId": {
          "type": [
            "string",
            "null"
          ]
        },
        "budgetLineId": {
          "type": [
            "string",
            "null"
          ]
        },
        "amount": {
          "$ref": "#/$defs/Money"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "memo": {
          "type": [
            "string",
            "null"
          ]
        },
        "dueDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "method": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "$ref": "#/$defs/PaymentRequestStatus"
        },
        "submittedAt": {
          "type": "string",
          "format": "date-time"
        },
        "approvedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "rejectedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "completedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "PaymentRequestStatus": {
      "type": "string",
      "description": "Current payment-request status. `unknown` means the status is unavailable.",
      "enum": [
        "submitted",
        "pending",
        "approved",
        "paid",
        "rejected",
        "canceled",
        "unknown"
      ]
    },
    "PaymentStatus": {
      "type": "string",
      "description": "Current payment status.",
      "enum": [
        "requested",
        "needs_approval",
        "ready_to_pay",
        "scheduled",
        "sending",
        "settled",
        "returned",
        "failed",
        "rejected",
        "canceled"
      ]
    },
    "PaymentTransactionLink": {
      "type": "object",
      "required": [
        "id",
        "projectId",
        "amount",
        "description",
        "status",
        "timestamp"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/Id"
        },
        "projectId": {
          "type": [
            "string",
            "null"
          ]
        },
        "amount": {
          "oneOf": [
            {
              "$ref": "#/$defs/Money"
            },
            {
              "type": "null"
            }
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string"
        },
        "timestamp": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    }
  }
}