mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
fix(portal): Hide trial duration message after subscription becomes active (#6703)
This commit is contained in:
@@ -157,6 +157,7 @@ defmodule Domain.Billing.EventHandler do
|
||||
"customer" => customer_id,
|
||||
"metadata" => subscription_metadata,
|
||||
"trial_end" => trial_end,
|
||||
"status" => status,
|
||||
"items" => %{
|
||||
"data" => [
|
||||
%{
|
||||
@@ -177,11 +178,13 @@ defmodule Domain.Billing.EventHandler do
|
||||
"metadata" => product_metadata
|
||||
}} = Billing.fetch_product(product_id)
|
||||
|
||||
subscription_trialing? = not is_nil(trial_end) and status in ["trialing", "paused"]
|
||||
|
||||
attrs =
|
||||
account_update_attrs(quantity, product_metadata, subscription_metadata, %{
|
||||
"subscription_id" => subscription_id,
|
||||
"product_name" => product_name,
|
||||
"trial_ends_at" => if(trial_end, do: DateTime.from_unix!(trial_end))
|
||||
"trial_ends_at" => if(subscription_trialing?, do: DateTime.from_unix!(trial_end))
|
||||
})
|
||||
|> Map.put(:disabled_at, nil)
|
||||
|> Map.put(:disabled_reason, nil)
|
||||
|
||||
@@ -221,6 +221,7 @@ defmodule Domain.Resources.Resource.Changeset do
|
||||
|> cast_embed(:filters, with: &cast_filter/2)
|
||||
|> unique_constraint(:ipv4, name: :resources_account_id_ipv4_index)
|
||||
|> unique_constraint(:ipv6, name: :resources_account_id_ipv6_index)
|
||||
|> unique_constraint(:type, name: :unique_internet_resource_per_account)
|
||||
end
|
||||
|
||||
def delete(%Resource{} = resource) do
|
||||
|
||||
@@ -21,10 +21,10 @@ defmodule Domain.Repo.Migrations.AddInternetResources do
|
||||
)
|
||||
|
||||
# Manual migration that needs to be run after deployment
|
||||
# Domain.Accounts.Account.Query.not_deleted()
|
||||
# (Domain.Accounts.Account.Query.not_deleted()
|
||||
# |> Domain.Repo.all()
|
||||
# |> Enum.each(fn account ->
|
||||
# Domain.Resources.create_internet_resource(account)
|
||||
# end)
|
||||
# end))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -812,6 +812,7 @@ defmodule Domain.BillingTest do
|
||||
"customer.subscription.updated",
|
||||
Stripe.subscription_object(customer_id, subscription_metadata, %{}, quantity)
|
||||
|> Map.put("trial_end", DateTime.to_unix(trial_ends_at))
|
||||
|> Map.put("status", "trialing")
|
||||
)
|
||||
|
||||
assert handle_events([event]) == :ok
|
||||
@@ -841,5 +842,37 @@ defmodule Domain.BillingTest do
|
||||
traffic_filters: false
|
||||
}
|
||||
end
|
||||
|
||||
test "resets trial ended when subscription becomes active", %{
|
||||
account: account,
|
||||
customer_id: customer_id
|
||||
} do
|
||||
account = Fixtures.Accounts.update_account(account, %{})
|
||||
|
||||
Bypass.open()
|
||||
|> Stripe.mock_fetch_customer_endpoint(account)
|
||||
|> Stripe.mock_fetch_product_endpoint("prod_Na6dGcTsmU0I4R", %{})
|
||||
|
||||
subscription_metadata = %{}
|
||||
quantity = 13
|
||||
|
||||
trial_ends_at =
|
||||
DateTime.utc_now()
|
||||
|> DateTime.add(-2, :day)
|
||||
|
||||
event =
|
||||
Stripe.build_event(
|
||||
"customer.subscription.updated",
|
||||
Stripe.subscription_object(customer_id, subscription_metadata, %{}, quantity)
|
||||
|> Map.put("trial_end", DateTime.to_unix(trial_ends_at))
|
||||
|> Map.put("status", "active")
|
||||
)
|
||||
|
||||
assert handle_events([event]) == :ok
|
||||
|
||||
assert account = Repo.get(Domain.Accounts.Account, account.id)
|
||||
|
||||
assert is_nil(account.metadata.stripe.trial_ends_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user