Skip to content

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

Grandfather old plans

Uku Taht1b91909021c0
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index ed52a60d1f..84432c5d8f 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -8,16 +8,25 @@ defmodule Plausible.Billing.Plans do
%{limit: 150_000_000, yearly_product_id: "648089", yearly_cost: "$4800"}
]
+ @v2_pricing_date ~D[2021-05-13]
+
def plans_for(user) do
- @plans_v1 |> Enum.map(fn plan -> Map.put(plan, :volume, number_format(plan[:limit])) end)
+ raw_plans =
+ if Timex.before?(user.inserted_at, @v2_pricing_date) do
+ @plans_v1
+ else
+ @plans_v2
+ end
+
+ Enum.map(raw_plans, fn plan -> Map.put(plan, :volume, number_format(plan[:limit])) end)
end
def all_yearly_plan_ids do
- Enum.map(@plans_v1, fn plan -> plan[:yearly_product_id] end)
+ Enum.map(all_plans(), fn plan -> plan[:yearly_product_id] end)
end
def for_product_id(product_id) do
- Enum.find(@plans_v1 ++ @unlisted_plans_v1, fn plan ->
+ Enum.find(all_plans(), fn plan ->
product_id in [plan[:monthly_product_id], plan[:yearly_product_id]]
end)
end
@@ -65,6 +74,7 @@ defmodule Plausible.Billing.Plans do
PlausibleWeb.StatsView.large_number_format(num)
end
- defp plans_v1() do
+ defp all_plans() do
+ @plans_v1 ++ @unlisted_plans_v1 ++ @plans_v2
end
end
diff --git a/test/workers/check_usage_test.exs b/test/workers/check_usage_test.exs
index 5adc802303..f6924d84a6 100644
--- a/test/workers/check_usage_test.exs
+++ b/test/workers/check_usage_test.exs
@@ -7,7 +7,7 @@ defmodule Plausible.Workers.CheckUsageTest do
alias Plausible.Billing.Plans
setup [:create_user, :create_site]
- @paddle_id_10k Plans.plans_for(nil) |> List.first() |> Map.get(:monthly_product_id)
+ @paddle_id_10k "558018"
test "ignores user without subscription" do
CheckUsage.perform(nil)
diff --git a/test/workers/notify_annual_renewal_test.exs b/test/workers/notify_annual_renewal_test.exs
index ebd29e0849..3c0b0fedc3 100644
--- a/test/workers/notify_annual_renewal_test.exs
+++ b/test/workers/notify_annual_renewal_test.exs
@@ -3,12 +3,11 @@ defmodule Plausible.Workers.NotifyAnnualRenewalTest do
use Bamboo.Test
import Plausible.TestUtils
alias Plausible.Workers.NotifyAnnualRenewal
- alias Plausible.Billing.Plans
setup [:create_user, :create_site]
- @plan_10k Plans.plans_for(nil) |> List.first()
- @monthly_plan @plan_10k[:monthly_product_id]
- @yearly_plan @plan_10k[:yearly_product_id]
+ @monthly_plan "558018"
+ @yearly_plan "572810"
+ @v2_pricing_yearly_plan "653232"
test "ignores user without subscription" do
NotifyAnnualRenewal.perform(nil)
@@ -115,6 +114,23 @@ defmodule Plausible.Workers.NotifyAnnualRenewalTest do
)
end
+ test "sends renewal notification to user on v2 yearly pricing plans", %{
+ user: user
+ } do
+ insert(:subscription,
+ user: user,
+ paddle_plan_id: @v2_pricing_yearly_plan,
+ next_bill_date: Timex.shift(Timex.today(), days: 7)
+ )
+
+ NotifyAnnualRenewal.perform(nil)
+
+ assert_email_delivered_with(
+ to: [{user.name, user.email}],
+ subject: "Your Plausible subscription is up for renewal"
+ )
+ end
+
describe "expiration" do
test "if user subscription is 'deleted', notify them about expiration instead", %{user: user} do
insert(:subscription,