From 7fe50c3ef29cd9e56ceb33ddcff90ae0bacd086a Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Mon, 1 Mar 2021 16:51:57 +0200 Subject: [PATCH] Fix check_usage --- lib/plausible/billing/plans.ex | 7 +++++-- lib/workers/check_usage.ex | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.ex index 743ac9be4..e3650e111 100644 --- a/lib/plausible/billing/plans.ex +++ b/lib/plausible/billing/plans.ex @@ -74,8 +74,11 @@ defmodule Plausible.Billing.Plans do end def allowance(subscription) do - Enum.find(@all_plans, fn plan -> plan[:product_id] == subscription.paddle_plan_id end) - |> Map.fetch!(:limit) + found = Enum.find(@all_plans, fn plan -> plan[:product_id] == subscription.paddle_plan_id end) + + if found do + Map.fetch!(found, :limit) + end end defp number_format(num) do diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.ex index 5b7b0ca16..37206b46a 100644 --- a/lib/workers/check_usage.ex +++ b/lib/workers/check_usage.ex @@ -39,6 +39,7 @@ defmodule Plausible.Workers.CheckUsage do join: s in Plausible.Billing.Subscription, on: s.user_id == u.id, where: s.status == "active", + where: not is_nil(s.last_bill_date), # Accounts for situations like last_bill_date==2021-01-31 AND today==2021-03-01. Since February never reaches the 31st day, the account is checked on 2021-03-01. where: least(day_of_month(s.last_bill_date), day_of_month(last_day_of_month(^yesterday))) ==