diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index 0be926cb6..5f5b9e9ef 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -244,6 +244,11 @@ defmodule Plausible.Billing do end end + @spec format_price(Money.t()) :: String.t() + def format_price(money) do + Money.to_string!(money, fractional_digits: 2, no_fraction_if_integer: true) + end + def paddle_api(), do: Application.fetch_env!(:plausible, :paddle_api) def cancelled_subscription_notice_dismiss_id(%Plausible.Auth.User{} = user) do diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing/billing.ex similarity index 50% rename from lib/plausible_web/components/billing.ex rename to lib/plausible_web/components/billing/billing.ex index 043932b45..9cc57470c 100644 --- a/lib/plausible_web/components/billing.ex +++ b/lib/plausible_web/components/billing/billing.ex @@ -4,86 +4,8 @@ defmodule PlausibleWeb.Components.Billing do use Phoenix.Component import PlausibleWeb.Components.Generic require Plausible.Billing.Subscription.Status - alias Plausible.Auth.User alias PlausibleWeb.Router.Helpers, as: Routes - alias Plausible.Billing.{Subscription, Plans, Subscriptions} - - attr(:billable_user, User, required: true) - attr(:current_user, User, required: true) - attr(:feature_mod, :atom, required: true, values: Plausible.Billing.Feature.list()) - attr(:grandfathered?, :boolean, default: false) - attr(:size, :atom, default: :sm) - attr(:rest, :global) - - def premium_feature_notice(assigns) do - ~H""" - <.notice - :if={@feature_mod.check_availability(@billable_user) !== :ok} - class="rounded-t-md rounded-b-none" - size={@size} - title="Notice" - {@rest} - > - <%= account_label(@current_user, @billable_user) %> does not have access to <%= @feature_mod.display_name() %>. To get access to this feature, - <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />. - - """ - end - - attr(:billable_user, User, required: true) - attr(:current_user, User, required: true) - attr(:limit, :integer, required: true) - attr(:resource, :string, required: true) - attr(:rest, :global) - - def limit_exceeded_notice(assigns) do - ~H""" - <.notice {@rest} title="Notice"> - <%= account_label(@current_user, @billable_user) %> is limited to <%= @limit %> <%= @resource %>. To increase this limit, - <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />. - - """ - end - - attr(:current_user, :map) - attr(:billable_user, :map) - - defp upgrade_call_to_action(assigns) do - billable_user = Plausible.Users.with_subscription(assigns.billable_user) - - plan = - Plausible.Billing.Plans.get_regular_plan(billable_user.subscription, only_non_expired: true) - - trial? = Plausible.Billing.on_trial?(assigns.billable_user) - growth? = plan && plan.kind == :growth - - cond do - assigns.billable_user.id !== assigns.current_user.id -> - ~H"please reach out to the site owner to upgrade their subscription" - - growth? || trial? -> - ~H""" - please - <.link - class="underline inline-block" - href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)} - > - upgrade your subscription - - """ - - true -> - ~H"please contact hello@plausible.io to upgrade your subscription" - end - end - - defp account_label(current_user, billable_user) do - if current_user.id == billable_user.id do - "Your account" - else - "The owner of this site" - end - end + alias Plausible.Billing.{Subscription, Subscriptions} def render_monthly_pageview_usage(%{usage: usage} = assigns) when is_map_key(usage, :last_30_days) do @@ -283,142 +205,6 @@ defmodule PlausibleWeb.Components.Billing do """ end - attr(:user, :map, required: true) - attr(:dismissable, :boolean, default: true) - - @doc """ - Given a user with a cancelled subscription, this component renders a cancelled - subscription notice. If the given user does not have a subscription or it has a - different status, this function returns an empty template. - - It also takes a dismissable argument which renders the notice dismissable (with - the help of JavaScript and localStorage). We show a dismissable notice about a - cancelled subscription across the app, but when the user dismisses it, we will - start displaying it in the account settings > subscription section instead. - - So it's either shown across the app, or only on the /settings page. Depending - on whether the localStorage flag to dismiss it has been set or not. - """ - def subscription_cancelled_notice(assigns) - - def subscription_cancelled_notice( - %{ - dismissable: true, - user: %User{subscription: %Subscription{status: Subscription.Status.deleted()}} - } = assigns - ) do - ~H""" - - """ - end - - def subscription_cancelled_notice( - %{ - dismissable: false, - user: %User{subscription: %Subscription{status: Subscription.Status.deleted()}} - } = assigns - ) do - assigns = assign(assigns, :container_id, "local-subscription-cancelled-notice") - - ~H""" - - - """ - end - - def subscription_cancelled_notice(assigns), do: ~H"" - - attr(:class, :string, default: "") - attr(:subscription, :any, default: nil) - - def subscription_past_due_notice( - %{subscription: %Subscription{status: Subscription.Status.past_due()}} = assigns - ) do - ~H""" - - """ - end - - def subscription_past_due_notice(assigns), do: ~H"" - - attr(:class, :string, default: "") - attr(:subscription, :any, default: nil) - - def subscription_paused_notice( - %{subscription: %Subscription{status: Subscription.Status.paused()}} = assigns - ) do - ~H""" - - """ - end - - def subscription_paused_notice(assigns), do: ~H"" - - def upgrade_ineligible_notice(assigns) do - ~H""" - - """ - end - def present_enterprise_plan(assigns) do ~H"""