{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ap2-protocol.org/schemas/payment_receipt.json",
  "title": "Payment Receipt",
  "description": "Receipt that supplies information about the final state of a payment.",
  "type": "object",
  "properties": {
    "status": {
      "description": "The status of the payment.",
      "$ref": "types/receipt_status.json"
    },
    "iss": {
      "type": "string",
      "description": "The issuer of the receipt."
    },
    "iat": {
      "type": "integer",
      "description": "The creation timestamp as a Unix epoch."
    },
    "reference": {
      "type": "string",
      "description": "The hash of the closed Mandate that this receipt is binding to."
    },
    "error": {
      "type": "string",
      "description": "A unique error code. Present if and only if status is Error."
    },
    "error_description": {
      "type": "string",
      "description": "A human-readable error description. Present if and only if status is Error."
    },
    "payment_id": {
      "type": "string",
      "description": "A unique identifier for the payment."
    },
    "psp_confirmation_id": {
      "type": "string",
      "description": "A unique identifier for the transaction confirmation at the PSP. Present only if status is Success."
    },
    "network_confirmation_id": {
      "type": "string",
      "description": "A unique identifier for the transaction confirmation at the network. Present only if status is Success."
    }
  },
  "required": [
    "status",
    "iss",
    "iat",
    "reference",
    "payment_id"
  ],
  "oneOf": [
    {
      "title": "Payment Receipt Success",
      "properties": {
        "status": {
          "const": "Success"
        }
      },
      "required": [
        "psp_confirmation_id",
        "network_confirmation_id"
      ]
    },
    {
      "title": "Payment Receipt Error",
      "properties": {
        "status": {
          "const": "Error"
        }
      },
      "required": [
        "error",
        "error_description"
      ]
    }
  ]
}
