AshBilling.Checks.HasPrice (ash_billing v0.7.0)

Copy Markdown View Source

An Ash policy check that authorizes if the current actor has an active subscription to a specific price or one of multiple allowed prices.

Uses the actor snapshot and freshness rules of AshBilling.Checks.Subscribed. Multi-item subscriptions are outside the synchronized local model; unsupported updates retain the last supported state until application remediation.

Requires a valid, non-empty :price identifier or a non-empty list of non-empty price identifiers. If :price is missing, nil, empty, whitespace-only, contains invalid elements, or is not a string/list of strings, authorization fails closed (denies access).

Usage

policies do
  # Single price
  policy action(:pro_feature) do
    authorize_if {AshBilling.Checks.HasPrice, price: "price_pro_tier"}
  end

  # Multiple allowed prices (e.g., Pro or Enterprise)
  policy action(:pro_or_enterprise_feature) do
    authorize_if {AshBilling.Checks.HasPrice, price: ["price_pro_tier", "price_enterprise_tier"]}
  end
end

Summary

Functions

eager_evaluate?()

Callback implementation for Ash.Policy.Check.eager_evaluate?/0.

prefer_expanded_description?()

Callback implementation for Ash.Policy.Check.prefer_expanded_description?/0.

requires_original_data?(_, _)

Callback implementation for Ash.Policy.Check.requires_original_data?/2.

strict_check(actor, context, opts)

Callback implementation for Ash.Policy.Check.strict_check/3.

type()

Callback implementation for Ash.Policy.Check.type/0.