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 @@ +