diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index 93d2c84725..dd397db9ca 100644 --- a/lib/plausible/billing/plans.ex +++ b/lib/plausible/billing/plans.ex @@ -5,12 +5,11 @@ defmodule Plausible.Billing.Plans do alias Plausible.Auth.User for f <- [ + :legacy_plans, :plans_v1, :plans_v2, :plans_v3, :plans_v4, - :unlisted_plans_v1, - :unlisted_plans_v2, :sandbox_plans ] do path = Application.app_dir(:plausible, ["priv", "#{f}.json"]) @@ -41,7 +40,7 @@ defmodule Plausible.Billing.Plans do owned_plan = get_regular_plan(user.subscription) cond do - Application.get_env(:plausible, :environment) == "dev" -> plans_sandbox() + Application.get_env(:plausible, :environment) == "dev" -> @sandbox_plans !owned_plan -> if v4_available, do: @plans_v4, else: @plans_v3 owned_plan.kind == :business -> @plans_v4 owned_plan.generation == 1 -> @plans_v1 @@ -57,7 +56,7 @@ defmodule Plausible.Billing.Plans do owned_plan = get_regular_plan(user.subscription) cond do - Application.get_env(:plausible, :environment) == "dev" -> plans_sandbox() + Application.get_env(:plausible, :environment) == "dev" -> @sandbox_plans owned_plan && owned_plan.generation < 4 -> @plans_v3 true -> @plans_v4 end @@ -80,12 +79,10 @@ defmodule Plausible.Billing.Plans do do: yearly_product_id end - defp find(product_id, scope \\ all()) + defp find(nil), do: nil - defp find(nil, _scope), do: nil - - defp find(product_id, scope) do - Enum.find(scope, fn plan -> + defp find(product_id) do + Enum.find(all(), fn plan -> product_id in [plan.monthly_product_id, plan.yearly_product_id] end) end @@ -220,15 +217,6 @@ defmodule Plausible.Billing.Plans do end defp all() do - @plans_v1 ++ - @unlisted_plans_v1 ++ - @plans_v2 ++ @unlisted_plans_v2 ++ @plans_v3 ++ @plans_v4 ++ plans_sandbox() - end - - defp plans_sandbox() do - case Application.get_env(:plausible, :environment) do - "dev" -> @sandbox_plans - _ -> [] - end + @legacy_plans ++ @plans_v1 ++ @plans_v2 ++ @plans_v3 ++ @plans_v4 end end diff --git a/priv/legacy_plans.json b/priv/legacy_plans.json new file mode 100644 index 0000000000..024807a6fd --- /dev/null +++ b/priv/legacy_plans.json @@ -0,0 +1,22 @@ +[ + { + "kind":"growth", + "generation": 1, + "monthly_pageview_limit":1000000, + "yearly_product_id":"590753", + "monthly_product_id":"558746", + "site_limit":50, + "team_member_limit":"unlimited", + "features":["goals","props","stats_api"] + }, + { + "kind":"growth", + "generation": 1, + "monthly_pageview_limit":150000000, + "yearly_product_id":"648089", + "monthly_product_id":null, + "site_limit":50, + "team_member_limit":"unlimited", + "features":["goals","props","stats_api"] + } +] diff --git a/priv/unlisted_plans_v1.json b/priv/unlisted_plans_v1.json deleted file mode 100644 index b7fd14b27a..0000000000 --- a/priv/unlisted_plans_v1.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "kind":"growth", - "generation":1, - "monthly_pageview_limit":150000000, - "yearly_product_id":"648089", - "monthly_product_id":null, - "site_limit":50, - "team_member_limit":"unlimited", - "features":["goals","props"] - } -] diff --git a/priv/unlisted_plans_v2.json b/priv/unlisted_plans_v2.json deleted file mode 100644 index ff635879b7..0000000000 --- a/priv/unlisted_plans_v2.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "kind":"growth", - "generation":2, - "monthly_pageview_limit":10000000, - "monthly_product_id":"655350", - "yearly_product_id":null, - "site_limit":50, - "team_member_limit":"unlimited", - "features":["goals","props"] - } -] diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs index d0f18e32ad..f98dfdbf59 100644 --- a/test/plausible/billing/plans_test.exs +++ b/test/plausible/billing/plans_test.exs @@ -2,6 +2,7 @@ defmodule Plausible.Billing.PlansTest do use Plausible.DataCase, async: true alias Plausible.Billing.Plans + @legacy_plan_id "558746" @v1_plan_id "558018" @v2_plan_id "654177" @v4_plan_id "857097" @@ -9,6 +10,11 @@ defmodule Plausible.Billing.PlansTest do @v4_business_plan_id "857105" describe "getting subscription plans for user" do + test "growth_plans_for/1 returns v1 plans for a user on a legacy plan" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: @legacy_plan_id)) + assert List.first(Plans.growth_plans_for(user)).monthly_product_id == @v1_plan_id + end + test "growth_plans_for/1 returns v1 plans for users who are already on v1 pricing" do user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id)) assert List.first(Plans.growth_plans_for(user)).monthly_product_id == @v1_plan_id @@ -40,7 +46,12 @@ defmodule Plausible.Billing.PlansTest do assert List.first(Plans.growth_plans_for(user)).monthly_product_id == @v4_plan_id end - test "business_plans_for/1 returns v3 business plans for a legacy subscriber" do + test "business_plans_for/1 returns v3 business plans for a user on a legacy plan" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: @legacy_plan_id)) + assert List.first(Plans.business_plans_for(user)).monthly_product_id == @v3_business_plan_id + end + + test "business_plans_for/1 returns v3 business plans for a v2 subscriber" do user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v2_plan_id)) business_plans = Plans.business_plans_for(user) @@ -157,6 +168,8 @@ defmodule Plausible.Billing.PlansTest do describe "yearly_product_ids/0" do test "lists yearly plan ids" do assert [ + "590753", + "648089", "572810", "590752", "597486", @@ -167,7 +180,6 @@ defmodule Plausible.Billing.PlansTest do "642354", "642356", "650653", - "648089", "653232", "653234", "653236", diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exs index 36542ba4cf..908d889048 100644 --- a/test/plausible/billing/quota_test.exs +++ b/test/plausible/billing/quota_test.exs @@ -3,6 +3,7 @@ defmodule Plausible.Billing.QuotaTest do alias Plausible.Billing.Quota alias Plausible.Billing.Feature.{Goals, RevenueGoals, Funnels, Props, StatsAPI} + @legacy_plan_id "558746" @v1_plan_id "558018" @v2_plan_id "654177" @v3_plan_id "749342" @@ -115,6 +116,12 @@ defmodule Plausible.Billing.QuotaTest do end describe "monthly_pageview_limit/1" do + test "is based on the plan if user is on a legacy plan" do + user = insert(:user, subscription: build(:subscription, paddle_plan_id: @legacy_plan_id)) + + assert Quota.monthly_pageview_limit(user.subscription) == 1_000_000 + end + test "is based on the plan if user is on a standard plan" do user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id))