Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Show pricing v2 when appropriate

Uku Tahtb9b37cdd34a4
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index 9f7d7062a6..ab1846e9fa 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -9,12 +9,17 @@ defmodule Plausible.Billing.Plans do
%{limit: 10_000_000, monthly_product_id: "655350", yearly_cost: "$250"}
]
- @v2_pricing_date ~D[2021-05-13]
-
def plans_for(user) do
+ v1_plans = plans_v1()
+
+ v1_plan_ids =
+ v1_plans
+ |> Enum.map(fn plan -> [plan[:monthly_product_id], plan[:yearly_product_id]] end)
+ |> List.flatten()
+
raw_plans =
- if Timex.before?(user.inserted_at, @v2_pricing_date) do
- plans_v1()
+ if user.subscription && user.subscription.paddle_plan_id in v1_plan_ids do
+ v1_plans
else
plans_v2()
end
diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs
new file mode 100644
index 0000000000..646afadaec
--- /dev/null
+++ b/test/plausible/billing/plans_test.exs
@@ -0,0 +1,21 @@
+defmodule Plausible.Billing.PlansTest do
+ use Plausible.DataCase
+ alias Plausible.Billing.Plans
+
+ @v1_plan_id "558018"
+ @v2_plan_id "654177"
+
+ describe "plans_for" do
+ test "shows v1 pricing 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.plans_for(user))[:monthly_product_id] == @v1_plan_id
+ end
+
+ test "shows v2 pricing for everyone else" do
+ user = insert(:user) |> Repo.preload(:subscription)
+
+ assert List.first(Plans.plans_for(user))[:monthly_product_id] == @v2_plan_id
+ end
+ end
+end