diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index 63bbf647a..cea0b107f 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -8,7 +8,7 @@ defmodule Plausible.Billing do end def subscription_created(params) do - params = if params["passthrough"] do + params = if present?(params["passthrough"]) do params else user = Repo.get_by(Plausible.Auth.User, email: params["email"]) @@ -137,4 +137,9 @@ defmodule Plausible.Billing do next_bill_amount: params["unit_price"] || params["new_unit_price"] } end + + defp present?(""), do: false + defp present?(nil), do: false + defp present?(_), do: true + end diff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exs index 835de38cf..4452c9dcf 100644 --- a/test/plausible/billing/billing_test.exs +++ b/test/plausible/billing/billing_test.exs @@ -45,6 +45,7 @@ defmodule Plausible.BillingTest do user = insert(:user) Billing.subscription_created(%{ + "passthrough" => "", "email" => user.email, "alert_name" => "subscription_created", "subscription_id" => @subscription_id,