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
Localize billing screens
Uku Tahtf16666e374bb
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.exindex 3ae8c55019..d0ff81c7e1 100644--- a/lib/plausible/billing/billing.ex+++ b/lib/plausible/billing/billing.ex@@ -211,7 +211,8 @@ defmodule Plausible.Billing douser_id: params["passthrough"],status: params["status"],next_bill_date: params["next_bill_date"],- next_bill_amount: params["unit_price"] || params["new_unit_price"]+ next_bill_amount: params["unit_price"] || params["new_unit_price"],+ currency_code: params["currency"]}enddiff --git a/lib/plausible/billing/subscription.ex b/lib/plausible/billing/subscription.exindex 7a9d2d91e1..806b217e45 100644--- a/lib/plausible/billing/subscription.ex+++ b/lib/plausible/billing/subscription.ex@@ -10,7 +10,8 @@ defmodule Plausible.Billing.Subscription do:status,:next_bill_amount,:next_bill_date,- :user_id+ :user_id,+ :currency_code]@optional_fields [:last_bill_date]@@ -25,6 +26,7 @@ defmodule Plausible.Billing.Subscription dofield :next_bill_amount, :stringfield :next_bill_date, :datefield :last_bill_date, :date+ field :currency_code, :stringbelongs_to :user, Plausible.Auth.Userdiff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.exindex 81a4966f19..5de38f183a 100644--- a/lib/plausible_web/controllers/billing_controller.ex+++ b/lib/plausible_web/controllers/billing_controller.ex@@ -81,7 +81,6 @@ defmodule PlausibleWeb.BillingController dodef upgrade(conn, _params) dousage = 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,@@ -96,8 +95,7 @@ defmodule PlausibleWeb.BillingController doif plan docycle = if plan[:monthly_product_id] == plan_id, do: "monthly", else: "yearly"- cost = if cycle == "monthly", do: plan[:monthly_cost], else: plan[:yearly_cost]- plan = Map.merge(plan, %{cycle: cycle, cost: cost, product_id: plan_id})+ plan = Map.merge(plan, %{cycle: cycle, product_id: plan_id})usage = Plausible.Billing.usage(conn.assigns[:current_user])render(conn, "upgrade_to_plan.html",diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.exindex 7d828a5d29..ab2eef03b9 100644--- a/lib/plausible_web/email.ex+++ b/lib/plausible_web/email.ex@@ -138,7 +138,8 @@ defmodule PlausibleWeb.Email do|> render("yearly_renewal_notification.html", %{user: user,date: date,- next_bill_amount: user.subscription.next_bill_amount+ next_bill_amount: user.subscription.next_bill_amount,+ currency: user.subscription.currency_code})end@@ -151,8 +152,7 @@ defmodule PlausibleWeb.Email do|> subject("Your Plausible subscription is about to expire")|> render("yearly_expiration_notification.html", %{user: user,- date: date,- next_bill_amount: user.subscription.next_bill_amount+ date: date})enddiff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eexindex c04fba6169..6a9a38fea9 100644--- a/lib/plausible_web/templates/auth/user_settings.html.eex+++ b/lib/plausible_web/templates/auth/user_settings.html.eex@@ -50,7 +50,7 @@<div class="h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900" style="width: 11.75rem;"><h4 class="font-black dark:text-gray-100">Next bill amount</h4><%= if @subscription && @subscription.status in ["active", "past_due"] do %>- <div class="py-2 text-xl font-medium dark:text-gray-100">$<%= @subscription.next_bill_amount %></div>+ <div class="py-2 text-xl font-medium dark:text-gray-100"><%= PlausibleWeb.BillingView.present_currency(@subscription.currency_code) %><%= @subscription.next_bill_amount %></div><%= if @subscription.update_url do %><%= link("Update billing info", to: @subscription.update_url, class: "text-sm text-indigo-500 font-medium") %><% end %>diff --git a/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eexindex 14907c7fda..3adcd89023 100644--- a/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex+++ b/lib/plausible_web/templates/billing/upgrade_to_plan.html.eex@@ -10,7 +10,7 @@</div><div class="w-full py-4 dark:text-gray-100">- <span>With this link you can upgrade to a plan with <b><%= PlausibleWeb.StatsView.large_number_format(@plan[:limit]) %> monthly pageviews</b></span>. You will be billed <%= @plan[:cost] %> on a <%= @plan[:cycle] %> basis.+ <span>With this link you can upgrade to a plan with <b><%= PlausibleWeb.StatsView.large_number_format(@plan[:limit]) %> monthly pageviews</b></span>, billed on a <%= @plan[:cycle] %> basis.</div><div class="mt-6 text-left">diff --git a/lib/plausible_web/templates/email/over_limit.html.eex b/lib/plausible_web/templates/email/over_limit.html.eexindex e142a82ac7..4fa5ba502a 100644--- a/lib/plausible_web/templates/email/over_limit.html.eex+++ b/lib/plausible_web/templates/email/over_limit.html.eex@@ -8,7 +8,7 @@ We don't enforce any hard limits at the moment, we're still counting your stats<br /><br />In the last billing cycle (<%= date_format(@last_cycle.first) %> to <%= date_format(@last_cycle.last) %>), your account has used <%= PlausibleWeb.StatsView.large_number_format(@usage) %> billable pageviews.<%= if @usage <= 20_000_000 do %>-Based on that we recommend you select the <%= @suggested_plan[:volume] %>/mo plan which runs at <%= @suggested_plan[:monthly_cost] %>/mo or <%= @suggested_plan[:yearly_cost] %>/yr when billed yearly.+Based on that we recommend you select the <%= @suggested_plan[:volume] %>/mo plan.<br /><br />You can upgrade your subscription using our self-serve platform. The new charge will be prorated to reflect the amount you have already paid and the time until your current subscription is supposed to expire.<br /><br />diff --git a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex b/lib/plausible_web/templates/email/trial_upgrade_email.html.eexindex a02a951bae..82f668aa39 100644--- a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex+++ b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex@@ -4,7 +4,7 @@ Thanks for exploring Plausible, a simple and privacy-friendly alternative to Goo<br /><br />In the last month, your account has used <%= PlausibleWeb.AuthView.delimit_integer(@usage) %> billable pageviews<%= if @custom_events > 0, do: " and custom events in total", else: "" %>.<%= if @usage <= 20_000_000 do %>-Based on that we recommend you select the <%= @suggested_plan[:volume] %>/mo plan which runs at <%= @suggested_plan[:monthly_cost] %>/mo or <%= @suggested_plan[:yearly_cost] %>/yr when billed yearly.+Based on that we recommend you select the <%= @suggested_plan[:volume] %>/mo plan.<br /><br /><%= link("Upgrade now", to: "#{plausible_url()}/billing/upgrade") %><br /><br />diff --git a/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex b/lib/plausible_web/templates/email/yearly_renewal_notification.html.eexindex 322945cada..8d7e650b79 100644--- a/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex+++ b/lib/plausible_web/templates/email/yearly_renewal_notification.html.eex@@ -1,6 +1,6 @@Hey <%= user_salutation(@user) %>,<br /><br />-Time flies! This is a reminder that your annual subscription for Plausible Analytics is due to renew on <%= @date %>. We will automatically charge $<%= @next_bill_amount %> from your preferred billing method.+Time flies! This is a reminder that your annual subscription for Plausible Analytics is due to renew on <%= @date %>. We will automatically charge <%= PlausibleWeb.BillingView.present_currency(@currency) %><%= @next_bill_amount %> from your preferred billing method.<br /><br />There's no action required if you're happy to continue using Plausible to count your website stats in a privacy-friendly way.<br /><br />diff --git a/priv/repo/migrations/20210513091653_add_currency_to_subscription.exs b/priv/repo/migrations/20210513091653_add_currency_to_subscription.exsnew file mode 100644index 0000000000..07393ea157--- /dev/null+++ b/priv/repo/migrations/20210513091653_add_currency_to_subscription.exs@@ -0,0 +1,15 @@+defmodule Plausible.Repo.Migrations.AddCurrencyToSubscription do+ use Ecto.Migration++ def change do+ alter table(:subscriptions) do+ add :currency_code, :string+ end++ execute "UPDATE subscriptions set currency_code='USD'"++ alter table(:subscriptions) do+ modify :currency_code, :string, null: false+ end+ end+enddiff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exsindex 0e4cc8cda2..f20a6e7967 100644--- a/test/plausible/billing/billing_test.exs+++ b/test/plausible/billing/billing_test.exs@@ -181,13 +181,15 @@ defmodule Plausible.BillingTest do"passthrough" => user.id,"status" => "active","next_bill_date" => "2019-06-01",- "unit_price" => "6.00"+ "unit_price" => "6.00",+ "currency" => "EUR"})subscription = Repo.get_by(Plausible.Billing.Subscription, user_id: user.id)assert subscription.paddle_subscription_id == @subscription_idassert subscription.next_bill_date == ~D[2019-06-01]assert subscription.next_bill_amount == "6.00"+ assert subscription.currency_code == "EUR"endtest "create with email address" do@@ -203,7 +205,8 @@ defmodule Plausible.BillingTest do"cancel_url" => "cancel_url.com","status" => "active","next_bill_date" => "2019-06-01",- "unit_price" => "6.00"+ "unit_price" => "6.00",+ "currency" => "EUR"})subscription = Repo.get_by(Plausible.Billing.Subscription, user_id: user.id)@@ -227,7 +230,8 @@ defmodule Plausible.BillingTest do"passthrough" => user.id,"status" => "active","next_bill_date" => "2019-06-01",- "new_unit_price" => "12.00"+ "new_unit_price" => "12.00",+ "currency" => "EUR"})subscription = Repo.get_by(Plausible.Billing.Subscription, user_id: user.id)diff --git a/test/support/factory.ex b/test/support/factory.exindex 35f33739b4..34407d336c 100644--- a/test/support/factory.ex+++ b/test/support/factory.ex@@ -107,7 +107,8 @@ defmodule Plausible.Factory doupdate_url: "cancel.com",status: "active",next_bill_amount: "6.00",- next_bill_date: Timex.today()+ next_bill_date: Timex.today(),+ currency_code: "USD"}enddiff --git a/test/workers/check_usage_test.exs b/test/workers/check_usage_test.exsindex de338f6537..f32256a4ad 100644--- a/test/workers/check_usage_test.exs+++ b/test/workers/check_usage_test.exs@@ -68,31 +68,6 @@ defmodule Plausible.Workers.CheckUsageTest do)end- test "includes both monthly and yearly price", %{- user: user- } do- billing_stub =- Plausible.Billing- |> stub(:last_two_billing_months_usage, fn _user -> {11_000, 11_000} end)- |> stub(:last_two_billing_cycles, fn _user ->- {Date.range(Timex.today(), Timex.today()), Date.range(Timex.today(), Timex.today())}- end)-- insert(:subscription,- user: user,- paddle_plan_id: @paddle_id_10k,- last_bill_date: Timex.shift(Timex.today(), days: -1)- )-- CheckUsage.perform(nil, billing_stub)-- assert_email_delivered_with(- to: [user],- html_body:- ~r/select the 100k\/mo plan which runs at \$12\/mo or \$120\/yr when billed yearly/- )- end-describe "timing" dotest "checks usage one day after the last_bill_date", %{user: userdiff --git a/test/workers/send_trial_notifications_test.exs b/test/workers/send_trial_notifications_test.exsindex 7548badc09..b014264ac5 100644--- a/test/workers/send_trial_notifications_test.exs+++ b/test/workers/send_trial_notifications_test.exs@@ -86,63 +86,63 @@ defmodule Plausible.Workers.SendTrialNotificationsTest douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000, 0})- assert email.html_body =~ "we recommend you select the 10k/mo plan which runs at $6/mo"+ assert email.html_body =~ "we recommend you select the 10k/mo plan."endtest "suggests 100k/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {90_000, 0})- assert email.html_body =~ "we recommend you select the 100k/mo plan which runs at $12/mo"+ assert email.html_body =~ "we recommend you select the 100k/mo plan."endtest "suggests 200k/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {180_000, 0})- assert email.html_body =~ "we recommend you select the 200k/mo plan which runs at $20/mo"+ assert email.html_body =~ "we recommend you select the 200k/mo plan."endtest "suggests 500k/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {450_000, 0})- assert email.html_body =~ "we recommend you select the 500k/mo plan which runs at $30/mo"+ assert email.html_body =~ "we recommend you select the 500k/mo plan."endtest "suggests 1m/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {900_000, 0})- assert email.html_body =~ "we recommend you select the 1M/mo plan which runs at $50/mo"+ assert email.html_body =~ "we recommend you select the 1M/mo plan."endtest "suggests 2m/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {1_800_000, 0})- assert email.html_body =~ "we recommend you select the 2M/mo plan which runs at $70/mo"+ assert email.html_body =~ "we recommend you select the 2M/mo plan."endtest "suggests 5m/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {4_500_000, 0})- assert email.html_body =~ "we recommend you select the 5M/mo plan which runs at $100/mo"+ assert email.html_body =~ "we recommend you select the 5M/mo plan."endtest "suggests 10m/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {9_000_000, 0})- assert email.html_body =~ "we recommend you select the 10M/mo plan which runs at $150/mo"+ assert email.html_body =~ "we recommend you select the 10M/mo plan."endtest "suggests 20m/mo plan" douser = insert(:user)email = PlausibleWeb.Email.trial_upgrade_email(user, "today", {19_000_000, 0})- assert email.html_body =~ "we recommend you select the 20M/mo plan which runs at $225/mo"+ assert email.html_body =~ "we recommend you select the 20M/mo plan."endtest "does not suggest a plan above that" do