mirror of
https://github.com/plausible/analytics.git
synced 2024-10-26 18:32:25 +03:00
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:
parent
58afe3376f
commit
712f60f37f
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user