mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
Fix display
This commit is contained in:
parent
ebdd856df7
commit
ce649966ed
@ -74,8 +74,7 @@ defmodule Plausible.Billing.Plans do
|
|||||||
def subscription_interval(subscription) do
|
def subscription_interval(subscription) do
|
||||||
case for_product_id(subscription.paddle_plan_id) do
|
case for_product_id(subscription.paddle_plan_id) do
|
||||||
nil ->
|
nil ->
|
||||||
enterprise_plan =
|
enterprise_plan = get_enterprise_plan(subscription)
|
||||||
Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: subscription.user_id)
|
|
||||||
|
|
||||||
enterprise_plan && enterprise_plan.billing_interval
|
enterprise_plan && enterprise_plan.billing_interval
|
||||||
|
|
||||||
@ -96,11 +95,7 @@ defmodule Plausible.Billing.Plans do
|
|||||||
if found do
|
if found do
|
||||||
Map.fetch!(found, :limit)
|
Map.fetch!(found, :limit)
|
||||||
else
|
else
|
||||||
enterprise_plan =
|
enterprise_plan = get_enterprise_plan(subscription)
|
||||||
Repo.get_by(Plausible.Billing.EnterprisePlan,
|
|
||||||
user_id: subscription.user_id,
|
|
||||||
paddle_plan_id: subscription.paddle_plan_id
|
|
||||||
)
|
|
||||||
|
|
||||||
if enterprise_plan do
|
if enterprise_plan do
|
||||||
enterprise_plan.monthly_pageview_limit
|
enterprise_plan.monthly_pageview_limit
|
||||||
@ -114,15 +109,11 @@ defmodule Plausible.Billing.Plans do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_enterprise_plan(user) do
|
def get_enterprise_plan(subscription) do
|
||||||
if user.subscription do
|
|
||||||
Repo.get_by(Plausible.Billing.EnterprisePlan,
|
Repo.get_by(Plausible.Billing.EnterprisePlan,
|
||||||
user_id: user.id,
|
user_id: subscription.user_id,
|
||||||
paddle_plan_id: user.subscription.paddle_plan_id
|
paddle_plan_id: subscription.paddle_plan_id
|
||||||
)
|
)
|
||||||
else
|
|
||||||
Repo.get_by(Plausible.Billing.EnterprisePlan, user_id: user.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def suggested_plan(user, usage) do
|
def suggested_plan(user, usage) do
|
||||||
|
@ -489,6 +489,46 @@ defmodule PlausibleWeb.AuthControllerTest do
|
|||||||
assert html_response(conn, 200) =~ "N/A billing"
|
assert html_response(conn, 200) =~ "N/A billing"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "shows enterprise plan subscription", %{conn: conn, user: user} do
|
||||||
|
insert(:subscription, paddle_plan_id: "123", user: user)
|
||||||
|
|
||||||
|
insert(:enterprise_plan,
|
||||||
|
paddle_plan_id: "123",
|
||||||
|
user: user,
|
||||||
|
monthly_pageview_limit: 10_000_000,
|
||||||
|
billing_interval: :yearly
|
||||||
|
)
|
||||||
|
|
||||||
|
conn = get(conn, "/settings")
|
||||||
|
assert html_response(conn, 200) =~ "10M pageviews"
|
||||||
|
assert html_response(conn, 200) =~ "yearly billing"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows current enterprise plan subscription when user has a new one to upgrade to", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user
|
||||||
|
} do
|
||||||
|
insert(:subscription, paddle_plan_id: "123", user: user)
|
||||||
|
|
||||||
|
insert(:enterprise_plan,
|
||||||
|
paddle_plan_id: "123",
|
||||||
|
user: user,
|
||||||
|
monthly_pageview_limit: 10_000_000,
|
||||||
|
billing_interval: :yearly
|
||||||
|
)
|
||||||
|
|
||||||
|
insert(:enterprise_plan,
|
||||||
|
paddle_plan_id: "1234",
|
||||||
|
user: user,
|
||||||
|
monthly_pageview_limit: 20_000_000,
|
||||||
|
billing_interval: :yearly
|
||||||
|
)
|
||||||
|
|
||||||
|
conn = get(conn, "/settings")
|
||||||
|
assert html_response(conn, 200) =~ "10M pageviews"
|
||||||
|
assert html_response(conn, 200) =~ "yearly billing"
|
||||||
|
end
|
||||||
|
|
||||||
test "shows invoices for subscribed user", %{conn: conn, user: user} do
|
test "shows invoices for subscribed user", %{conn: conn, user: user} do
|
||||||
insert(:subscription,
|
insert(:subscription,
|
||||||
paddle_plan_id: "558018",
|
paddle_plan_id: "558018",
|
||||||
|
Loading…
Reference in New Issue
Block a user