Skip to content
Snippets Groups Projects
Commit 8719865a authored by Uku Taht's avatar Uku Taht
Browse files

Redirect user when they've already upgraded

parent ed9e1d9d
No related branches found
No related tags found
No related merge requests found
......@@ -31,19 +31,22 @@ defmodule PlausibleWeb.BillingController do
def upgrade_enterprise_plan(conn, %{"plan_id" => plan_id}) do
user = conn.assigns[:current_user]
subscription = user.subscription
plan = Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: user.id, id: plan_id)
if plan do
usage = Plausible.Billing.usage(conn.assigns[:current_user])
cond do
plan && subscription && plan.paddle_plan_id == subscription.paddle_plan_id ->
redirect(conn, to: Routes.billing_path(conn, :change_plan_form))
render(conn, "upgrade_to_plan.html",
usage: usage,
user: user,
plan: plan,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
else
render_error(conn, 404)
plan ->
render(conn, "upgrade_to_plan.html",
user: user,
plan: plan,
layout: {PlausibleWeb.LayoutView, "focus.html"}
)
true ->
render_error(conn, 404)
end
end
......
......@@ -40,6 +40,16 @@ defmodule PlausibleWeb.BillingControllerTest do
assert html_response(conn, 200) =~ "Upgrade your free trial"
assert html_response(conn, 200) =~ "enterprise plan"
end
test "redirects to change-plan page if user is already subscribed to the given enterprise plan",
%{conn: conn, user: user} do
plan = insert(:enterprise_plan, user: user)
insert(:subscription, paddle_plan_id: plan.paddle_plan_id, user: user)
conn = get(conn, "/billing/upgrade/enterprise/#{plan.id}")
assert redirected_to(conn) == "/billing/change-plan"
end
end
describe "GET /change-plan" do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment