diff --git a/elixir/apps/domain/lib/domain/accounts/account.ex b/elixir/apps/domain/lib/domain/accounts/account.ex index 2970d19d3..d7c16a73a 100644 --- a/elixir/apps/domain/lib/domain/accounts/account.ex +++ b/elixir/apps/domain/lib/domain/accounts/account.ex @@ -17,6 +17,7 @@ defmodule Domain.Accounts.Account do field :subscription_id, :string field :product_name, :string field :billing_email, :string + field :support_type, :string end end diff --git a/elixir/apps/domain/lib/domain/accounts/account/changeset.ex b/elixir/apps/domain/lib/domain/accounts/account/changeset.ex index e41d8d142..a5e89aaca 100644 --- a/elixir/apps/domain/lib/domain/accounts/account/changeset.ex +++ b/elixir/apps/domain/lib/domain/accounts/account/changeset.ex @@ -89,7 +89,13 @@ defmodule Domain.Accounts.Account.Changeset do def stripe_metadata_changeset(stripe \\ %Account.Metadata.Stripe{}, attrs) do stripe - |> cast(attrs, [:customer_id, :subscription_id, :product_name, :billing_email]) + |> cast(attrs, [ + :customer_id, + :subscription_id, + :product_name, + :billing_email, + :support_type + ]) end def validate_account_id_or_slug(account_id_or_slug) do diff --git a/elixir/apps/domain/lib/domain/billing/event_handler.ex b/elixir/apps/domain/lib/domain/billing/event_handler.ex index c42cb81b0..75761f70f 100644 --- a/elixir/apps/domain/lib/domain/billing/event_handler.ex +++ b/elixir/apps/domain/lib/domain/billing/event_handler.ex @@ -176,12 +176,9 @@ defmodule Domain.Billing.EventHandler do }} = Billing.fetch_product(product_id) attrs = - account_update_attrs(quantity, product_metadata, subscription_metadata) - |> Map.put(:metadata, %{ - stripe: %{ - subscription_id: subscription_id, - product_name: product_name - } + account_update_attrs(quantity, product_metadata, subscription_metadata, %{ + "subscription_id" => subscription_id, + "product_name" => product_name }) |> Map.put(:disabled_at, nil) |> Map.put(:disabled_reason, nil) @@ -333,10 +330,16 @@ defmodule Domain.Billing.EventHandler do end end - defp account_update_attrs(quantity, product_metadata, subscription_metadata) do + defp account_update_attrs( + quantity, + product_metadata, + subscription_metadata, + stripe_metadata_overrides + ) do limit_fields = Accounts.Limits.__schema__(:fields) |> Enum.map(&to_string/1) + metadata_fields = ["support_type"] - features_and_limits = + params = Map.merge(product_metadata, subscription_metadata) |> Enum.flat_map(fn {feature, "true"} -> @@ -346,21 +349,28 @@ defmodule Domain.Billing.EventHandler do [{feature, false}] {key, value} -> - if key in limit_fields do - [{key, cast_limit(value)}] - else - [] + cond do + key in limit_fields -> + [{key, cast_limit(value)}] + + key in metadata_fields -> + [{key, value}] + + true -> + [] end end) |> Enum.into(%{}) - {users_count, features_and_limits} = Map.pop(features_and_limits, "users_count", quantity) - {limits, features} = Map.split(features_and_limits, limit_fields) + {users_count, params} = Map.pop(params, "users_count", quantity) + {metadata, params} = Map.split(params, metadata_fields) + {limits, features} = Map.split(params, limit_fields) limits = Map.merge(limits, %{"users_count" => users_count}) %{ features: features, - limits: limits + limits: limits, + metadata: %{stripe: Map.merge(metadata, stripe_metadata_overrides)} } end diff --git a/elixir/apps/domain/priv/repo/seeds.exs b/elixir/apps/domain/priv/repo/seeds.exs index 3671a4ec7..9420c7037 100644 --- a/elixir/apps/domain/priv/repo/seeds.exs +++ b/elixir/apps/domain/priv/repo/seeds.exs @@ -41,7 +41,8 @@ account = customer_id: "cus_PZKIfcHB6SSBA4", subscription_id: "sub_1OkGm2ADeNU9NGxvbrCCw6m3", product_name: "Enterprise", - billing_email: "fin@firez.one" + billing_email: "fin@firez.one", + support_type: "email" } }, limits: %{ diff --git a/elixir/apps/domain/test/domain/billing_test.exs b/elixir/apps/domain/test/domain/billing_test.exs index 5e02668df..fe8f5edb6 100644 --- a/elixir/apps/domain/test/domain/billing_test.exs +++ b/elixir/apps/domain/test/domain/billing_test.exs @@ -765,7 +765,7 @@ defmodule Domain.BillingTest do assert account.disabled_reason == nil end - test "updates account features and limits on subscription update", %{ + test "updates account on subscription update", %{ account: account, customer_id: customer_id } do @@ -778,7 +778,8 @@ defmodule Domain.BillingTest do "monthly_active_users_count" => "15", "service_accounts_count" => "unlimited", "gateway_groups_count" => 1, - "users_count" => 14 + "users_count" => 14, + "support_type" => "email" } }) @@ -804,6 +805,7 @@ defmodule Domain.BillingTest do assert account.metadata.stripe.customer_id == customer_id assert account.metadata.stripe.subscription_id assert account.metadata.stripe.product_name == "Enterprise" + assert account.metadata.stripe.support_type == "email" assert account.limits == %Domain.Accounts.Limits{ monthly_active_users_count: 15, diff --git a/elixir/apps/web/lib/web/components/core_components.ex b/elixir/apps/web/lib/web/components/core_components.ex index 8707f19a7..927175c30 100644 --- a/elixir/apps/web/lib/web/components/core_components.ex +++ b/elixir/apps/web/lib/web/components/core_components.ex @@ -1108,25 +1108,31 @@ defmodule Web.CoreComponents do def feature_name(%{feature: :flow_activities} = assigns) do ~H""" - See detailed flow activities (beta) + See detailed Resource access logs """ end def feature_name(%{feature: :multi_site_resources} = assigns) do ~H""" - Define globally-distributed resources (beta) + Define globally-distributed resources """ end def feature_name(%{feature: :traffic_filters} = assigns) do ~H""" - Filter traffic using protocol and port rules (beta) + Restrict access based on port and protocol rules """ end def feature_name(%{feature: :self_hosted_relays} = assigns) do ~H""" - Host your own relays (beta) + Host your own relays + """ + end + + def feature_name(%{feature: :rest_api} = assigns) do + ~H""" + REST API """ end diff --git a/elixir/apps/web/lib/web/live/settings/billing.ex b/elixir/apps/web/lib/web/live/settings/billing.ex index aad19ded1..70d21843c 100644 --- a/elixir/apps/web/lib/web/live/settings/billing.ex +++ b/elixir/apps/web/lib/web/live/settings/billing.ex @@ -84,7 +84,19 @@ defmodule Web.Settings.Billing do <%= @account.metadata.stripe.billing_email %> + + + + <.section> + <:title> + Limits + + <:help> + Upgrade your plan to increase the limits below. + + <:content> + <.vertical_table id="billing-limits"> <.vertical_table_row :if={not is_nil(@account.limits.users_count)}> <:label>
Users
@@ -166,32 +178,51 @@ defmodule Web.Settings.Billing do <.section> <:title> - Enabled Enterprise Features + Support - <:help> - For further details on enrolling in beta features, reach out to your account manager - <:content> - <.vertical_table id="features"> - <.vertical_table_row :for={ - {key, _value} <- Map.delete(Map.from_struct(@account.features), :limits) - }> - <:label><.feature_name feature={key} /> - <:value> - <% value = apply(Domain.Accounts, :"#{key}_enabled?", [@account]) %> - <.icon - :if={value == true} - name="hero-check" - class="inline-block w-5 h-5 mr-1 text-green-500" - /> - <.icon - :if={value == false} - name="hero-x-mark" - class="inline-block w-5 h-5 mr-1 text-red-500" - /> - - - +