Update accept_traffic_until on payment succeeded notification (#3731)

* Update `accept_traffic_until` on payment succeeded notification

* full build only
This commit is contained in:
hq1 2024-01-27 10:12:15 +01:00 committed by GitHub
parent 58afe3376f
commit 712f60f37f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View File

@ -190,13 +190,19 @@ defmodule Plausible.Billing do
amount =
:erlang.float_to_binary(api_subscription["next_payment"]["amount"] / 1, decimals: 2)
subscription =
subscription
|> Subscription.changeset(%{
next_bill_amount: amount,
next_bill_date: api_subscription["next_payment"]["date"],
last_bill_date: api_subscription["last_payment"]["date"]
})
|> Repo.update!()
|> Repo.preload(:user)
Plausible.Users.update_accept_traffic_until(subscription.user)
subscription
|> Subscription.changeset(%{
next_bill_amount: amount,
next_bill_date: api_subscription["next_payment"]["date"],
last_bill_date: api_subscription["last_payment"]["date"]
})
|> Repo.update!()
end
end

View File

@ -394,6 +394,22 @@ defmodule Plausible.BillingTest do
end
describe "subscription_payment_succeeded" do
@tag :full_build_only
test "updates accept_traffic_until" do
user = insert(:user)
subscription = insert(:subscription, user: user)
refute user.accept_traffic_until
Billing.subscription_payment_succeeded(%{
"alert_name" => "subscription_payment_succeeded",
"subscription_id" => subscription.paddle_subscription_id
})
user = Plausible.Users.with_subscription(user.id)
assert user.accept_traffic_until == Date.add(user.subscription.next_bill_date, 30)
end
test "sets the next bill amount and date, last bill date" do
user = insert(:user)
subscription = insert(:subscription, user: user)