List plan benefits on the new upgrade page (#3444)
* change team member limits for new v4 plans * duplicate business plans with unlimited team members We need to do this because we want grandfathered users to have unlimited team members on business plans as well. Otherwise we'd have to build overrides on the subscription level when checking the limit. * refactor generating plan structs * move Plan module into a separate file * remove not needed conditions * add generation field to plans * sync the sanbox plan limits and features with plan generations * implement displaying plan benefits * add grandfathering notice * plug in the real v3 business plan IDs * optimize N/A text color for darkmode * use String.to_existing_atom instead Co-authored-by: Vini Brasil <vini@hey.com> * Remove the unnecessary part of a comment Co-authored-by: Vini Brasil <vini@hey.com> * make the Plan.new function simpler * use exlamation marks --------- Co-authored-by: Vini Brasil <vini@hey.com>pull/3391/head list
parent
957138a8ec
commit
2ada3d700f
@ -0,0 +1,95 @@
|
||||
defmodule Plausible.Billing.Plan do
|
||||
@moduledoc false
|
||||
|
||||
@derive Jason.Encoder
|
||||
@enforce_keys ~w(kind generation site_limit monthly_pageview_limit team_member_limit features volume monthly_product_id yearly_product_id)a
|
||||
defstruct @enforce_keys ++ [:monthly_cost, :yearly_cost]
|
||||
|
||||
@type t() ::
|
||||
%__MODULE__{
|
||||
kind: atom(),
|
||||
generation: non_neg_integer(),
|
||||
monthly_pageview_limit: non_neg_integer(),
|
||||
site_limit: non_neg_integer(),
|
||||
team_member_limit: non_neg_integer() | :unlimited,
|
||||
volume: String.t(),
|
||||
monthly_cost: Money.t() | nil,
|
||||
yearly_cost: Money.t() | nil,
|
||||
monthly_product_id: String.t() | nil,
|
||||
yearly_product_id: String.t() | nil,
|
||||
features: [atom()]
|
||||
}
|
||||
| :enterprise
|
||||
|
||||
def build!(raw_params, file_name) when is_map(raw_params) do
|
||||
raw_params
|
||||
|> put_kind()
|
||||
|> put_generation()
|
||||
|> put_volume()
|
||||
|> put_team_member_limit!(file_name)
|
||||
|> put_features!(file_name)
|
||||
|> new!()
|
||||
end
|
||||
|
||||
defp new!(params) do
|
||||
struct!(__MODULE__, params)
|
||||
end
|
||||
|
||||
defp put_kind(params) do
|
||||
Map.put(params, :kind, String.to_existing_atom(params.kind))
|
||||
end
|
||||
|
||||
# Due to grandfathering, we sometimes need to check the "generation"
|
||||
# (e.g. v1, v2, etc...) of a user's subscription plan. For instance,
|
||||
# on prod, the users subscribed to a v2 plan are only supposed to
|
||||
# see v2 plans when they go to the upgrade page.
|
||||
#
|
||||
# In the `dev` environment though, "sandbox" plans are used, which
|
||||
# unlike production plans, contain multiple generations of plans in
|
||||
# the same file for testing purposes.
|
||||
defp put_generation(params) do
|
||||
Map.put(params, :generation, params.generation)
|
||||
end
|
||||
|
||||
defp put_volume(params) do
|
||||
volume =
|
||||
params.monthly_pageview_limit
|
||||
|> PlausibleWeb.StatsView.large_number_format()
|
||||
|
||||
Map.put(params, :volume, volume)
|
||||
end
|
||||
|
||||
defp put_team_member_limit!(params, file_name) do
|
||||
team_member_limit =
|
||||
case params.team_member_limit do
|
||||
number when is_integer(number) ->
|
||||
number
|
||||
|
||||
"unlimited" ->
|
||||
:unlimited
|
||||
|
||||
other ->
|
||||
raise ArgumentError,
|
||||
"Failed to parse team member limit #{inspect(other)} from #{file_name}.json"
|
||||
end
|
||||
|
||||
Map.put(params, :team_member_limit, team_member_limit)
|
||||
end
|
||||
|
||||
defp put_features!(params, file_name) do
|
||||
features =
|
||||
Plausible.Billing.Feature.list()
|
||||
|> Enum.filter(fn module ->
|
||||
to_string(module.name()) in params.features
|
||||
end)
|
||||
|
||||
if length(features) == length(params.features) do
|
||||
Map.put(params, :features, features)
|
||||
else
|
||||
raise(
|
||||
ArgumentError,
|
||||
"Unrecognized feature(s) in #{inspect(params.features)} (#{file_name}.json)"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,146 +1,162 @@
|
||||
[
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"857097",
|
||||
"yearly_product_id":"857079",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"857098",
|
||||
"yearly_product_id":"857080",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"857099",
|
||||
"yearly_product_id":"857081",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"857100",
|
||||
"yearly_product_id":"857082",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"857101",
|
||||
"yearly_product_id":"857083",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"857102",
|
||||
"yearly_product_id":"857084",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"857103",
|
||||
"yearly_product_id":"857085",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"857104",
|
||||
"yearly_product_id":"857086",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"857105",
|
||||
"yearly_product_id":"857087",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"857106",
|
||||
"yearly_product_id":"857088",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"857107",
|
||||
"yearly_product_id":"857089",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"857108",
|
||||
"yearly_product_id":"857090",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"857109",
|
||||
"yearly_product_id":"857091",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"857110",
|
||||
"yearly_product_id":"857092",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"857111",
|
||||
"yearly_product_id":"857093",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"857112",
|
||||
"yearly_product_id":"857094",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props","revenue_goals","funnels","stats_api"]
|
||||
}
|
||||
]
|
||||
|
||||
@ -1,146 +1,162 @@
|
||||
[
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":1,
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"63842",
|
||||
"yearly_product_id":"63859",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"site_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":2,
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"63843",
|
||||
"yearly_product_id":"63860",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"site_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":3,
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"63844",
|
||||
"yearly_product_id":"63861",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"site_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"63845",
|
||||
"yearly_product_id":"63862",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"features":["goals","props","stats_api"]
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"63846",
|
||||
"yearly_product_id":"63863",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"features":["goals","props","stats_api"]
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"63847",
|
||||
"yearly_product_id":"63864",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"features":["goals","props","stats_api"]
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"63848",
|
||||
"yearly_product_id":"63865",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"features":["goals","props","stats_api"]
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"63849",
|
||||
"yearly_product_id":"63866",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5,
|
||||
"features":["goals","props","stats_api"]
|
||||
"team_member_limit":3,
|
||||
"features":["goals"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":3,
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"63850",
|
||||
"yearly_product_id":"63867",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":3,
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"63851",
|
||||
"yearly_product_id":"63868",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":3,
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"63852",
|
||||
"yearly_product_id":"63869",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":"unlimited",
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"63853",
|
||||
"yearly_product_id":"63870",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"63854",
|
||||
"yearly_product_id":"63871",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"63855",
|
||||
"yearly_product_id":"63872",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"63856",
|
||||
"yearly_product_id":"63873",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"generation":4,
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"63857",
|
||||
"yearly_product_id":"63874",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50,
|
||||
"team_member_limit":10,
|
||||
"features":["goals","props", "revenue_goals", "funnels","stats_api"]
|
||||
}
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue