diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index e3650e111..0e53d58ed 100644 --- a/lib/plausible/billing/plans.ex +++ b/lib/plausible/billing/plans.ex @@ -32,6 +32,13 @@ defmodule Plausible.Billing.Plans do monthly_cost: "$150", limit: 20_000_000, cycle: "yearly" + }, + %{ + product_id: "648089", + cost: "$4800", + monthly_cost: "$400", + limit: 150_000_000, + cycle: "yearly" } ] @@ -54,6 +61,10 @@ defmodule Plausible.Billing.Plans do } end + def for_product_id(product_id) do + Enum.find(@all_plans, fn plan -> plan[:product_id] == product_id end) + end + def suggested_plan_name(usage) do plan = suggested_plan(usage) number_format(plan[:limit]) <> "/mo" diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.ex index 3496a0059..3ce1ea128 100644 --- a/lib/plausible_web/controllers/billing_controller.ex +++ b/lib/plausible_web/controllers/billing_controller.ex @@ -76,6 +76,23 @@ defmodule PlausibleWeb.BillingController do ) end + def upgrade_to_plan(conn, %{"plan_id" => plan_id}) do + plan = Plausible.Billing.Plans.for_product_id(plan_id) + + if plan do + usage = Plausible.Billing.usage(conn.assigns[:current_user]) + + render(conn, "upgrade_to_plan.html", + usage: usage, + plan: plan, + user: conn.assigns[:current_user], + layout: {PlausibleWeb.LayoutView, "focus.html"} + ) + else + render_error(conn, 404) + end + end + def upgrade_success(conn, _params) do render(conn, "upgrade_success.html", layout: {PlausibleWeb.LayoutView, "focus.html"}) end diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index 73d2447ef..885fcbeb0 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -140,6 +140,7 @@ defmodule PlausibleWeb.Router do get "/billing/change-plan/preview/:plan_id", BillingController, :change_plan_preview post "/billing/change-plan/:new_plan_id", BillingController, :change_plan get "/billing/upgrade", BillingController, :upgrade + get "/billing/upgrade/:plan_id", BillingController, :upgrade_to_plan get "/billing/upgrade-success", BillingController, :upgrade_success get "/sites", SiteController, :index diff --git a/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex new file mode 100644 index 000000000..14907c7fd --- /dev/null +++ b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex @@ -0,0 +1,44 @@ +
+

Upgrade your free trial

+
+ +
+
+
+
+ You've used <%= PlausibleWeb.AuthView.delimit_integer(@usage) %> billable pageviews in the last 30 days +
+ +
+ With this link you can upgrade to a plan with <%= PlausibleWeb.StatsView.large_number_format(@plan[:limit]) %> monthly pageviews. You will be billed <%= @plan[:cost] %> on a <%= @plan[:cycle] %> basis. +
+ +
+ + + +
+
+ +
+

+ What happens if I go over my page views limit? +

+
+ You will never be charged extra for an occasional traffic spike. There are no surprise fees and your card will never be charged unexpectedly.

+ If your page views exceed your plan for two consecutive months, we will contact you to upgrade to a higher plan for the following month. You will have two weeks to make a decision. You can decide to continue with a higher plan or to cancel your account at that point. +
+ +
+
+
+ +
+ Questions? Contact <%= link("support@plausible.io", to: "mailto: support@plausible.io", class: "text-indigo-500") %> +
+ + + diff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.ex index fb138bf21..8c4511d1d 100644 --- a/lib/plausible_web/views/stats_view.ex +++ b/lib/plausible_web/views/stats_view.ex @@ -24,7 +24,7 @@ defmodule PlausibleWeb.StatsView do "#{thousands}k" end - n >= 1_000_000 && n < 100_000_000 -> + n >= 1_000_000 && n < 1_000_000_000 -> millions = trunc(n / 100_000) / 10 if millions == trunc(millions) do