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)
This commit is contained in:
RobertJoonas 2023-10-25 13:46:55 +03:00 committed by GitHub
parent 9798a80a5a
commit a226773da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 45 deletions

View File

@ -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

22
priv/legacy_plans.json Normal file
View File

@ -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"]
}
]

View File

@ -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"]
}
]

View File

@ -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"]
}
]

View File

@ -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",

View File

@ -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))