Skip to content

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

Fetch enterprise plan corretly

Uku Taht24632964034a
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex
index 6c4c0e4482..7501bc4f4e 100644
--- a/lib/plausible/billing/plans.ex
+++ b/lib/plausible/billing/plans.ex
@@ -66,7 +66,7 @@ defmodule Plausible.Billing.Plans do
Map.fetch!(found, :limit)
else
enterprise_plan =
- Repo.get_by(Plausible.Billing.EnterprisePlan, paddle_plan_id: subscription.paddle_plan_id)
+ Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: subscription.user_id)
enterprise_plan && enterprise_plan.monthly_pageview_limit
end
diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs
index 646afadaec..a2875fa649 100644
--- a/test/plausible/billing/plans_test.exs
+++ b/test/plausible/billing/plans_test.exs
@@ -18,4 +18,24 @@ defmodule Plausible.Billing.PlansTest do
assert List.first(Plans.plans_for(user))[:monthly_product_id] == @v2_plan_id
end
end
+
+ describe "allowance" do
+ 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))
+
+ assert Plans.allowance(user.subscription) == 10_000
+ end
+
+ test "is based on the enterprise plan if user is on an enterprise plan" do
+ user = insert(:user)
+
+ enterprise_plan =
+ insert(:enterprise_plan, user_id: user.id, monthly_pageview_limit: 100_000)
+
+ subscription =
+ insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id)
+
+ assert Plans.allowance(subscription) == 100_000
+ end
+ end
end