{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/paypal/json-schema/paypal-customer-usage-schema.json",
  "title": "CustomerUsage",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/paypal-customers-api-openapi.yml#/components/schemas/CustomerUsage",
  "type": "object",
  "required": [
    "from_datetime",
    "to_datetime",
    "issuing_date",
    "total_amount",
    "taxes_amount",
    "charges_usage"
  ],
  "properties": {
    "from_datetime": {
      "allOf": [
        {
          "$ref": "#/$defs/DateTimeWithZone"
        },
        {
          "description": "Starting date of billing period, in the ISO 8601 datetime format in Universal Time (UTC)."
        }
      ]
    },
    "to_datetime": {
      "allOf": [
        {
          "$ref": "#/$defs/DateTimeWithZone"
        },
        {
          "description": "Ending date of the billing period, in the ISO 8601 datetime format in Universal Time (UTC)."
        }
      ]
    },
    "issuing_date": {
      "allOf": [
        {
          "$ref": "#/$defs/Date"
        }
      ],
      "description": "The date of creation of the invoice."
    },
    "invoice_id": {
      "type": "string",
      "description": "Unique invoice Id."
    },
    "total_amount": {
      "allOf": [
        {
          "$ref": "#/$defs/Amount"
        }
      ],
      "description": "The total amount for the current usage period, including all charges and taxes."
    },
    "taxes_amount": {
      "allOf": [
        {
          "$ref": "#/$defs/Amount"
        }
      ],
      "description": "The total amount of taxes applied to the current usage period."
    },
    "charges_usage": {
      "type": "array",
      "description": "Array of charges that comprise the current usage. It contains detailed information about individual charge items associated with the usage.",
      "items": {
        "$ref": "#/$defs/CustomerChargeUsage"
      }
    }
  },
  "$defs": {
    "Amount": {
      "allOf": [
        {
          "$ref": "#/$defs/AmountNoCurrency"
        },
        {
          "type": "object",
          "required": [
            "currency_code"
          ],
          "properties": {
            "currency_code": {
              "$ref": "#/$defs/Currency"
            }
          }
        }
      ]
    },
    "AmountNoCurrency": {
      "type": "object",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "type": "number",
          "format": "decimal",
          "description": "The amount value in the corresponding currency unit (e.g., two decimals for USD, no decimals for JPY).",
          "minimum": 0,
          "nullable": false,
          "default": 0
        }
      }
    },
    "ChargeModel": {
      "type": "string",
      "description": "The pricing model applied to this charge",
      "enum": [
        "STANDARD",
        "GRADUATED",
        "PACKAGE",
        "PERCENTAGE",
        "VOLUME"
      ],
      "x-enum-varnames": [
        "STANDARD",
        "GRADUATED",
        "PACKAGE",
        "PERCENTAGE",
        "VOLUME"
      ],
      "x-enum-descriptions": [
        "Standard pricing model where a fixed amount is charged per unit",
        "Graduated pricing model where the price per unit decreases as the quantity increases",
        "Package pricing model where a fixed price is charged for a set of units",
        "Percentage pricing model where a percentage of a base amount is charged",
        "Volume-based pricing model where the price varies based on the total volume consumed"
      ],
      "default": "STANDARD"
    },
    "Currency": {
      "type": "string",
      "description": "Currency code in ISO 4217 format.",
      "minLength": 3,
      "maxLength": 3,
      "pattern": "^[A-Z]{3}$"
    },
    "CustomerChargeUsage": {
      "type": "object",
      "required": [
        "units",
        "events_count",
        "amount",
        "charge",
        "metric"
      ],
      "properties": {
        "units": {
          "type": "string",
          "pattern": "^[0-9]+.?[0-9]*$",
          "description": "The number of units utilized for a specific charge item."
        },
        "events_count": {
          "type": "integer",
          "description": "The total count of usage events that have been recorded for a particular charge during the specified time period."
        },
        "amount": {
          "allOf": [
            {
              "$ref": "#/$defs/Amount"
            }
          ]
        },
        "charge": {
          "allOf": [
            {
              "$ref": "#/$defs/UsageBasedCharge"
            }
          ]
        },
        "metric": {
          "allOf": [
            {
              "$ref": "#/$defs/CustomerUsageMetric"
            }
          ]
        }
      }
    },
    "CustomerUsageMetric": {
      "title": "CustomerUsageMetric",
      "description": "Represents a metric used for customer usage. It includes the name, code, and aggregation type of the metric.",
      "type": "object",
      "required": [
        "name",
        "code",
        "aggregation_type"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Name of the metric used for this charge."
        },
        "code": {
          "type": "string",
          "description": "Unique code identifying the metric used for this charge."
        },
        "aggregation_type": {
          "$ref": "#/$defs/MetricAggregationType"
        }
      }
    },
    "Date": {
      "type": "string",
      "format": "date",
      "description": "Date in ISO 8601 format (YYYY-MM-DD).",
      "pattern": "^(?:[1-9]\\d{3}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|02-(?:0[1-9]|1\\d|2[0-8]))|(?:(?:\\d{2}(?:0[48]|[2468][048]|[13579][26]))|(?:[02468][048]00|[13579][26]00))-02-29)$"
    },
    "DateTimeWithZone": {
      "type": "string",
      "format": "date-time",
      "description": "Date and time in ISO 8601 format."
    },
    "MetricAggregationType": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "COUNT",
        "SUM",
        "MAX",
        "COUNT_DISTINCT",
        "LATEST"
      ],
      "x-enum-varnames": [
        "COUNT",
        "SUM",
        "MAX",
        "COUNT_DISTINCT",
        "LATEST"
      ],
      "x-enum-descriptions": [
        "Count the number of events",
        "Sum the values of a numeric field",
        "Find the maximum value of a numeric field",
        "Count the number of distinct values",
        "Use the latest value"
      ],
      "description": "Aggregation type for the metric"
    },
    "TaxBase": {
      "description": "Base schema for tax request/response objects",
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Name of the tax"
        },
        "rate": {
          "type": "string",
          "pattern": "^(?!0+(?:\\.0+)?$)(?:0?\\.\\d{1,2}|[1-9]\\d?(?:\\.\\d{1,2})?|100(?:\\.0{1,2})?)$",
          "description": "The percentage rate of the tax applied to transactions. A decimal amount from 0.01 to 100.00 inclusive, always with exactly two decimal places, no leading zeros except 0.xx."
        },
        "description": {
          "type": "string",
          "description": "Detailed description of the tax for internal reference"
        }
      }
    },
    "TaxCode": {
      "type": "string",
      "description": "Unique code used to identify the tax. Must contain only alphanumeric characters, underscores, and hyphens.",
      "pattern": "^[a-zA-Z0-9_-]*$"
    },
    "TaxResponse": {
      "description": "Represents a customizable tax rate that can be applied to invoices and fees",
      "type": "object",
      "allOf": [
        {
          "$ref": "#/$defs/TaxBase"
        },
        {
          "type": "object",
          "properties": {
            "code": {
              "$ref": "#/$defs/TaxCode"
            },
            "id": {
              "type": "string",
              "format": "uuid",
              "description": "Unique identifier of the tax"
            },
            "created_at": {
              "allOf": [
                {
                  "$ref": "#/$defs/DateTimeWithZone"
                },
                {
                  "description": "The effective start date of the subscription; can be past, current, or future. Date must be provided in ISO 8601 format"
                }
              ]
            }
          }
        }
      ]
    },
    "UsageBasedCharge": {
      "type": "object",
      "required": [
        "id",
        "metric_id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier of the charge"
        },
        "metric_id": {
          "type": "string",
          "description": "Unique identifier of the metric"
        },
        "charge_model": {
          "$ref": "#/$defs/ChargeModel",
          "description": "Defines the pricing model to calculate the charge"
        },
        "properties": {
          "type": "object",
          "description": "Pricing thresholds that determine the charges"
        },
        "taxes": {
          "type": "array",
          "description": "List of tax entities configured for the usage based charge.",
          "items": {
            "$ref": "#/$defs/TaxResponse"
          }
        },
        "min_amount": {
          "allOf": [
            {
              "$ref": "#/$defs/Amount"
            }
          ]
        }
      }
    }
  }
}