Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Fix display
Uku Tahtce649966ede1
diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.exindex 40ac2a2183..d18859662e 100644--- a/lib/plausible/billing/plans.ex+++ b/lib/plausible/billing/plans.ex@@ -74,8 +74,7 @@ defmodule Plausible.Billing.Plans dodef subscription_interval(subscription) docase for_product_id(subscription.paddle_plan_id) donil ->- enterprise_plan =- Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: subscription.user_id)+ enterprise_plan = get_enterprise_plan(subscription)enterprise_plan && enterprise_plan.billing_interval@@ -96,11 +95,7 @@ defmodule Plausible.Billing.Plans doif found doMap.fetch!(found, :limit)else- enterprise_plan =- Repo.get_by(Plausible.Billing.EnterprisePlan,- user_id: subscription.user_id,- paddle_plan_id: subscription.paddle_plan_id- )+ enterprise_plan = get_enterprise_plan(subscription)if enterprise_plan doenterprise_plan.monthly_pageview_limit@@ -114,15 +109,11 @@ defmodule Plausible.Billing.Plans doendend- def get_enterprise_plan(user) do- if user.subscription do- Repo.get_by(Plausible.Billing.EnterprisePlan,- user_id: user.id,- paddle_plan_id: user.subscription.paddle_plan_id- )- else- Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: user.id)- end+ def get_enterprise_plan(subscription) do+ Repo.get_by(Plausible.Billing.EnterprisePlan,+ user_id: subscription.user_id,+ paddle_plan_id: subscription.paddle_plan_id+ )enddef suggested_plan(user, usage) dodiff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exsindex f3c5ce34e8..25ea5de2d7 100644--- a/test/plausible_web/controllers/auth_controller_test.exs+++ b/test/plausible_web/controllers/auth_controller_test.exs@@ -489,6 +489,46 @@ defmodule PlausibleWeb.AuthControllerTest doassert html_response(conn, 200) =~ "N/A billing"end+ test "shows enterprise plan subscription", %{conn: conn, user: user} do+ insert(:subscription, paddle_plan_id: "123", user: user)++ insert(:enterprise_plan,+ paddle_plan_id: "123",+ user: user,+ monthly_pageview_limit: 10_000_000,+ billing_interval: :yearly+ )++ conn = get(conn, "/settings")+ assert html_response(conn, 200) =~ "10M pageviews"+ assert html_response(conn, 200) =~ "yearly billing"+ end++ test "shows current enterprise plan subscription when user has a new one to upgrade to", %{+ conn: conn,+ user: user+ } do+ insert(:subscription, paddle_plan_id: "123", user: user)++ insert(:enterprise_plan,+ paddle_plan_id: "123",+ user: user,+ monthly_pageview_limit: 10_000_000,+ billing_interval: :yearly+ )++ insert(:enterprise_plan,+ paddle_plan_id: "1234",+ user: user,+ monthly_pageview_limit: 20_000_000,+ billing_interval: :yearly+ )++ conn = get(conn, "/settings")+ assert html_response(conn, 200) =~ "10M pageviews"+ assert html_response(conn, 200) =~ "yearly billing"+ end+test "shows invoices for subscribed user", %{conn: conn, user: user} doinsert(:subscription,paddle_plan_id: "558018",