Fix webhook

This commit is contained in:
Uku Taht 2019-10-15 11:30:02 +08:00
parent 1bb756362d
commit b458b5a392
2 changed files with 7 additions and 1 deletions

View File

@ -8,7 +8,7 @@ defmodule Plausible.Billing do
end end
def subscription_created(params) do def subscription_created(params) do
params = if params["passthrough"] do params = if present?(params["passthrough"]) do
params params
else else
user = Repo.get_by(Plausible.Auth.User, email: params["email"]) 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"] next_bill_amount: params["unit_price"] || params["new_unit_price"]
} }
end end
defp present?(""), do: false
defp present?(nil), do: false
defp present?(_), do: true
end end

View File

@ -45,6 +45,7 @@ defmodule Plausible.BillingTest do
user = insert(:user) user = insert(:user)
Billing.subscription_created(%{ Billing.subscription_created(%{
"passthrough" => "",
"email" => user.email, "email" => user.email,
"alert_name" => "subscription_created", "alert_name" => "subscription_created",
"subscription_id" => @subscription_id, "subscription_id" => @subscription_id,