Show message when grace period is over

pull/1479/head
Uku Taht 5 years ago
parent e9cb8eb4e2
commit d3311898c5

@ -1,9 +1,11 @@
{
"name": "assets",
"version": "1.4.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.4.0",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.14.3",
@ -62,11 +64,11 @@
}
},
"../deps/phoenix": {
"version": "1.4.17",
"version": "1.5.13",
"license": "MIT"
},
"../deps/phoenix_html": {
"version": "2.14.2"
"version": "2.14.3"
},
"node_modules/@babel/code-frame": {
"version": "7.12.13",

@ -2,6 +2,55 @@
<%= render("_flash.html", assigns) %>
<% end %>
<%= if on_grace_period?(@conn.assigns[:current_user]) do %>
<div class="container">
<div class="rounded-md bg-yellow-100 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800">
Please upgrade your account
</h3>
<div class="mt-2 text-sm text-yellow-700">
<p>
In order to keep your stats running, we require you to upgrade your account. If you do not upgrade your account <%= grace_period_end(@conn.assigns[:current_user]) %>, we will lock your sites and they won't be accessible. <%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>
</p>
</div>
</div>
</div>
</div>
</div>
<% end %>
<%= if grace_period_over?(@conn.assigns[:current_user]) do %>
<div class="container">
<div class="rounded-md bg-yellow-100 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800">
Dashboard locked
</h3>
<div class="mt-2 text-sm text-yellow-700">
<p>
As you have outgrown your subscription tier, we kindly ask you to upgrade your subscription to accommodate your new traffic levels. <%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>
</p>
</div>
</div>
</div>
</div>
</div>
<% end %>
<%= if @conn.assigns[:current_user] && @conn.assigns[:current_user].subscription && @conn.assigns[:current_user].subscription.status == "past_due" do %>
<div class="container">
<div class="p-2 bg-yellow-100 rounded-lg sm:p-3">

@ -1,6 +1,6 @@
<div x-data="{selectedInvitation: null, invitationOpen: false, invitations: <%= Enum.map(@invitations, &({&1.invitation_id, &1})) |> Enum.into(%{}) |> Jason.encode! %>}" @keydown.escape.window="invitationOpen = false" class="container pt-6">
<%= if @needs_to_upgrade do %>
<%= if @needs_to_upgrade == {true, :no_active_subscription} do %>
<div class="rounded-md bg-yellow-100 p-4">
<div class="flex">
<div class="flex-shrink-0">

@ -55,6 +55,26 @@ defmodule PlausibleWeb.LayoutView do
end
end
def on_grace_period?(user) do
user.grace_period &&
Timex.diff(user.grace_period.end_date, Timex.today(), :days) >= 0
end
def grace_period_over?(user) do
user.grace_period &&
Timex.diff(user.grace_period.end_date, Timex.today(), :days) < 0
end
def grace_period_end(user) do
end_date = user.grace_period.end_date
case Timex.diff(end_date, Timex.today(), :days) do
0 -> "today"
1 -> "tomorrow"
n -> "within #{n} days"
end
end
@doc "http://blog.plataformatec.com.br/2018/05/nested-layouts-with-phoenix/"
def render_layout(layout, assigns, do: content) do
render(layout, Map.put(assigns, :inner_layout, content))

@ -104,13 +104,13 @@ defmodule Plausible.Workers.CheckUsage do
end
defp check_pageview_limit(subscriber, billing_mod) do
allowance = Plausible.Billing.Plans.allowance(subscriber.subscription)
allowance = Plausible.Billing.Plans.allowance(subscriber.subscription) * 1.1
{_, last_cycle} = billing_mod.last_two_billing_cycles(subscriber)
{last_last_cycle_usage, last_cycle_usage} =
billing_mod.last_two_billing_months_usage(subscriber)
if last_last_cycle_usage > allowance && last_cycle_usage > allowance do
if last_last_cycle_usage >= allowance && last_cycle_usage >= allowance do
{:over_limit, {last_cycle, last_cycle_usage}}
else
{:within_limit, {last_cycle, last_cycle_usage}}

@ -49,6 +49,28 @@ defmodule Plausible.Workers.CheckUsageTest do
assert Repo.reload(user).grace_period == nil
end
test "does not send an email if account is over the limit by less than 10%", %{
user: user
} do
billing_stub =
Plausible.Billing
|> stub(:last_two_billing_cycles, fn _user ->
{Date.range(Timex.today(), Timex.today()), Date.range(Timex.today(), Timex.today())}
end)
|> stub(:last_two_billing_months_usage, fn _user -> {10_999, 11_000} 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_no_emails_delivered()
assert Repo.reload(user).grace_period == nil
end
test "sends an email when an account is over their limit for two consecutive billing months", %{
user: user
} do

Loading…
Cancel
Save