Skip to content

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

Report allowance issues to Sentry

Uku Taht9c07cf7ea69a
diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.ex
index d18804d847..a2d96e4e57 100644
--- a/lib/workers/check_usage.ex
+++ b/lib/workers/check_usage.ex
@@ -104,7 +104,18 @@ defmodule Plausible.Workers.CheckUsage do
end
defp check_pageview_limit(subscriber, billing_mod) do
- allowance = Plausible.Billing.Plans.allowance(subscriber.subscription) * 1.1
+ allowance =
+ case Plausible.Billing.Plans.allowance(subscriber.subscription) do
+ allowance when is_number(allowance) ->
+ allowance * 1.1
+
+ _allowance ->
+ Sentry.capture_message("Unable to calculate allowance",
+ user: subscriber,
+ subscription: subscriber.subscription
+ )
+ end
+
{_, last_cycle} = billing_mod.last_two_billing_cycles(subscriber)
{last_last_cycle_usage, last_cycle_usage} =
diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exs
index a2875fa649..1ed1811141 100644
--- a/test/plausible/billing/plans_test.exs
+++ b/test/plausible/billing/plans_test.exs
@@ -26,6 +26,12 @@ defmodule Plausible.Billing.PlansTest do
assert Plans.allowance(user.subscription) == 10_000
end
+ test "free_10k has 10k allowance" do
+ user = insert(:user, subscription: build(:subscription, paddle_plan_id: "free_10k"))
+
+ 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)