Enable over limit notifications

pull/771/head
Uku Taht 6 years ago
parent ff32218bd0
commit 9db24f54d5

@ -12,15 +12,27 @@ defmodule Plausible.Billing.Plans do
]
@yearly_plans [
%{product_id: "572810", cost: "$48", limit: 10_000, cycle: "yearly"},
%{product_id: "590752", cost: "$96", limit: 100_000, cycle: "yearly"},
%{product_id: "597486", cost: "$144", limit: 200_000, cycle: "yearly"},
%{product_id: "597488", cost: "$216", limit: 500_000, cycle: "yearly"},
%{product_id: "597643", cost: "$384", limit: 1_000_000, cycle: "yearly"},
%{product_id: "597310", cost: "$552", limit: 2_000_000, cycle: "yearly"},
%{product_id: "597312", cost: "$792", limit: 5_000_000, cycle: "yearly"},
%{product_id: "642354", cost: "$1200", limit: 10_000_000, cycle: "yearly"},
%{product_id: "642356", cost: "$1800", limit: 20_000_000, cycle: "yearly"}
%{product_id: "572810", cost: "$48", monthly_cost: "$4", limit: 10_000, cycle: "yearly"},
%{product_id: "590752", cost: "$96", monthly_cost: "$8", limit: 100_000, cycle: "yearly"},
%{product_id: "597486", cost: "$144", monthly_cost: "$12", limit: 200_000, cycle: "yearly"},
%{product_id: "597488", cost: "$216", monthly_cost: "$18", limit: 500_000, cycle: "yearly"},
%{product_id: "597643", cost: "$384", monthly_cost: "$32", limit: 1_000_000, cycle: "yearly"},
%{product_id: "597310", cost: "$552", monthly_cost: "$46", limit: 2_000_000, cycle: "yearly"},
%{product_id: "597312", cost: "$792", monthly_cost: "$66", limit: 5_000_000, cycle: "yearly"},
%{
product_id: "642354",
cost: "$1200",
monthly_cost: "$100",
limit: 10_000_000,
cycle: "yearly"
},
%{
product_id: "642356",
cost: "$1800",
monthly_cost: "$150",
limit: 20_000_000,
cycle: "yearly"
}
]
@all_plans @monthly_plans ++ @yearly_plans
@ -52,6 +64,11 @@ defmodule Plausible.Billing.Plans do
plan[:cost] <> "/mo"
end
def suggested_plan_cost_yearly(usage) do
plan = Enum.find(@yearly_plans, fn plan -> usage < plan[:limit] end)
plan[:monthly_cost] <> "/mo"
end
defp suggested_plan(usage) do
Enum.find(@monthly_plans, fn plan -> usage < plan[:limit] end)
end

@ -113,23 +113,10 @@ defmodule PlausibleWeb.Email do
end
def over_limit_email(user, usage, last_cycle) do
yearly_plan_ids =
Plausible.Billing.Plans.plans()
|> Map.fetch!(:yearly)
|> Enum.map(fn {_limit, plan} -> plan[:product_id] end)
subject_pre =
if user.subscription.paddle_plan_id in yearly_plan_ids do
"[YEARLY] "
else
""
end
base_email()
# Temporary testing
|> to(["uku@plausible.io"])
|> to(user)
|> tag("over-limit")
|> subject("#{subject_pre}You have outgrown your Plausible subscription tier ")
|> subject("You have outgrown your Plausible subscription tier ")
|> render("over_limit.html", %{
user: user,
usage: usage,

@ -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 <%= Plausible.Billing.Plans.suggested_plan_name(@usage) %> plan which runs at <%= Plausible.Billing.Plans.suggested_plan_cost(@usage) %>. You can also go with yearly billing to get 33% off.
Based on that we recommend you select the <%= Plausible.Billing.Plans.suggested_plan_name(@usage) %> plan which runs at <%= Plausible.Billing.Plans.suggested_plan_cost(@usage) %> or <%= Plausible.Billing.Plans.suggested_plan_cost_yearly(@usage) %> when billed yearly.
<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 />

@ -64,11 +64,35 @@ defmodule Plausible.Workers.CheckUsageTest do
CheckUsage.perform(nil, nil, billing_stub)
assert_email_delivered_with(
# to: [user],
to: [user],
subject: "You have outgrown your Plausible subscription tier "
)
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, nil, billing_stub)
assert_email_delivered_with(
to: [user],
html_body: ~r/select the 100k\/mo plan which runs at \$12\/mo or \$8\/mo when billed yearly/
)
end
describe "timing" do
test "checks usage one day after the last_bill_date", %{
user: user
@ -89,7 +113,7 @@ defmodule Plausible.Workers.CheckUsageTest do
CheckUsage.perform(nil, nil, billing_stub)
assert_email_delivered_with(
# to: [user],
to: [user],
subject: "You have outgrown your Plausible subscription tier "
)
end
@ -134,7 +158,7 @@ defmodule Plausible.Workers.CheckUsageTest do
CheckUsage.perform(nil, nil, billing_stub)
assert_email_delivered_with(
# to: [user],
to: [user],
subject: "You have outgrown your Plausible subscription tier "
)
end
@ -159,7 +183,7 @@ defmodule Plausible.Workers.CheckUsageTest do
CheckUsage.perform(nil, nil, billing_stub)
assert_email_delivered_with(
# to: [user],
to: [user],
subject: "You have outgrown your Plausible subscription tier "
)
end

Loading…
Cancel
Save