Check lock status after subscription has been updated

This commit is contained in:
Uku Taht 2021-07-15 10:28:09 +03:00
parent 145a3599c1
commit 70c6010538
2 changed files with 23 additions and 1 deletions

View File

@ -25,7 +25,7 @@ defmodule Plausible.Billing do
subscription = Repo.get_by!(Subscription, paddle_subscription_id: params["subscription_id"])
changeset = Subscription.changeset(subscription, format_subscription(params))
Repo.update(changeset)
Repo.update(changeset) |> check_lock_status
end
def subscription_cancelled(params) do

View File

@ -310,6 +310,28 @@ defmodule Plausible.BillingTest do
assert subscription.paddle_plan_id == "new-plan-id"
assert subscription.next_bill_amount == "12.00"
end
test "unlocks sites if subscription is changed from past_due to active" do
user = insert(:user)
subscription = insert(:subscription, user: user, status: "past_due")
site = insert(:site, locked: true, members: [user])
Billing.subscription_updated(%{
"alert_name" => "subscription_updated",
"subscription_id" => subscription.paddle_subscription_id,
"subscription_plan_id" => "new-plan-id",
"update_url" => "update_url.com",
"cancel_url" => "cancel_url.com",
"passthrough" => user.id,
"old_status" => "past_due",
"status" => "active",
"next_bill_date" => "2019-06-01",
"new_unit_price" => "12.00",
"currency" => "EUR"
})
refute Repo.reload!(site).locked
end
end
describe "subscription_cancelled" do