From 88efccef2f374a034a50dd984457ed783c8f8bad Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 13 May 2021 11:59:33 +0300 Subject: [PATCH] Localize the /upgrade page --- lib/plausible/billing/plans.ex | 23 +++++---- .../controllers/billing_controller.ex | 1 + .../templates/billing/_plan_option.html.eex | 10 ++-- .../templates/billing/upgrade.html.eex | 48 ++++++++++++++----- priv/plans_v2.json | 14 +++--- 5 files changed, 63 insertions(+), 33 deletions(-) diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index 9ccdd4ee1..08eb6299c 100644 --- a/lib/plausible/billing/plans.ex +++ b/lib/plausible/billing/plans.ex @@ -1,21 +1,16 @@ defmodule Plausible.Billing.Plans do - @plans_v1 File.read!(Application.app_dir(:plausible) <> "/priv/plans_v1.json") - |> Jason.decode!(keys: :atoms) - @plans_v2 File.read!(Application.app_dir(:plausible) <> "/priv/plans_v2.json") - |> Jason.decode!(keys: :atoms) - @unlisted_plans_v1 [ %{limit: 150_000_000, yearly_product_id: "648089", yearly_cost: "$4800"} ] - @v2_pricing_date ~D[2021-05-11] + @v2_pricing_date ~D[2017-05-11] def plans_for(user) do raw_plans = if Timex.before?(user.inserted_at, @v2_pricing_date) do - @plans_v1 + plans_v1() else - @plans_v2 + plans_v2() end Enum.map(raw_plans, fn plan -> Map.put(plan, :volume, number_format(plan[:limit])) end) @@ -75,6 +70,16 @@ defmodule Plausible.Billing.Plans do end defp all_plans() do - @plans_v1 ++ @unlisted_plans_v1 ++ @plans_v2 + plans_v1() ++ @unlisted_plans_v1 ++ plans_v2() + end + + defp plans_v1() do + File.read!(Application.app_dir(:plausible) <> "/priv/plans_v1.json") + |> Jason.decode!(keys: :atoms) + end + + defp plans_v2() do + File.read!(Application.app_dir(:plausible) <> "/priv/plans_v2.json") + |> Jason.decode!(keys: :atoms) end end diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.ex index 52660ff2b..81a4966f1 100644 --- a/lib/plausible_web/controllers/billing_controller.ex +++ b/lib/plausible_web/controllers/billing_controller.ex @@ -81,6 +81,7 @@ defmodule PlausibleWeb.BillingController do def upgrade(conn, _params) do usage = Plausible.Billing.usage(conn.assigns[:current_user]) today = Timex.today() + IO.inspect(Plausible.Billing.Plans.plans_for(conn.assigns[:current_user])) render(conn, "upgrade.html", usage: usage, diff --git a/lib/plausible_web/templates/billing/_plan_option.html.eex b/lib/plausible_web/templates/billing/_plan_option.html.eex index d1db3b7f9..1c7cdf91c 100644 --- a/lib/plausible_web/templates/billing/_plan_option.html.eex +++ b/lib/plausible_web/templates/billing/_plan_option.html.eex @@ -1,7 +1,7 @@ - - <%= @volume %> - - <%= @monthly_price %> / mo - <%= @yearly_price %> / yr + + <%= @plan[:volume] %> + + / mo + / yr diff --git a/lib/plausible_web/templates/billing/upgrade.html.eex b/lib/plausible_web/templates/billing/upgrade.html.eex index 4c642b4f4..478679882 100644 --- a/lib/plausible_web/templates/billing/upgrade.html.eex +++ b/lib/plausible_web/templates/billing/upgrade.html.eex @@ -1,16 +1,13 @@ +