View Source Plausible.Billing.Feature behaviour (Plausible v0.0.1)
This module provides an interface for managing features, e.g. Revenue Goals, Funnels and Custom Properties.
Feature modules have functions for toggling the feature on/off and checking whether the feature is available for a site/user.
When defining new features, the following options are expected by the
__using__
macro:
:name
- an atom representing the feature name in the plan JSON file (see also Plausible.Billing.Plan).:display_name
- human-readable display name of the feature:toggle_field
- the field in the %Plausible.Site{} schema that toggles the feature. Ifnil
or not set, toggle/2 silently returns:ok
:free
- if set totrue
, makes thecheck_availability/1
function always return:ok
(no matter the user's subscription status)
Functions defined by __using__
can be overridden if needed.
Summary
Callbacks
Checks whether the site owner or the user plan includes the given feature.
Returns the human-readable display name of the feature.
Checks whether a feature is enabled or not. Returns false when the feature is disabled or the user does not have access to it.
Returns whether the feature is free to use or not.
Returns the atom representing the feature name in the plan JSON file.
Toggles the feature on and off for a site. Returns
{:error, :upgrade_required}
when toggling a feature the site owner does not
have access to.
Returns the %Plausible.Site{} field that toggles the feature on and off.
Types
@type t() ::
Plausible.Billing.Feature.RevenueGoals
| Plausible.Billing.Feature.Funnels
| Plausible.Billing.Feature.Props
| Plausible.Billing.Feature.StatsAPI
| Plausible.Billing.Feature.Goals
Callbacks
@callback check_availability(Plausible.Auth.User.t()) :: :ok | {:error, :upgrade_required} | {:error, :not_implemented}
Checks whether the site owner or the user plan includes the given feature.
@callback display_name() :: String.t()
Returns the human-readable display name of the feature.
@callback enabled?(Plausible.Site.t()) :: boolean()
Checks whether a feature is enabled or not. Returns false when the feature is disabled or the user does not have access to it.
@callback free?() :: boolean()
Returns whether the feature is free to use or not.
@callback name() :: atom()
Returns the atom representing the feature name in the plan JSON file.
@callback toggle(Plausible.Site.t(), Keyword.t()) :: :ok | {:error, :upgrade_required}
Toggles the feature on and off for a site. Returns
{:error, :upgrade_required}
when toggling a feature the site owner does not
have access to.
@callback toggle_field() :: atom()
Returns the %Plausible.Site{} field that toggles the feature on and off.
Functions
Lists all available feature modules.