{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uncorrelate.com/schemas/purchase.schema.json",
  "title": "Purchase (revenue block)",
  "description": "The `revenue` block of a `$purchase` event. `POST /v1/purchases` (and the SDKs' `UC.Purchase` / `Uncorrelate.purchase`) is sugar that accepts this object plus `player_id` and writes the `$purchase` event. The SDK sends what the store gave it, including the receipt. The server validates the receipt with Apple or Google asynchronously and writes the result as `$purchase_validated` (or `$purchase_rejected`); revenue charts count validated purchases by default. The client-reported price is kept for display but is never treated as truth. See docs/recipe/05-ingestion-and-sdks.md#receipts.",
  "type": "object",
  "required": [
    "store",
    "sku",
    "transaction_id"
  ],
  "additionalProperties": false,
  "properties": {
    "store": {
      "enum": [
        "app_store",
        "google_play",
        "steam",
        "web",
        "other"
      ]
    },
    "sku": {
      "type": "string"
    },
    "transaction_id": {
      "type": "string",
      "description": "Store transaction id. Dedup key for revenue: a transaction counts once, whatever the insert_id."
    },
    "original_transaction_id": {
      "type": "string",
      "description": "Subscriptions: ties renewals together."
    },
    "kind": {
      "enum": [
        "consumable",
        "non_consumable",
        "subscription",
        "subscription_renewal",
        "refund"
      ],
      "default": "consumable"
    },
    "quantity": {
      "type": "integer",
      "minimum": 1,
      "default": 1
    },
    "price": {
      "type": "number",
      "description": "Local price as the store showed it, in `currency`. Client-reported."
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "is_sandbox": {
      "type": "boolean",
      "default": false
    },
    "receipt": {
      "description": "What the store returned. A string is accepted as-is (base64 App Store receipt, StoreKit 2 JWS, or Play purchase token; the server detects which from `store` and the shape). The object forms are explicit and preferred.",
      "oneOf": [
        {
          "type": "string"
        },
        {
          "title": "Apple (StoreKit 2)",
          "required": [
            "jws"
          ],
          "additionalProperties": false,
          "properties": {
            "jws": {
              "type": "string",
              "description": "Transaction.jwsRepresentation. Verified offline against Apple's certificate chain; App Store Server API used for refunds/renewals."
            }
          },
          "type": "object"
        },
        {
          "title": "Apple (StoreKit 1, legacy)",
          "required": [
            "app_receipt"
          ],
          "additionalProperties": false,
          "properties": {
            "app_receipt": {
              "type": "string",
              "description": "Base64 app receipt."
            }
          },
          "type": "object"
        },
        {
          "title": "Google Play",
          "required": [
            "purchase_token",
            "package_name"
          ],
          "additionalProperties": false,
          "properties": {
            "purchase_token": {
              "type": "string"
            },
            "package_name": {
              "type": "string"
            },
            "signature": {
              "type": "string",
              "description": "Optional; enables an offline signature check before the Play Developer API call."
            },
            "original_json": {
              "type": "string"
            }
          },
          "type": "object"
        }
      ]
    }
  },
  "examples": [
    {
      "store": "app_store",
      "sku": "gems_pack_500",
      "transaction_id": "2000000812345678",
      "kind": "consumable",
      "price": 4.99,
      "currency": "USD",
      "receipt": {
        "jws": "eyJhbGciOiJFUzI1NiIsIng1YyI6WyJ..."
      }
    }
  ]
}
