mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 09:33:19 +03:00
Check lock status after subscription has been updated
This commit is contained in:
parent
145a3599c1
commit
70c6010538
@ -25,7 +25,7 @@ defmodule Plausible.Billing do
|
|||||||
subscription = Repo.get_by!(Subscription, paddle_subscription_id: params["subscription_id"])
|
subscription = Repo.get_by!(Subscription, paddle_subscription_id: params["subscription_id"])
|
||||||
changeset = Subscription.changeset(subscription, format_subscription(params))
|
changeset = Subscription.changeset(subscription, format_subscription(params))
|
||||||
|
|
||||||
Repo.update(changeset)
|
Repo.update(changeset) |> check_lock_status
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscription_cancelled(params) do
|
def subscription_cancelled(params) do
|
||||||
|
@ -310,6 +310,28 @@ defmodule Plausible.BillingTest do
|
|||||||
assert subscription.paddle_plan_id == "new-plan-id"
|
assert subscription.paddle_plan_id == "new-plan-id"
|
||||||
assert subscription.next_bill_amount == "12.00"
|
assert subscription.next_bill_amount == "12.00"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "subscription_cancelled" do
|
describe "subscription_cancelled" do
|
||||||
|
Loading…
Reference in New Issue
Block a user