{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/decionis-com/json-schema/decionis-com-commerce-payment-authorization-request-schema.json",
  "title": "CommercePaymentAuthorizationRequest",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/decionis-com-well-known-openapi.json#/components/schemas/CommercePaymentAuthorizationRequest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "attempt_id",
    "request"
  ],
  "dependencies": {
    "executor": [
      "intent"
    ],
    "intent": [
      "executor"
    ]
  },
  "properties": {
    "version": {
      "type": "string",
      "const": "commerce-payment-authorization-v1"
    },
    "attempt_id": {
      "type": "string",
      "format": "uuid",
      "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
    },
    "request": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transaction_id",
        "erp_type",
        "tenant_id",
        "timestamp",
        "agent_id",
        "mode",
        "payment",
        "facts",
        "native_context",
        "payment_evidence"
      ],
      "properties": {
        "transaction_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "erp_type": {
          "type": "string",
          "const": "D365_BC"
        },
        "tenant_id": {
          "type": "string",
          "format": "uuid"
        },
        "native_context": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "version",
            "org_id",
            "workspace_environment",
            "connection_id",
            "expected_revision",
            "environment_name",
            "company_id"
          ],
          "properties": {
            "version": {
              "type": "string",
              "const": "commerce-native-context-v1"
            },
            "org_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "workspace_environment": {
              "type": "string",
              "enum": [
                "sandbox",
                "production"
              ]
            },
            "connection_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "expected_revision": {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            },
            "environment_name": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,79}$"
            },
            "company_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            }
          }
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "agent_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "mode": {
          "type": "string",
          "const": "ENFORCE"
        },
        "payment": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "payment_id",
            "vendor_id",
            "amount",
            "currency"
          ],
          "properties": {
            "payment_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "vendor_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "invoice_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "amount": {
              "type": "number",
              "minimum": 0,
              "maximum": 1000000000000
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "due_at": {
              "type": "string",
              "format": "date-time",
              "maxLength": 40
            },
            "rail": {
              "type": "string",
              "enum": [
                "ach",
                "wire",
                "card",
                "stablecoin",
                "other"
              ]
            }
          }
        },
        "facts": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "observed_at"
          ],
          "properties": {
            "observed_at": {
              "type": "string",
              "format": "date-time",
              "maxLength": 40
            },
            "payment": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "prior_payment_count": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000000000
                }
              }
            },
            "treasury": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "cash_position": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1000000000000
                },
                "run_total": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1000000000000
                }
              }
            },
            "beneficiary": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "changed_at": {
                  "anyOf": [
                    {
                      "type": "string",
                      "format": "date-time",
                      "maxLength": 40
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "verification": {
                  "type": "string",
                  "enum": [
                    "verified",
                    "unverified",
                    "pending"
                  ]
                }
              }
            }
          }
        },
        "payment_evidence": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "version",
            "method",
            "journal_id",
            "journal_revision",
            "batch_id",
            "batch_revision",
            "invoice_entry_id",
            "invoice_revision",
            "invoice_remaining_amount",
            "funding_bank_id",
            "funding_bank_revision",
            "beneficiary_bank_id",
            "beneficiary_bank_revision",
            "source_revisions",
            "snapshot_sha256"
          ],
          "properties": {
            "version": {
              "type": "string",
              "const": "commerce-payment-evidence-v1"
            },
            "method": {
              "type": "string",
              "const": "ledger_cash_same_currency_single_payment_v1"
            },
            "source": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "sandbox",
                "evaluation_company"
              ],
              "properties": {
                "sandbox": {
                  "type": "boolean"
                },
                "evaluation_company": {
                  "type": "boolean"
                }
              }
            },
            "journal_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "journal_revision": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$",
              "maxLength": 19
            },
            "batch_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "batch_revision": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$",
              "maxLength": 19
            },
            "invoice_entry_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "invoice_revision": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$",
              "maxLength": 19
            },
            "invoice_remaining_amount": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 1000000000000
            },
            "funding_bank_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "funding_bank_revision": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$",
              "maxLength": 19
            },
            "beneficiary_bank_id": {
              "type": "string",
              "format": "uuid",
              "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
            },
            "beneficiary_bank_revision": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,18}$",
              "maxLength": 19
            },
            "source_revisions": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "run",
                "invoice",
                "treasury"
              ],
              "properties": {
                "run": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "invoice": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "treasury": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              }
            },
            "snapshot_sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          }
        },
        "posted": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "entry_id",
            "vendor_id",
            "amount",
            "currency",
            "posted_at"
          ],
          "properties": {
            "entry_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "vendor_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "amount": {
              "type": "number",
              "minimum": 0,
              "maximum": 1000000000000
            },
            "currency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "posted_at": {
              "type": "string",
              "format": "date-time",
              "maxLength": 40
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "payment_evidence"
            ]
          },
          "then": {
            "properties": {
              "erp_type": {
                "const": "D365_BC"
              },
              "facts": {
                "type": "object",
                "required": [
                  "treasury"
                ],
                "properties": {
                  "treasury": {
                    "type": "object",
                    "required": [
                      "cash_position",
                      "run_total"
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "erp_type": {
                "const": "D365_BC"
              }
            },
            "required": [
              "erp_type"
            ]
          },
          "then": {
            "required": [
              "native_context"
            ]
          },
          "else": {
            "not": {
              "required": [
                "native_context"
              ]
            }
          }
        }
      ],
      "not": {
        "required": [
          "posted"
        ]
      }
    },
    "executor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "platform",
        "style",
        "version"
      ],
      "properties": {
        "platform": {
          "type": "string",
          "const": "business-central"
        },
        "style": {
          "type": "string",
          "const": "permit"
        },
        "version": {
          "type": "string",
          "maxLength": 64,
          "pattern": "^[0-9A-Za-z][0-9A-Za-z.+_-]*$"
        }
      }
    },
    "intent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "intent_id",
        "captured_at",
        "expires_at",
        "actor",
        "action",
        "context",
        "downstream_target",
        "intent_hash"
      ],
      "properties": {
        "protocol_version": {
          "type": "string",
          "const": "agent-safe.intent/1"
        },
        "tenant_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
        },
        "intent_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^(?!00000000-0000-0000-0000-000000000000$)[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
        },
        "captured_at": {
          "type": "string",
          "format": "date-time",
          "maxLength": 40
        },
        "expires_at": {
          "type": "string",
          "format": "date-time",
          "maxLength": 40
        },
        "actor": {
          "type": "object",
          "maxProperties": 4
        },
        "action": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "resource",
            "parameters"
          ],
          "properties": {
            "type": {
              "type": "string",
              "const": "payment.release"
            },
            "resource": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            },
            "parameters": {
              "type": "object",
              "maxProperties": 20
            }
          }
        },
        "context": {
          "type": "object",
          "required": [
            "idempotency_key"
          ],
          "maxProperties": 20
        },
        "downstream_target": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "system",
            "operation"
          ],
          "properties": {
            "system": {
              "type": "string",
              "const": "business-central"
            },
            "operation": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "environment": {
              "type": "string",
              "enum": [
                "sandbox",
                "production"
              ]
            },
            "endpoint": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            }
          }
        },
        "correlation_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "expected_effect_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "intent_hash": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        }
      }
    }
  }
}