From a226773da163adc2a567cf87ce69d79678edb804 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:46:55 +0300 Subject: [PATCH] Legacy plans (#3455) * replace unlisted plans with legacy plans ...and add a legacy plan that has an existing subscriber in Paddle. All legacy plans are considered generation 1 - meaning that when a user on one of these plans and they'll go to the upgrade page, then the listed plans will be v1 for Growth and v3 for Business. * remove redundant plans_sandbox function * remove the unused 'scope' argument from Plans.find * remove unused plan * add basic test coverage for legacy plans * add another plan with an existing active subscriber (fix another bug) --- lib/plausible/billing/plans.ex | 26 +++++++------------------- priv/legacy_plans.json | 22 ++++++++++++++++++++++ priv/unlisted_plans_v1.json | 12 ------------ priv/unlisted_plans_v2.json | 12 ------------ test/plausible/billing/plans_test.exs | 16 ++++++++++++++-- test/plausible/billing/quota_test.exs | 7 +++++++ 6 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 priv/legacy_plans.json delete mode 100644 priv/unlisted_plans_v1.json delete mode 100644 priv/unlisted_plans_v2.json diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index 93d2c8472..dd397db9c 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 000000000..024807a6f --- /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 b7fd14b27..000000000 --- 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 ff635879b..000000000 --- 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 d0f18e32a..f98dfdbf5 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 36542ba4c..908d88904 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))