Localize billing screens

This commit is contained in:
Uku Taht 2021-05-13 12:42:01 +03:00
parent 547e888242
commit f16666e374
14 changed files with 47 additions and 51 deletions

View File

@ -211,7 +211,8 @@ defmodule Plausible.Billing do
user_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"]
}
end

View File

@ -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 do
field :next_bill_amount, :string
field :next_bill_date, :date
field :last_bill_date, :date
field :currency_code, :string
belongs_to :user, Plausible.Auth.User

View File

@ -81,7 +81,6 @@ 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,
@ -96,8 +95,7 @@ defmodule PlausibleWeb.BillingController do
if plan do
cycle = 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",

View File

@ -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
})
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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_id
assert subscription.next_bill_date == ~D[2019-06-01]
assert subscription.next_bill_amount == "6.00"
assert subscription.currency_code == "EUR"
end
test "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)

View File

@ -107,7 +107,8 @@ defmodule Plausible.Factory do
update_url: "cancel.com",
status: "active",
next_bill_amount: "6.00",
next_bill_date: Timex.today()
next_bill_date: Timex.today(),
currency_code: "USD"
}
end

View File

@ -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" do
test "checks usage one day after the last_bill_date", %{
user: user

View File

@ -86,63 +86,63 @@ defmodule Plausible.Workers.SendTrialNotificationsTest do
user = 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."
end
test "suggests 100k/mo plan" do
user = 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."
end
test "suggests 200k/mo plan" do
user = 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."
end
test "suggests 500k/mo plan" do
user = 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."
end
test "suggests 1m/mo plan" do
user = 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."
end
test "suggests 2m/mo plan" do
user = 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."
end
test "suggests 5m/mo plan" do
user = 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."
end
test "suggests 10m/mo plan" do
user = 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."
end
test "suggests 20m/mo plan" do
user = 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."
end
test "does not suggest a plan above that" do