# `MishkaPay.Ash.Subscribed`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/lib/mishka_pay/ash/subscribed.ex#L6)

Whether a user has a subscription that gives access now: a policy check for the host's own
resources, and `subscribed?/3` for code and templates. Members-only posts and files sold by
plan are its first use.

    policies do
      policy action(:read_members_post) do
        authorize_if {MishkaPay.Ash.Subscribed, resource: MyApp.Pay.Subscription}
      end

      policy action(:download_pro_file) do
        authorize_if {MishkaPay.Ash.Subscribed,
                      resource: MyApp.Pay.Subscription, product: ["prod_pro", "prod_team"]}
      end
    end

It reads `resource` (a `kind :subscription` resource with `belongs_to_user`) for a row of the
user with a status that gives access, in one query each time, so a cancel or a failed renewal
the webhooks brought counts at once. The row's user comes from the checkout's owner
(`MishkaPay.Ash.Owner`).

## Options

  * `:resource`: the subscription resource. Required.
  * `:price`, `:product`: a provider price or product id, or a list of them; the user needs a
    subscription to one of them. Left out, any subscription counts.
  * `:statuses`: the statuses that give access, `[:active, :trialing]` unless named. A
    trialing row counts until its `trial_end`. Add `:past_due` to keep access while the
    provider retries a failed renewal.
  * `:tenant`: the site, for `subscribed?/3`; the check takes the action's tenant. A resource
    with Ash multitenancy reads in that tenant, any other compares its `:tenant` attribute.

The check fails closed: no actor, an actor that is not a resource record, or a read that
fails, and access is refused.

# `eager_evaluate?`

# `prefer_expanded_description?`

# `requires_original_data?`

# `strict_check`

# `subscribed?`

```elixir
@spec subscribed?(Ash.Resource.t(), term(), keyword()) :: boolean()
```

Whether `user` (a record of the host's user resource, or its id) has a subscription in
`resource` that gives access now. Takes the options of the check.

# `type`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
