Use Phoenix LiveView for the upgrade page (#3382)
* add a new upgrade page liveview behind a FF * Create plans_v4.json file * Add the upgrade page UI template and some basic functionalities * different content based on subscription plan existing or not * pageview slider * monthly/yearly switch * fix tests * split into 2 separate functions * rename variables * implement volume slider + read default interval/volume from plan * organize choose-plan.ex better * remove unused vars from tests * make monthly_cost and yearly_cost nil by default The actual prices for all plans are stored in Paddle. We don't need to keep the duplicates in the JSON files. * add fetch_prices/1 to PaddleApi * make v4 business ID's differ from growth ones * render actual price information from plans ...and make the prices in both growth and business plan boxes change dynamically when the pageview slider or interval is changed. * highlight current subscription plan box * add test describe block for business tier subscription * connect to live socket only on the specific LV page using focus.html * only wrap the input slider inside the form * little readability improvement * add v4 team_member_limits (after rebase with master) * extract monthly_quota_box function in user_settings When the business_tier FF is enabled, this section is different and links to the new upgrade page. * document subscription statuses * change _notice.html.eex to .heex * extract subscription status notice components * add failed payment notices to upgrade page * create class_of_element/2 convenience function for testing * add cancel_subscription mix task * implement checkout buttons * mix format * get all available plans with prices through plans.ex * use more suitable function for fetching usage * avoid double db lookups on mount * rename variable * separate functions for getting plan by product_id vs subscription * separate subscription status docs into context module * consider cancelled subscriptions * default volume by usage if no subscription plan * add enterprise-level volume option to slider * optimize for darkmode * UI improvements * display 2 months free notice for yearly billing * VAT excluded notice * note about having a business subscription in user settings * make the page pop and fit plans on screen on first render * optimize for mobile and remove background containers * change default price tag to simply 'N/A' * fix tests * Change Paddle.js integration to use JavaScript directly * rename many variables * allow users on v1 and v2 plan subscribe to 20M and 50M tiers * add a test for two months free label * make it work with a free_10k subscription * small test improvement and formatting * change other upgrade link in user settings if FF enabled * dialyzer * fix typo * add test for free_10k user * silence credo * mix format * credo - add moduledoc * credo - another moduledoc * handle calls to sentry on the api level * refactor getting regular subscription plan for LiveView * post review code style tweaks * remove unused aliases * credo - add @moduledoc false to Subscriptions * crash in cancel_subscription task when Repo update fails * readability improvements (review suggestions) * add comment about 'external_resource' module attr --------- Co-authored-by: Vinicius Brasil <vini@hey.com>pull/3389/head r2023.10.03-200
parent
16ce0f1ea8
commit
8bc86d165f
@ -0,0 +1,132 @@
|
||||
{
|
||||
"response": {
|
||||
"customer_country": "ES",
|
||||
"products": [
|
||||
{
|
||||
"currency": "EUR",
|
||||
"list_price": {
|
||||
"gross": 7.26,
|
||||
"net": 6.0,
|
||||
"tax": 1.26
|
||||
},
|
||||
"price": {
|
||||
"gross": 7.26,
|
||||
"net": 6.0,
|
||||
"tax": 1.26
|
||||
},
|
||||
"product_id": 19878,
|
||||
"product_title": "kymme tuhat",
|
||||
"subscription": {
|
||||
"frequency": 1,
|
||||
"interval": "month",
|
||||
"list_price": {
|
||||
"gross": 7.26,
|
||||
"net": 6.0,
|
||||
"tax": 1.26
|
||||
},
|
||||
"price": {
|
||||
"gross": 7.26,
|
||||
"net": 6.0,
|
||||
"tax": 1.26
|
||||
},
|
||||
"trial_days": 0
|
||||
},
|
||||
"vendor_set_prices_included_tax": false
|
||||
},
|
||||
{
|
||||
"currency": "EUR",
|
||||
"list_price": {
|
||||
"gross": 72.6,
|
||||
"net": 60.0,
|
||||
"tax": 12.6
|
||||
},
|
||||
"price": {
|
||||
"gross": 72.6,
|
||||
"net": 60.0,
|
||||
"tax": 12.6
|
||||
},
|
||||
"product_id": 20127,
|
||||
"product_title": "kymme tuhat yearly",
|
||||
"subscription": {
|
||||
"frequency": 1,
|
||||
"interval": "year",
|
||||
"list_price": {
|
||||
"gross": 72.6,
|
||||
"net": 60.0,
|
||||
"tax": 12.6
|
||||
},
|
||||
"price": {
|
||||
"gross": 72.6,
|
||||
"net": 60.0,
|
||||
"tax": 12.6
|
||||
},
|
||||
"trial_days": 0
|
||||
},
|
||||
"vendor_set_prices_included_tax": false
|
||||
},
|
||||
{
|
||||
"currency": "EUR",
|
||||
"list_price": {
|
||||
"gross": 14.93,
|
||||
"net": 12.34,
|
||||
"tax": 2.59
|
||||
},
|
||||
"price": {
|
||||
"gross": 14.93,
|
||||
"net": 12.34,
|
||||
"tax": 2.59
|
||||
},
|
||||
"product_id": 20657,
|
||||
"product_title": "sadat tuhat",
|
||||
"subscription": {
|
||||
"frequency": 1,
|
||||
"interval": "month",
|
||||
"list_price": {
|
||||
"gross": 14.93,
|
||||
"net": 12.34,
|
||||
"tax": 2.59
|
||||
},
|
||||
"price": {
|
||||
"gross": 14.93,
|
||||
"net": 12.34,
|
||||
"tax": 2.59
|
||||
},
|
||||
"trial_days": 0
|
||||
},
|
||||
"vendor_set_prices_included_tax": false
|
||||
},
|
||||
{
|
||||
"currency": "EUR",
|
||||
"list_price": {
|
||||
"gross": 145.61,
|
||||
"net": 120.34,
|
||||
"tax": 25.27
|
||||
},
|
||||
"price": {
|
||||
"gross": 145.61,
|
||||
"net": 120.34,
|
||||
"tax": 25.27
|
||||
},
|
||||
"product_id": 20658,
|
||||
"product_title": "sada tuhat yearly",
|
||||
"subscription": {
|
||||
"frequency": 1,
|
||||
"interval": "year",
|
||||
"list_price": {
|
||||
"gross": 145.61,
|
||||
"net": 120.34,
|
||||
"tax": 25.27
|
||||
},
|
||||
"price": {
|
||||
"gross": 145.61,
|
||||
"net": 120.34,
|
||||
"tax": 25.27
|
||||
},
|
||||
"trial_days": 0
|
||||
},
|
||||
"vendor_set_prices_included_tax": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
defmodule Mix.Tasks.CancelSubscription do
|
||||
@moduledoc """
|
||||
This task is meant to replicate the behavior of cancelling
|
||||
a subscription. On production, this action is initiated by
|
||||
a Paddle webhook. Currently, only the subscription status
|
||||
is changed with that action.
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
use Plausible.Repo
|
||||
alias Plausible.{Repo, Billing.Subscription}
|
||||
require Logger
|
||||
|
||||
def run([paddle_subscription_id]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
Repo.get_by!(Subscription, paddle_subscription_id: paddle_subscription_id)
|
||||
|> Subscription.changeset(%{status: "deleted"})
|
||||
|> Repo.update!()
|
||||
|
||||
Logger.info("Successfully set the subscription status to 'deleted'.")
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,22 @@
|
||||
defmodule Plausible.Billing.Subscriptions do
|
||||
@moduledoc false
|
||||
|
||||
alias Plausible.Billing.{Subscription}
|
||||
|
||||
@spec expired?(Subscription.t()) :: boolean()
|
||||
@doc """
|
||||
Returns whether the given subscription is expired. That means that the
|
||||
subscription status is `deleted` and the date until which the customer
|
||||
has paid for (i.e. `next_bill_date`) has passed.
|
||||
"""
|
||||
def expired?(subscription)
|
||||
|
||||
def expired?(%Subscription{paddle_plan_id: "free_10k"}), do: false
|
||||
|
||||
def expired?(%Subscription{status: status, next_bill_date: next_bill_date}) do
|
||||
cancelled? = status == "deleted"
|
||||
expired? = Timex.compare(next_bill_date, Timex.today()) < 0
|
||||
|
||||
cancelled? && expired?
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,648 @@
|
||||
defmodule PlausibleWeb.Live.ChoosePlan do
|
||||
@moduledoc """
|
||||
LiveView for upgrading to a plan, or changing an existing plan.
|
||||
"""
|
||||
use Phoenix.LiveView
|
||||
use Phoenix.HTML
|
||||
alias Plausible.Users
|
||||
alias Plausible.Billing.{Plans, Plan, Quota}
|
||||
alias PlausibleWeb.Router.Helpers, as: Routes
|
||||
|
||||
import PlausibleWeb.Components.Billing
|
||||
|
||||
@contact_link "https://plausible.io/contact"
|
||||
@billing_faq_link "https://plausible.io/docs/billing"
|
||||
|
||||
def mount(_params, %{"user_id" => user_id}, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign_new(:user, fn ->
|
||||
Users.with_subscription(user_id)
|
||||
end)
|
||||
|> assign_new(:usage, fn %{user: user} ->
|
||||
Quota.monthly_pageview_usage(user)
|
||||
end)
|
||||
|> assign_new(:owned_plan, fn %{user: %{subscription: subscription}} ->
|
||||
Plans.get_regular_plan(subscription, only_non_expired: true)
|
||||
end)
|
||||
|> assign_new(:current_interval, fn %{user: user} ->
|
||||
current_user_subscription_interval(user.subscription)
|
||||
end)
|
||||
|> assign_new(:available_plans, fn %{user: user} ->
|
||||
Plans.available_plans_with_prices(user)
|
||||
end)
|
||||
|> assign_new(:available_volumes, fn %{available_plans: available_plans} ->
|
||||
get_available_volumes(available_plans)
|
||||
end)
|
||||
|> assign_new(:selected_volume, fn %{
|
||||
owned_plan: owned_plan,
|
||||
usage: usage,
|
||||
available_volumes: available_volumes
|
||||
} ->
|
||||
default_selected_volume(owned_plan, usage, available_volumes)
|
||||
end)
|
||||
|> assign_new(:selected_interval, fn %{current_interval: current_interval} ->
|
||||
current_interval || :monthly
|
||||
end)
|
||||
|> assign_new(:selected_growth_plan, fn %{
|
||||
available_plans: available_plans,
|
||||
selected_volume: selected_volume
|
||||
} ->
|
||||
get_plan_by_volume(available_plans.growth, selected_volume)
|
||||
end)
|
||||
|> assign_new(:selected_business_plan, fn %{
|
||||
available_plans: available_plans,
|
||||
selected_volume: selected_volume
|
||||
} ->
|
||||
get_plan_by_volume(available_plans.business, selected_volume)
|
||||
end)
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="bg-gray-100 dark:bg-gray-900 pt-1 pb-12 sm:pb-16 text-gray-900 dark:text-gray-100">
|
||||
<div class="mx-auto max-w-7xl px-6 lg:px-8">
|
||||
<.subscription_past_due_notice class="pb-2" subscription={@user.subscription} />
|
||||
<.subscription_paused_notice class="pb-2" subscription={@user.subscription} />
|
||||
<div class="mx-auto max-w-4xl text-center">
|
||||
<p class="text-4xl font-bold tracking-tight sm:text-5xl">
|
||||
<%= if @owned_plan,
|
||||
do: "Change subscription plan",
|
||||
else: "Upgrade your account" %>
|
||||
</p>
|
||||
</div>
|
||||
<.interval_picker selected_interval={@selected_interval} />
|
||||
<.slider selected_volume={@selected_volume} available_volumes={@available_volumes} />
|
||||
<div class="mt-6 isolate mx-auto grid max-w-md grid-cols-1 gap-8 lg:mx-0 lg:max-w-none lg:grid-cols-3">
|
||||
<.plan_box
|
||||
kind={:growth}
|
||||
owned={@owned_plan && Map.get(@owned_plan, :kind) == :growth}
|
||||
plan_to_render={
|
||||
if @selected_growth_plan,
|
||||
do: @selected_growth_plan,
|
||||
else: List.last(@available_plans.growth)
|
||||
}
|
||||
available={!!@selected_growth_plan}
|
||||
{assigns}
|
||||
/>
|
||||
<.plan_box
|
||||
kind={:business}
|
||||
owned={@owned_plan && Map.get(@owned_plan, :kind) == :business}
|
||||
plan_to_render={
|
||||
if @selected_business_plan,
|
||||
do: @selected_business_plan,
|
||||
else: List.last(@available_plans.business)
|
||||
}
|
||||
available={!!@selected_business_plan}
|
||||
{assigns}
|
||||
/>
|
||||
<.enterprise_plan_box />
|
||||
</div>
|
||||
<p class="mx-auto mt-2 max-w-2xl text-center text-lg leading-8 text-gray-600 dark:text-gray-400">
|
||||
<.usage usage={@usage} />
|
||||
</p>
|
||||
<.pageview_limit_notice :if={!@owned_plan} />
|
||||
<.help_links />
|
||||
</div>
|
||||
</div>
|
||||
<.slider_styles />
|
||||
<.paddle_script />
|
||||
"""
|
||||
end
|
||||
|
||||
def handle_event("set_interval", %{"interval" => interval}, socket) do
|
||||
new_interval =
|
||||
case interval do
|
||||
"yearly" -> :yearly
|
||||
"monthly" -> :monthly
|
||||
end
|
||||
|
||||
{:noreply, assign(socket, selected_interval: new_interval)}
|
||||
end
|
||||
|
||||
def handle_event("slide", %{"slider" => index}, socket) do
|
||||
index = String.to_integer(index)
|
||||
%{available_plans: available_plans, available_volumes: available_volumes} = socket.assigns
|
||||
|
||||
new_volume =
|
||||
if index == length(available_volumes) do
|
||||
:enterprise
|
||||
else
|
||||
Enum.at(available_volumes, index)
|
||||
end
|
||||
|
||||
{:noreply,
|
||||
assign(socket,
|
||||
selected_volume: new_volume,
|
||||
selected_growth_plan: get_plan_by_volume(available_plans.growth, new_volume),
|
||||
selected_business_plan: get_plan_by_volume(available_plans.business, new_volume)
|
||||
)}
|
||||
end
|
||||
|
||||
defp default_selected_volume(%Plan{monthly_pageview_limit: limit}, _, _), do: limit
|
||||
|
||||
defp default_selected_volume(_, usage, available_volumes) do
|
||||
Enum.find(available_volumes, &(usage < &1)) || :enterprise
|
||||
end
|
||||
|
||||
defp current_user_subscription_interval(subscription) do
|
||||
case Plans.subscription_interval(subscription) do
|
||||
"yearly" -> :yearly
|
||||
"monthly" -> :monthly
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp get_plan_by_volume(_, :enterprise), do: nil
|
||||
|
||||
defp get_plan_by_volume(plans, volume) do
|
||||
Enum.find(plans, &(&1.monthly_pageview_limit == volume))
|
||||
end
|
||||
|
||||
defp interval_picker(assigns) do
|
||||
~H"""
|
||||
<div class="mt-6 flex justify-center">
|
||||
<div class="flex flex-col">
|
||||
<.two_months_free active={@selected_interval == :yearly} />
|
||||
<fieldset class="grid grid-cols-2 gap-x-1 rounded-full p-1 text-center text-xs font-semibold leading-5 ring-1 ring-inset ring-gray-300 dark:ring-gray-600">
|
||||
<label
|
||||
class={"cursor-pointer rounded-full px-2.5 py-1 #{if @selected_interval == :monthly, do: "bg-indigo-600 text-white"}"}
|
||||
phx-click="set_interval"
|
||||
phx-value-interval="monthly"
|
||||
>
|
||||
<input type="radio" name="frequency" value="monthly" class="sr-only" />
|
||||
<span>Monthly</span>
|
||||
</label>
|
||||
<label
|
||||
class={"cursor-pointer rounded-full px-2.5 py-1 #{if @selected_interval == :yearly, do: "bg-indigo-600 text-white"}"}
|
||||
phx-click="set_interval"
|
||||
phx-value-interval="yearly"
|
||||
>
|
||||
<input type="radio" name="frequency" value="yearly" class="sr-only" />
|
||||
<span>Yearly</span>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def two_months_free(assigns) do
|
||||
~H"""
|
||||
<div class="grid grid-cols-2 gap-x-1">
|
||||
<div></div>
|
||||
<span
|
||||
id="two-months-free"
|
||||
class={[
|
||||
"mb-1 block whitespace-no-wrap w-max px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 ring-1",
|
||||
@active &&
|
||||
"bg-yellow-100 ring-yellow-700 text-yellow-700 dark:text-yellow-200 dark:bg-inherit dark:ring-1 dark:ring-yellow-200",
|
||||
!@active && "text-gray-500 ring-gray-300 dark:text-gray-400 dark:ring-gray-600"
|
||||
]}
|
||||
>
|
||||
2 months free
|
||||
</span>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp slider(assigns) do
|
||||
~H"""
|
||||
<form class="mt-4 max-w-2xl mx-auto">
|
||||
<p class="text-xl text-gray-600 dark:text-gray-400 text-center">
|
||||
Monthly pageviews: <b><%= slider_value(@selected_volume, @available_volumes) %></b>
|
||||
</p>
|
||||
<input
|
||||
phx-change="slide"
|
||||
name="slider"
|
||||
class="shadow-md border border-gray-200 dark:bg-gray-600 dark:border-none"
|
||||
type="range"
|
||||
min="0"
|
||||
max={length(@available_volumes)}
|
||||
step="1"
|
||||
value={
|
||||
Enum.find_index(@available_volumes, &(&1 == @selected_volume)) || length(@available_volumes)
|
||||
}
|
||||
/>
|
||||
</form>
|
||||
"""
|
||||
end
|
||||
|
||||
defp plan_box(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
id={"#{@kind}-plan-box"}
|
||||
class={[
|
||||
"rounded-3xl px-6 sm:px-8 py-4 sm:py-6 dark:bg-gray-800",
|
||||
!@owned && "ring-1 ring-gray-300 dark:ring-gray-600",
|
||||
@owned && "ring-2 ring-indigo-600"
|
||||
]}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-x-4">
|
||||
<h3 class={[
|
||||
"text-lg font-semibold leading-8",
|
||||
!@owned && "text-gray-900 dark:text-gray-100",
|
||||
@owned && "text-indigo-600"
|
||||
]}>
|
||||
<%= String.capitalize(to_string(@kind)) %>
|
||||
</h3>
|
||||
<.current_label :if={@owned} />
|
||||
</div>
|
||||
<div>
|
||||
<.render_price_info available={@available} {assigns} />
|
||||
<%= cond do %>
|
||||
<% !@available -> %>
|
||||
<.contact_button class="bg-indigo-600 hover:bg-indigo-500 text-white" />
|
||||
<% @owned_plan && @user.subscription && @user.subscription.status in ["active", "past_due", "paused"] -> %>
|
||||
<.render_change_plan_link
|
||||
paddle_product_id={get_paddle_product_id(@plan_to_render, @selected_interval)}
|
||||
text={
|
||||
change_plan_link_text(
|
||||
@owned_plan,
|
||||
@plan_to_render,
|
||||
@current_interval,
|
||||
@selected_interval
|
||||
)
|
||||
}
|
||||
{assigns}
|
||||
/>
|
||||
<% true -> %>
|
||||
<.paddle_button
|
||||
paddle_product_id={get_paddle_product_id(@plan_to_render, @selected_interval)}
|
||||
{assigns}
|
||||
/>
|
||||
<% end %>
|
||||
</div>
|
||||
<ul
|
||||
role="list"
|
||||
class="mt-8 space-y-3 text-sm leading-6 text-gray-600 dark:text-gray-100 xl:mt-10"
|
||||
>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-indigo-600 dark:text-green-600" /> 5 products
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-indigo-600 dark:text-green-600" /> Up to 1,000 subscribers
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-indigo-600 dark:text-green-600" /> Basic analytics
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-indigo-600 dark:text-green-600" /> 48-hour support response time
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def render_price_info(%{available: false} = assigns) do
|
||||
~H"""
|
||||
<p class="mt-6 flex items-baseline gap-x-1">
|
||||
<span class="text-4xl font-bold tracking-tight text-gray-900 dark:text-white">
|
||||
Custom
|
||||
</span>
|
||||
</p>
|
||||
<p class="h-4 mt-1"></p>
|
||||
"""
|
||||
end
|
||||
|
||||
def render_price_info(assigns) do
|
||||
~H"""
|
||||
<p class="mt-6 flex items-baseline gap-x-1">
|
||||
<.price_tag
|
||||
kind={@kind}
|
||||
selected_interval={@selected_interval}
|
||||
plan_to_render={@plan_to_render}
|
||||
/>
|
||||
</p>
|
||||
<p class="mt-1 text-xs">+ VAT if applicable</p>
|
||||
"""
|
||||
end
|
||||
|
||||
defp render_change_plan_link(assigns) do
|
||||
~H"""
|
||||
<.change_plan_link
|
||||
plan_already_owned={@text == "Currently on this plan"}
|
||||
billing_details_expired={
|
||||
@user.subscription && @user.subscription.status in ["past_due", "paused"]
|
||||
}
|
||||
{assigns}
|
||||
/>
|
||||
"""
|
||||
end
|
||||
|
||||
defp change_plan_link(assigns) do
|
||||
~H"""
|
||||
<.link
|
||||
id={"#{@kind}-checkout"}
|
||||
href={"/billing/change-plan/preview/" <> @paddle_product_id}
|
||||
class={[
|
||||
"w-full mt-6 block rounded-md py-2 px-3 text-center text-sm font-semibold leading-6 text-white",
|
||||
!(@plan_already_owned || @billing_details_expired) && "bg-indigo-600 hover:bg-indigo-500",
|
||||
(@plan_already_owned || @billing_details_expired) &&
|
||||
"pointer-events-none bg-gray-400 dark:bg-gray-600"
|
||||
]}
|
||||
>
|
||||
<%= @text %>
|
||||
</.link>
|
||||
<p
|
||||
:if={@billing_details_expired && !@plan_already_owned}
|
||||
class="text-center text-sm text-red-700 dark:text-red-500"
|
||||
>
|
||||
Please update your billing details first
|
||||
</p>
|
||||
"""
|
||||
end
|
||||
|
||||
defp paddle_button(assigns) do
|
||||
~H"""
|
||||
<button
|
||||
id={"#{@kind}-checkout"}
|
||||
onclick={"Paddle.Checkout.open(#{Jason.encode!(%{product: @paddle_product_id, email: @user.email, disableLogout: true, passthrough: @user.id, success: Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success), theme: "none"})})"}
|
||||
class="w-full mt-6 block rounded-md py-2 px-3 text-center text-sm font-semibold leading-6 text-white bg-indigo-600 hover:bg-indigo-500"
|
||||
>
|
||||
Upgrade
|
||||
</button>
|
||||
"""
|
||||
end
|
||||
|
||||
defp contact_button(assigns) do
|
||||
~H"""
|
||||
<.link
|
||||
href={contact_link()}
|
||||
class={[
|
||||
"mt-6 block rounded-md py-2 px-3 text-center text-sm font-semibold leading-6 bg-gray-800 hover:bg-gray-700 text-white dark:bg-indigo-600 dark:hover:bg-indigo-500",
|
||||
@class
|
||||
]}
|
||||
>
|
||||
Contact us
|
||||
</.link>
|
||||
"""
|
||||
end
|
||||
|
||||
defp enterprise_plan_box(assigns) do
|
||||
~H"""
|
||||
<div class="rounded-3xl px-6 sm:px-8 py-4 sm:py-6 ring-1 bg-gray-900 ring-gray-900 dark:bg-gray-800 dark:ring-gray-600">
|
||||
<h3 class="text-lg font-semibold leading-8 text-white dark:text-gray-100">Enterprise</h3>
|
||||
<p class="mt-6 flex items-baseline gap-x-1">
|
||||
<span class="text-4xl font-bold tracking-tight text-white dark:text-gray-100">
|
||||
Custom
|
||||
</span>
|
||||
</p>
|
||||
<p class="h-4 mt-1"></p>
|
||||
<.contact_button class="" />
|
||||
<ul role="list" class="mt-8 space-y-3 text-sm leading-6 xl:mt-10 text-gray-300">
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" /> Unlimited products
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" /> Unlimited subscribers
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" /> Advanced analytics
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" />
|
||||
1-hour, dedicated support response time
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" /> Marketing automations
|
||||
</li>
|
||||
<li class="flex gap-x-3">
|
||||
<.check_icon class="text-white dark:text-green-600" /> Custom reporting tools
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp current_label(assigns) do
|
||||
~H"""
|
||||
<div class="flex items-center justify-between gap-x-4">
|
||||
<p
|
||||
id="current-label"
|
||||
class="rounded-full bg-indigo-600/10 px-2.5 py-1 text-xs font-semibold leading-5 text-indigo-600 dark:ring-1 dark:ring-indigo-600/40"
|
||||
>
|
||||
Current
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp check_icon(assigns) do
|
||||
~H"""
|
||||
<svg {%{class: "h-6 w-5 flex-none #{@class}", viewBox: "0 0 20 20",fill: "currentColor","aria-hidden": "true"}}>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
"""
|
||||
end
|
||||
|
||||
defp usage(assigns) do
|
||||
~H"""
|
||||
You have used <b><%= PlausibleWeb.AuthView.delimit_integer(@usage) %></b>
|
||||
billable pageviews in the last 30 days
|
||||
"""
|
||||
end
|
||||
|
||||
defp pageview_limit_notice(assigns) do
|
||||
~H"""
|
||||
<div class="mt-12 mx-auto mt-6 max-w-2xl">
|
||||
<dt>
|
||||
<p class="w-full text-center text-gray-900 dark:text-gray-100">
|
||||
<span class="text-center font-semibold leading-7">
|
||||
What happens if I go over my page views limit?
|
||||
</span>
|
||||
</p>
|
||||
</dt>
|
||||
<dd class="mt-3">
|
||||
<div class="text-justify leading-7 block text-gray-600 dark:text-gray-100">
|
||||
You will never be charged extra for an occasional traffic spike. There are no surprise fees and your card will never be charged unexpectedly. If your page views exceed your plan for two consecutive months, we will contact you to upgrade to a higher plan for the following month. You will have two weeks to make a decision. You can decide to continue with a higher plan or to cancel your account at that point.
|
||||
</div>
|
||||
</dd>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp help_links(assigns) do
|
||||
~H"""
|
||||
<div class="mt-8 text-center">
|
||||
Questions? <a class="text-indigo-600" href={contact_link()}>Contact us</a>
|
||||
or see <a class="text-indigo-600" href={billing_faq_link()}>billing FAQ</a>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
defp price_tag(%{plan_to_render: %Plan{monthly_cost: nil}} = assigns) do
|
||||
~H"""
|
||||
<span class="text-4xl font-bold tracking-tight text-gray-900">
|
||||
N/A
|
||||
</span>
|
||||
"""
|
||||
end
|
||||
|
||||
defp price_tag(%{selected_interval: :monthly} = assigns) do
|
||||
~H"""
|
||||
<span
|
||||
id={"#{@kind}-price-tag-amount"}
|
||||
class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100"
|
||||
>
|
||||
<%= @plan_to_render.monthly_cost |> format_price() %>
|
||||
</span>
|
||||
<span
|
||||
id={"#{@kind}-price-tag-interval"}
|
||||
class="text-sm font-semibold leading-6 text-gray-600 dark:text-gray-500"
|
||||
>
|
||||
/month
|
||||
</span>
|
||||
"""
|
||||
end
|
||||
|
||||
defp price_tag(%{selected_interval: :yearly} = assigns) do
|
||||
~H"""
|
||||
<span class="text-2xl font-bold w-max tracking-tight line-through text-gray-500 dark:text-gray-600 mr-1">
|
||||
<%= @plan_to_render.monthly_cost |> Money.mult!(12) |> format_price() %>
|
||||
</span>
|
||||
<span
|
||||
id={"#{@kind}-price-tag-amount"}
|
||||
class="text-4xl font-bold tracking-tight text-gray-900 dark:text-gray-100"
|
||||
>
|
||||
<%= @plan_to_render.yearly_cost |> format_price() %>
|
||||
</span>
|
||||
<span id={"#{@kind}-price-tag-interval"} class="text-sm font-semibold leading-6 text-gray-600">
|
||||
/year
|
||||
</span>
|
||||
"""
|
||||
end
|
||||
|
||||
defp paddle_script(assigns) do
|
||||
~H"""
|
||||
<script type="text/javascript" src="https://cdn.paddle.com/paddle/paddle.js">
|
||||
</script>
|
||||
<script :if={Application.get_env(:plausible, :environment) == "dev"}>
|
||||
Paddle.Environment.set('sandbox')
|
||||
</script>
|
||||
<script>
|
||||
Paddle.Setup({vendor: <%= Application.get_env(:plausible, :paddle) |> Keyword.fetch!(:vendor_id) %> })
|
||||
</script>
|
||||
"""
|
||||
end
|
||||
|
||||
defp slider_styles(assigns) do
|
||||
~H"""
|
||||
<style>
|
||||
input[type="range"] {
|
||||
-moz-appearance: none;
|
||||
-webkit-appearance: none;
|
||||
background: white;
|
||||
border-radius: 3px;
|
||||
height: 6px;
|
||||
width: 100%;
|
||||
margin-top: 25px;
|
||||
margin-bottom: 15px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input[type="range"]::-webkit-slider-thumb {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
background-color: #5f48ff;
|
||||
background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2212%22%20height%3D%228%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8%20.5v7L12%204zM0%204l4%203.5v-7z%22%20fill%3D%22%23FFFFFF%22%20fill-rule%3D%22nonzero%22%2F%3E%3C%2Fsvg%3E");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
}
|
||||
|
||||
input[type="range"]::-moz-range-thumb {
|
||||
background-color: #5f48ff;
|
||||
background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2212%22%20height%3D%228%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8%20.5v7L12%204zM0%204l4%203.5v-7z%22%20fill%3D%22%23FFFFFF%22%20fill-rule%3D%22nonzero%22%2F%3E%3C%2Fsvg%3E");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
border: 0;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
}
|
||||
|
||||
input[type="range"]::-ms-thumb {
|
||||
background-color: #5f48ff;
|
||||
background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2212%22%20height%3D%228%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M8%20.5v7L12%204zM0%204l4%203.5v-7z%22%20fill%3D%22%23FFFFFF%22%20fill-rule%3D%22nonzero%22%2F%3E%3C%2Fsvg%3E");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
}
|
||||
|
||||
input[type="range"]::-moz-focus-outer {
|
||||
border: 0;
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
end
|
||||
|
||||
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
|
||||
defp change_plan_link_text(
|
||||
%Plan{kind: from_kind, monthly_pageview_limit: from_volume},
|
||||
%Plan{kind: to_kind, monthly_pageview_limit: to_volume},
|
||||
from_interval,
|
||||
to_interval
|
||||
) do
|
||||
cond do
|
||||
from_kind == :business && to_kind == :growth ->
|
||||
"Downgrade to Growth"
|
||||
|
||||
from_kind == :growth && to_kind == :business ->
|
||||
"Upgrade to Business"
|
||||
|
||||
from_volume == to_volume && from_interval == to_interval ->
|
||||
"Currently on this plan"
|
||||
|
||||
from_volume == to_volume ->
|
||||
"Change billing interval"
|
||||
|
||||
from_volume > to_volume ->
|
||||
"Downgrade"
|
||||
|
||||
true ->
|
||||
"Upgrade"
|
||||
end
|
||||
end
|
||||
|
||||
defp get_available_volumes(%{business: business_plans, growth: growth_plans}) do
|
||||
growth_volumes = Enum.map(growth_plans, & &1.monthly_pageview_limit)
|
||||
business_volumes = Enum.map(business_plans, & &1.monthly_pageview_limit)
|
||||
|
||||
(growth_volumes ++ business_volumes)
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
defp get_paddle_product_id(%Plan{monthly_product_id: plan_id}, :monthly), do: plan_id
|
||||
defp get_paddle_product_id(%Plan{yearly_product_id: plan_id}, :yearly), do: plan_id
|
||||
|
||||
defp slider_value(:enterprise, available_volumes) do
|
||||
List.last(available_volumes)
|
||||
|> PlausibleWeb.StatsView.large_number_format()
|
||||
|> Kernel.<>("+")
|
||||
end
|
||||
|
||||
defp slider_value(volume, _) when is_integer(volume) do
|
||||
PlausibleWeb.StatsView.large_number_format(volume)
|
||||
end
|
||||
|
||||
defp contact_link(), do: @contact_link
|
||||
|
||||
defp billing_faq_link(), do: @billing_faq_link
|
||||
end
|
||||
@ -0,0 +1,4 @@
|
||||
<%= live_render(@conn, PlausibleWeb.Live.ChoosePlan,
|
||||
id: "choose-plan",
|
||||
session: %{"user_id" => @user.id}
|
||||
) %>
|
||||
@ -1,111 +0,0 @@
|
||||
<%= if assigns[:flash] do %>
|
||||
<%= render("_flash.html", assigns) %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<%= if Plausible.Auth.GracePeriod.active?(@conn.assigns[:current_user]) do %>
|
||||
<div class="container">
|
||||
<div class="rounded-md bg-yellow-100 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-yellow-800">
|
||||
<%= if Plausible.Auth.enterprise?(@conn.assigns[:current_user]) do %>
|
||||
You have outgrown your Plausible subscription tier
|
||||
<% else %>
|
||||
Please upgrade your account
|
||||
<% end %>
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-yellow-700">
|
||||
<p>
|
||||
<%= if Plausible.Auth.enterprise?(@conn.assigns[:current_user]) do %>
|
||||
In order to keep your stats running, we require you to upgrade
|
||||
your account to accommodate your new usage levels. Please contact
|
||||
us to discuss a new custom enterprise plan.
|
||||
<%= link("Contact us →", to: "mailto:enterprise@plausible.io", class: "text-sm font-medium text-yellow-800") %>
|
||||
<% else %>
|
||||
In order to keep your stats running, we require you to upgrade
|
||||
your account. If you do not upgrade your account
|
||||
<%= grace_period_end(@conn.assigns[:current_user]) %>, we will
|
||||
lock your stats and they won't be accessible.
|
||||
<%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= if Plausible.Auth.GracePeriod.expired?(@conn.assigns[:current_user]) do %>
|
||||
<div class="container">
|
||||
<div class="rounded-md bg-yellow-100 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-yellow-800">
|
||||
Dashboard locked
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-yellow-700">
|
||||
<p>
|
||||
As you have outgrown your subscription tier, we kindly ask you to
|
||||
upgrade your subscription to accommodate your new traffic levels.
|
||||
<%= link("Upgrade now →", to: "/settings", class: "text-sm font-medium text-yellow-800") %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= if @conn.assigns[:current_user] && @conn.assigns[:current_user].subscription && @conn.assigns[:current_user].subscription.status == "past_due" do %>
|
||||
<aside class="container">
|
||||
<div class="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 to: @conn.assigns.current_user.subscription.update_url, class: "whitespace-nowrap font-medium text-yellow-700 hover:text-yellow-600" do %>
|
||||
Update billing info
|
||||
<span aria-hidden="true"> →</span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<% end %>
|
||||
|
||||
<%= if @conn.assigns[:current_user] && @conn.assigns[:current_user].subscription && @conn.assigns[:current_user].subscription.status == "paused" do %>
|
||||
<aside class="container">
|
||||
<div class="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-red-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 to: @conn.assigns.current_user.subscription.update_url, class: "whitespace-nowrap font-medium text-red-700 hover:text-red-600" do %>
|
||||
Update billing info
|
||||
<span aria-hidden="true"> →</span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<% end %>
|
||||
@ -0,0 +1,106 @@
|
||||
<%= if assigns[:flash] do %>
|
||||
<%= render("_flash.html", assigns) %>
|
||||
<% end %>
|
||||
|
||||
<%= if Plausible.Auth.GracePeriod.active?(@conn.assigns[:current_user]) do %>
|
||||
<div class="container">
|
||||
<div class="rounded-md bg-yellow-100 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg
|
||||
class="h-5 w-5 text-yellow-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-yellow-800">
|
||||
<%= if Plausible.Auth.enterprise?(@conn.assigns[:current_user]) do %>
|
||||
You have outgrown your Plausible subscription tier
|
||||
<% else %>
|
||||
Please upgrade your account
|
||||
<% end %>
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-yellow-700">
|
||||
<p>
|
||||
<%= if Plausible.Auth.enterprise?(@conn.assigns[:current_user]) do %>
|
||||
In order to keep your stats running, we require you to upgrade
|
||||
your account to accommodate your new usage levels. Please contact
|
||||
us to discuss a new custom enterprise plan. <%= link("Contact us →",
|
||||
to: "mailto:enterprise@plausible.io",
|
||||
class: "text-sm font-medium text-yellow-800"
|
||||
) %>
|
||||
<% else %>
|
||||
In order to keep your stats running, we require you to upgrade
|
||||
your account. If you do not upgrade your account <%= grace_period_end(
|
||||
@conn.assigns[:current_user]
|
||||
) %>, we will
|
||||
lock your stats and they won't be accessible. <%= link("Upgrade now →",
|
||||
to: "/settings",
|
||||
class: "text-sm font-medium text-yellow-800"
|
||||
) %>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= if Plausible.Auth.GracePeriod.expired?(@conn.assigns[:current_user]) do %>
|
||||
<div class="container">
|
||||
<div class="rounded-md bg-yellow-100 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<svg
|
||||
class="h-5 w-5 text-yellow-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-yellow-800">
|
||||
Dashboard locked
|
||||
</h3>
|
||||
<div class="mt-2 text-sm text-yellow-700">
|
||||
<p>
|
||||
As you have outgrown your subscription tier, we kindly ask you to
|
||||
upgrade your subscription to accommodate your new traffic levels. <%= link(
|
||||
"Upgrade now →",
|
||||
to: "/settings",
|
||||
class: "text-sm font-medium text-yellow-800"
|
||||
) %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<.subscription_past_due_notice
|
||||
subscription={@conn.assigns[:current_user] && @conn.assigns[:current_user].subscription}
|
||||
class="container"
|
||||
/>
|
||||
|
||||
<.subscription_paused_notice
|
||||
subscription={@conn.assigns[:current_user] && @conn.assigns[:current_user].subscription}
|
||||
class="container"
|
||||
/>
|
||||
@ -0,0 +1,130 @@
|
||||
[
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"change-me-749342",
|
||||
"yearly_product_id":"change-me-749343",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"change-me-749344",
|
||||
"yearly_product_id":"change-me-749345",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"change-me-749346",
|
||||
"yearly_product_id":"change-me-749347",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"change-me-749348",
|
||||
"yearly_product_id":"change-me-749349",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"change-me-749350",
|
||||
"yearly_product_id":"change-me-749352",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"change-me-749353",
|
||||
"yearly_product_id":"change-me-749355",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"change-me-749356",
|
||||
"yearly_product_id":"change-me-749357",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"growth",
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"change-me-749358",
|
||||
"yearly_product_id":"change-me-749359",
|
||||
"site_limit":10,
|
||||
"team_member_limit":5
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":10000,
|
||||
"monthly_product_id":"change-me-b749342",
|
||||
"yearly_product_id":"change-me-b749343",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":100000,
|
||||
"monthly_product_id":"change-me-b749344",
|
||||
"yearly_product_id":"change-me-b749345",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":200000,
|
||||
"monthly_product_id":"change-me-b749346",
|
||||
"yearly_product_id":"change-me-b749347",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":500000,
|
||||
"monthly_product_id":"change-me-b749348",
|
||||
"yearly_product_id":"change-me-b749349",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":1000000,
|
||||
"monthly_product_id":"change-me-b749350",
|
||||
"yearly_product_id":"change-me-b749352",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":2000000,
|
||||
"monthly_product_id":"change-me-b749353",
|
||||
"yearly_product_id":"change-me-b749355",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":5000000,
|
||||
"monthly_product_id":"change-me-b749356",
|
||||
"yearly_product_id":"change-me-b749357",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
},
|
||||
{
|
||||
"kind":"business",
|
||||
"monthly_pageview_limit":10000000,
|
||||
"monthly_product_id":"change-me-b749358",
|
||||
"yearly_product_id":"change-me-b749359",
|
||||
"site_limit":50,
|
||||
"team_member_limit":50
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,36 @@
|
||||
defmodule Plausible.Billing.PaddleApiTest do
|
||||
use Plausible.DataCase
|
||||
|
||||
import Mox
|
||||
setup :verify_on_exit!
|
||||
|
||||
@success "fixture/paddle_prices_success_response.json" |> File.read!() |> Jason.decode!()
|
||||
|
||||
describe "fetch_prices/1" do
|
||||
test "returns %Money{} structs per product_id when given a list of product_ids" do
|
||||
expect(
|
||||
Plausible.HTTPClient.Mock,
|
||||
:get,
|
||||
fn "https://checkout.paddle.com/api/2.0/prices",
|
||||
[{"content-type", "application/json"}, {"accept", "application/json"}],
|
||||
%{product_ids: "19878,20127,20657,20658"} ->
|
||||
{:ok,
|
||||
%Finch.Response{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
body: @success
|
||||
}}
|
||||
end
|
||||
)
|
||||
|
||||
assert Plausible.Billing.PaddleApi.fetch_prices(["19878", "20127", "20657", "20658"]) ==
|
||||
{:ok,
|
||||
%{
|
||||
"19878" => Money.new(:EUR, "6.0"),
|
||||
"20127" => Money.new(:EUR, "60.0"),
|
||||
"20657" => Money.new(:EUR, "12.34"),
|
||||
"20658" => Money.new(:EUR, "120.34")
|
||||
}}
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,516 @@
|
||||
defmodule PlausibleWeb.Live.ChoosePlanTest do
|
||||
alias Plausible.{Repo, Billing.Subscription}
|
||||
use PlausibleWeb.ConnCase, async: true
|
||||
import Phoenix.LiveViewTest
|
||||
import Plausible.Test.Support.HTML
|
||||
|
||||
@v1_10k_yearly_plan_id "572810"
|
||||
@v4_growth_200k_yearly_plan_id "change-me-749347"
|
||||
@v4_business_5m_monthly_plan_id "change-me-b749356"
|
||||
|
||||
@monthly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="monthly"]/
|
||||
@yearly_interval_button ~s/label[phx-click="set_interval"][phx-value-interval="yearly"]/
|
||||
@interval_button_active_class "bg-indigo-600 text-white"
|
||||
@slider_input ~s/input[name="slider"]/
|
||||
@two_months_free "#two-months-free"
|
||||
|
||||
@growth_plan_box "#growth-plan-box"
|
||||
@growth_price_tag_amount "#growth-price-tag-amount"
|
||||
@growth_price_tag_interval "#growth-price-tag-interval"
|
||||
@growth_current_label "#{@growth_plan_box} #current-label"
|
||||
@growth_checkout_button "#growth-checkout"
|
||||
|
||||
@business_plan_box "#business-plan-box"
|
||||
@business_price_tag_amount "#business-price-tag-amount"
|
||||
@business_price_tag_interval "#business-price-tag-interval"
|
||||
@business_current_label "#{@business_plan_box} #current-label"
|
||||
@business_checkout_button "#business-checkout"
|
||||
|
||||
describe "for a user with no subscription" do
|
||||
setup [:create_user, :log_in]
|
||||
|
||||
test "displays basic page content", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
|
||||
assert doc =~ "Upgrade your account"
|
||||
assert doc =~ "You have used <b>0</b>\nbillable pageviews in the last 30 days"
|
||||
assert doc =~ "Questions?"
|
||||
assert doc =~ "What happens if I go over my page views limit?"
|
||||
assert doc =~ "Enterprise"
|
||||
assert doc =~ "+ VAT if applicable"
|
||||
end
|
||||
|
||||
test "changing billing interval changes two months free colour", %{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
assert class_of_element(doc, @two_months_free) =~ "text-gray-500"
|
||||
refute class_of_element(doc, @two_months_free) =~ "text-yellow-700"
|
||||
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
refute class_of_element(doc, @two_months_free) =~ "text-gray-500"
|
||||
assert class_of_element(doc, @two_months_free) =~ "text-yellow-700"
|
||||
end
|
||||
|
||||
test "default billing interval is monthly, and can switch to yearly", %{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
assert class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class
|
||||
refute class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class
|
||||
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
refute class_of_element(doc, @monthly_interval_button) =~ @interval_button_active_class
|
||||
assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class
|
||||
end
|
||||
|
||||
test "default pageview limit is 10k", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "Monthly pageviews: <b>10k</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€10"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€90"
|
||||
end
|
||||
|
||||
test "pageview slider changes selected volume and prices shown", %{conn: conn} do
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 1})
|
||||
assert doc =~ "Monthly pageviews: <b>100k</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€20"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€100"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 2})
|
||||
assert doc =~ "Monthly pageviews: <b>200k</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€30"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€110"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 3})
|
||||
assert doc =~ "Monthly pageviews: <b>500k</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€40"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€120"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 4})
|
||||
assert doc =~ "Monthly pageviews: <b>1M</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€50"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€130"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 5})
|
||||
assert doc =~ "Monthly pageviews: <b>2M</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€60"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€140"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 6})
|
||||
assert doc =~ "Monthly pageviews: <b>5M</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€70"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€150"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 7})
|
||||
assert doc =~ "Monthly pageviews: <b>10M</b"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€80"
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€160"
|
||||
end
|
||||
|
||||
test "renders contact links for business and growth tiers when enterprise-level volume selected",
|
||||
%{
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 8})
|
||||
|
||||
assert text_of_element(doc, @growth_plan_box) =~ "Custom"
|
||||
assert text_of_element(doc, @growth_plan_box) =~ "Contact us"
|
||||
assert text_of_element(doc, @business_plan_box) =~ "Custom"
|
||||
assert text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 7})
|
||||
|
||||
refute text_of_element(doc, @growth_plan_box) =~ "Custom"
|
||||
refute text_of_element(doc, @growth_plan_box) =~ "Contact us"
|
||||
refute text_of_element(doc, @business_plan_box) =~ "Custom"
|
||||
refute text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
end
|
||||
|
||||
test "switching billing interval changes business and growth prices", %{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€10"
|
||||
assert text_of_element(doc, @growth_price_tag_interval) == "/month"
|
||||
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€90"
|
||||
assert text_of_element(doc, @business_price_tag_interval) == "/month"
|
||||
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€100"
|
||||
assert text_of_element(doc, @growth_price_tag_interval) == "/year"
|
||||
|
||||
assert text_of_element(doc, @business_price_tag_amount) == "€900"
|
||||
assert text_of_element(doc, @business_price_tag_interval) == "/year"
|
||||
end
|
||||
|
||||
test "checkout buttons are 'paddle buttons' with dynamic onclick attribute", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
element(lv, @slider_input) |> render_change(%{slider: 2})
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
assert %{
|
||||
"disableLogout" => true,
|
||||
"email" => user.email,
|
||||
"passthrough" => user.id,
|
||||
"product" => @v4_growth_200k_yearly_plan_id,
|
||||
"success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),
|
||||
"theme" => "none"
|
||||
} == get_paddle_checkout_params(find(doc, @growth_checkout_button))
|
||||
|
||||
element(lv, @slider_input) |> render_change(%{slider: 6})
|
||||
doc = element(lv, @monthly_interval_button) |> render_click()
|
||||
|
||||
assert get_paddle_checkout_params(find(doc, @business_checkout_button))["product"] ==
|
||||
@v4_business_5m_monthly_plan_id
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a user with a v4 growth subscription plan" do
|
||||
setup [:create_user, :log_in, :subscribe_v4_growth]
|
||||
|
||||
test "displays basic page content", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
|
||||
assert doc =~ "Change subscription plan"
|
||||
assert doc =~ "Questions?"
|
||||
refute doc =~ "What happens if I go over my page views limit?"
|
||||
end
|
||||
|
||||
test "displays usage", %{conn: conn, user: user} do
|
||||
site = insert(:site, members: [user])
|
||||
|
||||
populate_stats(site, [
|
||||
build(:pageview),
|
||||
build(:pageview)
|
||||
])
|
||||
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "You have used <b>2</b>\nbillable pageviews in the last 30 days"
|
||||
end
|
||||
|
||||
test "gets default selected interval from current subscription plan", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert class_of_element(doc, @yearly_interval_button) =~ @interval_button_active_class
|
||||
end
|
||||
|
||||
test "gets default pageview limit from current subscription plan", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "Monthly pageviews: <b>200k</b"
|
||||
end
|
||||
|
||||
test "pageview slider changes selected volume", %{conn: conn} do
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 1})
|
||||
assert doc =~ "Monthly pageviews: <b>100k</b"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 0})
|
||||
assert doc =~ "Monthly pageviews: <b>10k</b"
|
||||
end
|
||||
|
||||
test "makes it clear that the user is currently on a growth tier", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
|
||||
class = class_of_element(doc, @growth_plan_box)
|
||||
|
||||
assert class =~ "ring-2"
|
||||
assert class =~ "ring-indigo-600"
|
||||
assert text_of_element(doc, @growth_current_label) == "Current"
|
||||
end
|
||||
|
||||
test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Currently on this plan"
|
||||
assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"
|
||||
|
||||
doc = element(lv, @monthly_interval_button) |> render_click()
|
||||
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Change billing interval"
|
||||
assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 4})
|
||||
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Upgrade"
|
||||
assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 1})
|
||||
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Downgrade"
|
||||
assert text_of_element(doc, @business_checkout_button) == "Upgrade to Business"
|
||||
end
|
||||
|
||||
test "checkout buttons are dynamic links to /billing/change-plan/preview/<plan_id>", %{
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
growth_checkout_button = find(doc, @growth_checkout_button)
|
||||
|
||||
assert text_of_attr(growth_checkout_button, "href") =~
|
||||
"/billing/change-plan/preview/#{@v4_growth_200k_yearly_plan_id}"
|
||||
|
||||
element(lv, @slider_input) |> render_change(%{slider: 6})
|
||||
doc = element(lv, @monthly_interval_button) |> render_click()
|
||||
|
||||
business_checkout_button = find(doc, @business_checkout_button)
|
||||
|
||||
assert text_of_attr(business_checkout_button, "href") =~
|
||||
"/billing/change-plan/preview/#{@v4_business_5m_monthly_plan_id}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a user with a v4 business subscription plan" do
|
||||
setup [:create_user, :log_in, :subscribe_v4_business]
|
||||
|
||||
test "gets default pageview limit from current subscription plan", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "Monthly pageviews: <b>5M</b"
|
||||
end
|
||||
|
||||
test "makes it clear that the user is currently on a business tier", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
|
||||
class = class_of_element(doc, @business_plan_box)
|
||||
|
||||
assert class =~ "ring-2"
|
||||
assert class =~ "ring-indigo-600"
|
||||
assert text_of_element(doc, @business_current_label) == "Current"
|
||||
end
|
||||
|
||||
test "checkout button text and click-disabling CSS classes are dynamic", %{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
|
||||
assert text_of_element(doc, @business_checkout_button) == "Currently on this plan"
|
||||
assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"
|
||||
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
assert text_of_element(doc, @business_checkout_button) == "Change billing interval"
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 7})
|
||||
|
||||
assert text_of_element(doc, @business_checkout_button) == "Upgrade"
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 1})
|
||||
|
||||
assert text_of_element(doc, @business_checkout_button) == "Downgrade"
|
||||
assert text_of_element(doc, @growth_checkout_button) == "Downgrade to Growth"
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a user with a past_due subscription" do
|
||||
setup [:create_user, :log_in, :create_past_due_subscription]
|
||||
|
||||
test "renders failed payment notice and link to update billing details", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "There was a problem with your latest payment"
|
||||
assert doc =~ "https://update.billing.details"
|
||||
end
|
||||
|
||||
test "checkout buttons are disabled + notice about billing details (unless plan owned already)",
|
||||
%{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"
|
||||
refute element_exists?(doc, "#{@growth_checkout_button} + p")
|
||||
|
||||
assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
|
||||
assert text_of_element(doc, "#{@business_checkout_button} + p") =~
|
||||
"Please update your billing details first"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 4})
|
||||
|
||||
assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
|
||||
assert text_of_element(doc, "#{@growth_checkout_button} + p") =~
|
||||
"Please update your billing details first"
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a user with a paused subscription" do
|
||||
setup [:create_user, :log_in, :create_paused_subscription]
|
||||
|
||||
test "renders subscription paused notice and link to update billing details", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert doc =~ "Your subscription is paused due to failed payments"
|
||||
assert doc =~ "https://update.billing.details"
|
||||
end
|
||||
|
||||
test "checkout buttons are disabled + notice about billing details when plan not owned already",
|
||||
%{conn: conn} do
|
||||
{:ok, lv, doc} = get_liveview(conn)
|
||||
assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
assert text_of_element(doc, @growth_checkout_button) =~ "Currently on this plan"
|
||||
refute element_exists?(doc, "#{@growth_checkout_button} + p")
|
||||
|
||||
assert class_of_element(doc, @business_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
|
||||
assert text_of_element(doc, "#{@business_checkout_button} + p") =~
|
||||
"Please update your billing details first"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 4})
|
||||
|
||||
assert class_of_element(doc, @growth_checkout_button) =~ "pointer-events-none bg-gray-400"
|
||||
|
||||
assert text_of_element(doc, "#{@growth_checkout_button} + p") =~
|
||||
"Please update your billing details first"
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a user with a cancelled subscription" do
|
||||
setup [:create_user, :log_in, :create_cancelled_subscription]
|
||||
|
||||
test "checkout buttons are paddle buttons", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~ "Paddle.Checkout.open"
|
||||
|
||||
assert text_of_attr(find(doc, @business_checkout_button), "onclick") =~
|
||||
"Paddle.Checkout.open"
|
||||
end
|
||||
|
||||
test "currently owned tier is highlighted if stats are still unlocked", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
assert text_of_element(doc, @growth_current_label) == "Current"
|
||||
end
|
||||
|
||||
test "currently owned tier is not highlighted if stats are locked", %{conn: conn, user: user} do
|
||||
user.subscription
|
||||
|> Subscription.changeset(%{next_bill_date: Timex.shift(Timex.now(), months: -2)})
|
||||
|> Repo.update()
|
||||
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
refute element_exists?(doc, @growth_current_label)
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a grandfathered user" do
|
||||
setup [:create_user, :log_in]
|
||||
|
||||
test "on a v1 plan, Growth tiers are available at 20M, 50M, 50M+, but Business tiers are not",
|
||||
%{conn: conn, user: user} do
|
||||
create_subscription_for(user, paddle_plan_id: @v1_10k_yearly_plan_id)
|
||||
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 8})
|
||||
assert doc =~ "Monthly pageviews: <b>20M</b"
|
||||
assert text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€900"
|
||||
assert text_of_element(doc, @growth_price_tag_interval) == "/year"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 9})
|
||||
assert doc =~ "Monthly pageviews: <b>50M</b"
|
||||
assert text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
assert text_of_element(doc, @growth_price_tag_amount) == "€1K"
|
||||
assert text_of_element(doc, @growth_price_tag_interval) == "/year"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 10})
|
||||
assert doc =~ "Monthly pageviews: <b>50M+</b"
|
||||
assert text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
assert text_of_element(doc, @growth_plan_box) =~ "Contact us"
|
||||
|
||||
doc = lv |> element(@slider_input) |> render_change(%{slider: 7})
|
||||
assert doc =~ "Monthly pageviews: <b>10M</b"
|
||||
refute text_of_element(doc, @business_plan_box) =~ "Contact us"
|
||||
refute text_of_element(doc, @growth_plan_box) =~ "Contact us"
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a free_10k subscription" do
|
||||
setup [:create_user, :log_in, :subscribe_free_10k]
|
||||
|
||||
test "does not highlight any tier", %{conn: conn} do
|
||||
{:ok, _lv, doc} = get_liveview(conn)
|
||||
refute element_exists?(doc, @growth_current_label)
|
||||
refute element_exists?(doc, @business_current_label)
|
||||
end
|
||||
|
||||
test "renders Paddle upgrade buttons", %{conn: conn, user: user} do
|
||||
{:ok, lv, _doc} = get_liveview(conn)
|
||||
|
||||
element(lv, @slider_input) |> render_change(%{slider: 2})
|
||||
doc = element(lv, @yearly_interval_button) |> render_click()
|
||||
|
||||
assert %{
|
||||
"disableLogout" => true,
|
||||
"email" => user.email,
|
||||
"passthrough" => user.id,
|
||||
"product" => @v4_growth_200k_yearly_plan_id,
|
||||
"success" => Routes.billing_path(PlausibleWeb.Endpoint, :upgrade_success),
|
||||
"theme" => "none"
|
||||
} == get_paddle_checkout_params(find(doc, @growth_checkout_button))
|
||||
end
|
||||
end
|
||||
|
||||
defp subscribe_v4_growth(%{user: user}) do
|
||||
create_subscription_for(user, paddle_plan_id: @v4_growth_200k_yearly_plan_id)
|
||||
end
|
||||
|
||||
defp subscribe_v4_business(%{user: user}) do
|
||||
create_subscription_for(user, paddle_plan_id: @v4_business_5m_monthly_plan_id)
|
||||
end
|
||||
|
||||
defp create_past_due_subscription(%{user: user}) do
|
||||
create_subscription_for(user,
|
||||
paddle_plan_id: @v4_growth_200k_yearly_plan_id,
|
||||
status: "past_due",
|
||||
update_url: "https://update.billing.details"
|
||||
)
|
||||
end
|
||||
|
||||
defp create_paused_subscription(%{user: user}) do
|
||||
create_subscription_for(user,
|
||||
paddle_plan_id: @v4_growth_200k_yearly_plan_id,
|
||||
status: "paused",
|
||||
update_url: "https://update.billing.details"
|
||||
)
|
||||
end
|
||||
|
||||
defp create_cancelled_subscription(%{user: user}) do
|
||||
create_subscription_for(user,
|
||||
paddle_plan_id: @v4_growth_200k_yearly_plan_id,
|
||||
status: "deleted"
|
||||
)
|
||||
end
|
||||
|
||||
defp create_subscription_for(user, subscription_options) do
|
||||
insert(:subscription, Keyword.put(subscription_options, :user, user))
|
||||
{:ok, user: Plausible.Users.with_subscription(user)}
|
||||
end
|
||||
|
||||
defp subscribe_free_10k(%{user: user}) do
|
||||
Plausible.Billing.Subscription.free(%{user_id: user.id})
|
||||
|> Repo.insert!()
|
||||
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
defp get_liveview(conn) do
|
||||
conn = assign(conn, :live_module, PlausibleWeb.Live.ChoosePlan)
|
||||
{:ok, _lv, _doc} = live(conn, "/billing/choose-plan")
|
||||
end
|
||||
|
||||
defp get_paddle_checkout_params(element) do
|
||||
with onclick <- text_of_attr(element, "onclick"),
|
||||
[[_, checkout_params_str]] <- Regex.scan(~r/Paddle\.Checkout\.open\((.*?)\)/, onclick),
|
||||
{:ok, checkout_params} <- Jason.decode(checkout_params_str) do
|
||||
checkout_params
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,5 +1,6 @@
|
||||
{:ok, _} = Application.ensure_all_started(:ex_machina)
|
||||
Mox.defmock(Plausible.HTTPClient.Mock, for: Plausible.HTTPClient.Interface)
|
||||
Application.ensure_all_started(:double)
|
||||
FunWithFlags.enable(:business_tier)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, :manual)
|
||||
ExUnit.configure(exclude: [:slow])
|
||||
|
||||
Loading…
Reference in New Issue