{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/first-dollar-test-com/json-schema/first-dollar-test-com-receipt-schema.json",
  "title": "Receipt",
  "x-generated": "2026-11-08",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/first-dollar-test-com-api-openapi.json#/components/schemas/Receipt",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "terms": {
      "$ref": "#/$defs/Terms"
    },
    "payment": {
      "$ref": "#/$defs/MoneyStatus"
    },
    "verdict": {
      "$ref": "#/$defs/Verdict"
    },
    "reward": {
      "$ref": "#/$defs/MoneyStatus"
    },
    "refund": {
      "$ref": "#/$defs/MoneyStatus"
    },
    "settlement": {
      "$ref": "#/$defs/Settlement"
    },
    "attemptsRemaining": {
      "type": "integer",
      "minimum": 0
    },
    "deadline": {
      "type": "integer",
      "description": "Unix epoch milliseconds"
    },
    "discovery": {
      "$ref": "#/$defs/Discovery"
    }
  },
  "additionalProperties": true,
  "required": [
    "id",
    "terms",
    "payment",
    "reward",
    "refund",
    "settlement"
  ],
  "$defs": {
    "Discovery": {
      "type": "object",
      "required": [
        "entryChannel",
        "mode",
        "evidence",
        "touches"
      ],
      "properties": {
        "entryChannel": {
          "$ref": "#/$defs/DiscoveryChannel"
        },
        "selfReportedChannel": {
          "$ref": "#/$defs/DiscoveryChannel"
        },
        "mode": {
          "type": "string",
          "enum": [
            "autonomous",
            "human_handoff",
            "unknown"
          ]
        },
        "evidence": {
          "type": "string",
          "enum": [
            "server_observed",
            "self_report",
            "trace",
            "unknown"
          ]
        },
        "touches": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "object",
            "required": [
              "channel",
              "at"
            ],
            "properties": {
              "channel": {
                "$ref": "#/$defs/DiscoveryChannel"
              },
              "at": {
                "type": "integer",
                "description": "Unix epoch milliseconds"
              }
            }
          }
        }
      },
      "additionalProperties": true
    },
    "DiscoveryChannel": {
      "type": "string",
      "enum": [
        "google",
        "mcp_registry",
        "a2a",
        "x402_discovery",
        "direct_url",
        "human_handoff",
        "unknown"
      ]
    },
    "MoneyStatus": {
      "type": "object",
      "required": [
        "status"
      ],
      "properties": {
        "status": {
          "type": "string"
        },
        "amountUnits": {
          "type": "string"
        },
        "transaction": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$",
          "description": "Public transaction hash when available; may precede onchain inclusion/finality."
        },
        "finalized": {
          "type": "boolean",
          "description": "On receipts: true for a stored finalized reward/refund; fee true only when the original payment is paid/refunded and has a transaction."
        },
        "explorerUrl": {
          "type": "string",
          "format": "uri",
          "description": "Accepted-network Base explorer link for a well-formed public transaction hash. A link is not finality proof."
        }
      },
      "additionalProperties": true,
      "description": "Actual persisted payment or transfer state. Receipt-specific finalized and explorerUrl fields are presentation hints; a transaction hash alone is insufficient."
    },
    "Settlement": {
      "type": "object",
      "required": [
        "outcome",
        "expectedTransfer",
        "complete",
        "failureRefundPolicy",
        "completionRule"
      ],
      "properties": {
        "outcome": {
          "type": "string",
          "enum": [
            "pending",
            "pass",
            "retry_allowed",
            "terminal_fail",
            "timeout",
            "platform_refund"
          ]
        },
        "expectedTransfer": {
          "type": "string",
          "enum": [
            "undecided",
            "reward",
            "refund",
            "none"
          ]
        },
        "complete": {
          "type": "boolean",
          "description": "False until the expected reward/refund is finalized. A paid legacy terminal failure may complete with no transfer under its accepted no_refund policy."
        },
        "failureRefundPolicy": {
          "type": "string",
          "enum": [
            "no_refund",
            "full_fee_refund"
          ],
          "description": "Derived from this run’s accepted terms; missing legacy policy is no_refund."
        },
        "completionRule": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "Terms": {
      "type": "object",
      "required": [
        "version",
        "network",
        "asset",
        "payTo",
        "feeUnits",
        "rewardUnits",
        "taskVersion",
        "taskSeconds",
        "maxAttempts"
      ],
      "properties": {
        "version": {
          "type": "string"
        },
        "network": {
          "type": "string",
          "description": "CAIP-2 EVM network: Base mainnet eip155:8453, Base Sepolia eip155:84532, or an explicitly local fixture. Read live mode and accepted terms."
        },
        "asset": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{40}$"
        },
        "payTo": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{40}$"
        },
        "feeUnits": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "description": "USDC 6-decimal integer units; Beta v4 uses 1000000 (1 USDC). Paid or in-flight legacy runs retain their accepted amount; unpaid stale offers cannot enroll after the live version changes."
        },
        "rewardUnits": {
          "type": "string",
          "const": "1000000"
        },
        "taskVersion": {
          "type": "string"
        },
        "taskSeconds": {
          "type": "integer",
          "maximum": 3600
        },
        "maxAttempts": {
          "type": "integer"
        },
        "paidCohortClosesAt": {
          "type": "string",
          "format": "date-time",
          "description": "Immutable UTC boundary for new paid admission. At or after this instant new run creation and payment admission are rejected; recovery of existing paid obligations continues."
        },
        "fundingMode": {
          "type": "string",
          "enum": [
            "prefunded",
            "fee_backed"
          ],
          "description": "fee_backed means a finalized fee funds that run’s reward/refund obligation. Missing means a legacy prefunded run."
        },
        "failedTestPolicy": {
          "type": "string",
          "enum": [
            "no_refund",
            "full_fee_refund"
          ],
          "description": "full_fee_refund returns the full accepted fee after terminal failed attempts or paid-task timeout, without a reward. Missing/no_refund retains legacy behavior. Gas and execution costs are excluded."
        },
        "payoutMode": {
          "type": "string",
          "enum": [
            "direct",
            "x402_sponsored"
          ],
          "description": "x402_sponsored means the treasury signs a USDC authorization and the facilitator submits it and pays payout gas. Combined with fee_backed, no manual treasury ETH or seed-USDC funding is required. direct/missing preserves direct treasury transactions for older terms."
        }
      },
      "additionalProperties": true
    },
    "Verdict": {
      "type": "object",
      "required": [
        "status",
        "code"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "pass",
            "fail"
          ]
        },
        "code": {
          "type": "string"
        },
        "failureStep": {
          "type": "string"
        }
      }
    }
  }
}