@ -4,13 +4,14 @@ defmodule PlausibleWeb.Components.Billing do
use Phoenix.Component
import PlausibleWeb.Components.Generic
require Plausible.Billing.Subscription.Status
alias Plausible.Auth.User
alias Plausible.Billing.Feature . { RevenueGoals , Funnels }
alias Plausible.Billing.Feature . { Props , StatsAPI }
alias PlausibleWeb.Router.Helpers , as : Routes
alias Plausible.Billing . { Subscription , Plans , Plan , Subscriptions }
attr ( :billable_user , Plausible.Auth. User, required : true )
attr ( :current_user , Plausible.Auth. User, required : true )
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 )
@ -33,7 +34,7 @@ defmodule PlausibleWeb.Components.Billing do
not has_access? ->
~H """
< . notice class = " rounded-t-md rounded-b-none " size = { @size } { @rest } >
< . notice class = " rounded-t-md rounded-b-none " size = { @size } { @rest } title = " Notice " >
< % = account_label ( @current_user , @billable_user ) % > does not have access to < % = assigns . feature_mod . display_name ( ) % > . To get access to this feature ,
< . upgrade_call_to_action current_user = { @current_user } billable_user = { @billable_user } / > .
< / . notice >
@ -56,8 +57,8 @@ defmodule PlausibleWeb.Components.Billing do
end
end
attr ( :billable_user , Plausible.Auth. User, required : true )
attr ( :current_user , Plausible.Auth. User, required : true )
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 )
@ -65,7 +66,7 @@ defmodule PlausibleWeb.Components.Billing do
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
def limit_exceeded_notice ( assigns ) do
~H """
< . notice { @rest } >
< . 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 } / > .
< / . notice >
@ -215,86 +216,120 @@ 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 """
< aside id = " global-subscription-cancelled-notice " class = " container " >
< PlausibleWeb.Components.Generic . notice
dismissable_id = { Plausible.Billing . cancelled_subscription_notice_dismiss_id ( @user ) }
title = " Subscription cancelled "
theme = { :red }
class = " shadow-md dark:shadow-none "
>
< . subscription_cancelled_notice_body user = { @user } / >
< / PlausibleWeb.Components.Generic . notice >
< / aside >
"""
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 """
< aside id = { @container_id } class = " hidden " >
< PlausibleWeb.Components.Generic . notice
title = " Subscription cancelled "
theme = { :red }
class = " shadow-md dark:shadow-none "
>
< . subscription_cancelled_notice_body user = { @user } / >
< / PlausibleWeb.Components.Generic . notice >
< / aside >
< script
data - localstorage - key = { " notice_dismissed__ #{ Plausible.Billing . cancelled_subscription_notice_dismiss_id ( assigns . user ) } " }
data - container - id = { @container_id }
>
const dataset = document . currentScript . dataset
if ( localStorage [ dataset . localstorageKey ] ) {
document . getElementById ( dataset . containerId ) . classList . remove ( ' hidden ' )
}
< / script >
"""
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 """
< aside class = { @class } >
< div class = " shadow-md dark:shadow-none rounded-lg bg-yellow-100 p-4 " >
< div class = " flex " >
< div class = " flex-shrink-0 " >
< svg
class = " w-5 h-5 mt-0.5 text-yellow-800 "
viewBox = " 0 0 24 24 "
stroke = " currentColor "
fill = " none "
xmlns = " http://www.w3.org/2000/svg "
aria - hidden = " true "
>
< path
d = " M12 9V11M12 15H12.01M5.07183 19H18.9282C20.4678 19 21.4301 17.3333 20.6603 16L13.7321 4C12.9623 2.66667 11.0378 2.66667 10.268 4L3.33978 16C2.56998 17.3333 3.53223 19 5.07183 19Z "
stroke - width = " 2 "
stroke - linecap = " round "
stroke - linejoin = " round "
/ >
< / svg >
< / div >
< div class = " ml-3 flex-1 md:flex md:justify-between " >
< p class = " text-yellow-700 " >
There was a problem with your latest payment . Please update your payment information to keep using Plausible .
< / p >
< . link
href = { @subscription . update_url }
class = " whitespace-nowrap font-medium text-yellow-700 hover:text-yellow-600 "
>
Update billing info < span aria - hidden = " true " > & rarr ; < / span >
< / . link >
< / div >
< / div >
< / div >
< PlausibleWeb.Components.Generic . notice
title = " Payment failed "
class = " shadow-md dark:shadow-none "
>
There was a problem with your latest payment . Please update your payment information to keep using Plausible . < . link
href = { @subscription . update_url }
class = " whitespace-nowrap font-semibold "
> Update billing info < span aria - hidden = " true " > & rarr ; < / span > < / . link >
< / PlausibleWeb.Components.Generic . notice >
< / aside >
"""
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 """
< aside class = { @class } >
< div class = " shadow-md dark:shadow-none rounded-lg bg-red-100 p-4 " >
< div class = " flex " >
< div class = " flex-shrink-0 " >
< svg
class = " w-5 h-5 mt-0.5 text-yellow-800 "
viewBox = " 0 0 24 24 "
stroke = " currentColor "
fill = " none "
xmlns = " http://www.w3.org/2000/svg "
aria - hidden = " true "
>
< path
d = " M12 9V11M12 15H12.01M5.07183 19H18.9282C20.4678 19 21.4301 17.3333 20.6603 16L13.7321 4C12.9623 2.66667 11.0378 2.66667 10.268 4L3.33978 16C2.56998 17.3333 3.53223 19 5.07183 19Z "
stroke - width = " 2 "
stroke - linecap = " round "
stroke - linejoin = " round "
/ >
< / svg >
< / div >
< div class = " ml-3 flex-1 md:flex md:justify-between " >
< p class = " text-red-700 " >
Your subscription is paused due to failed payments . Please provide valid payment details to keep using Plausible .
< / p >
< . link
href = { @subscription . update_url }
class = " whitespace-nowrap font-medium text-red-700 hover:text-red-600 "
>
Update billing info < span aria - hidden = " true " > & rarr ; < / span >
< / . link >
< / div >
< / div >
< / div >
< PlausibleWeb.Components.Generic . notice
title = " Subscription paused "
theme = { :red }
class = " shadow-md dark:shadow-none "
>
Your subscription is paused due to failed payments . Please provide valid payment details to keep using Plausible . < . link
href = { @subscription . update_url }
class = " whitespace-nowrap font-semibold "
> Update billing info < span aria - hidden = " true " > & rarr ; < / span > < / . link >
< / PlausibleWeb.Components.Generic . notice >
< / aside >
"""
end
@ -322,10 +357,11 @@ defmodule PlausibleWeb.Components.Billing do
~H """
< div
:if = { FunWithFlags . enabled? ( :premium_features_private_preview ) && @features_to_lose != [ ] }
class = " container mt-2 "
class = " container "
>
< . notice
class = " shadow-md dark:shadow-none "
title = " Notice "
dismissable_id = { " premium_features_private_preview_end__ #{ @user . id } " }
>
Business plans are now live! The private preview of < % = PlausibleWeb.TextHelpers . pretty_join (
@ -432,6 +468,47 @@ defmodule PlausibleWeb.Components.Billing do
"""
end
defp subscription_cancelled_notice_body ( assigns ) do
if Plausible.Billing.Subscriptions . expired? ( assigns . user . subscription ) do
~H """
< . link class = " underline inline-block " href = { Plausible.Billing . upgrade_route_for ( @user ) } >
Upgrade your subscription
< / . link >
< p > to get access to your stats again . < / p >
"""
else
~H """
< p >
You have access to your stats until < span class = " font-semibold inline " > < % = Timex . format! ( @user . subscription . next_bill_date , " {Mshort} {D}, {YYYY} " ) % > < / span > .
< . link class = " underline inline-block " href = { Plausible.Billing . upgrade_route_for ( @user ) } >
Upgrade your subscription
< / . link >
to make sure you don ' t lose access.
< / p >
< . lose_grandfathering_warning user = { @user } / >
"""
end
end
defp lose_grandfathering_warning ( %{ user : %{ subscription : subscription } = user } = assigns ) do
business_tiers_available? = FunWithFlags . enabled? ( :business_tier , for : user )
plan = Plans . get_regular_plan ( subscription , only_non_expired : true )
loses_grandfathering = business_tiers_available? && plan && plan . generation < 4
assigns = assign ( assigns , :loses_grandfathering , loses_grandfathering )
~H """
< p :if = { @loses_grandfathering } class = " mt-2 " >
Please also note that by letting your subscription expire , you lose access to our grandfathered terms . If you want to subscribe again after that , your account will be offered the < . link
href = " https://plausible.io/ # pricing "
target = " _blank "
rel = " noopener noreferrer "
class = " underline "
> latest pricing < / . link > .
< / p >
"""
end
defp change_plan_or_upgrade_text ( nil ) , do : " Upgrade "
defp change_plan_or_upgrade_text ( % Subscription { status : Subscription.Status . deleted ( ) } ) ,