2018-09-25 12:24:11 +02:00
|
|
|
import logging
|
2024-09-24 23:27:28 +02:00
|
|
|
from typing import TYPE_CHECKING, Annotated, Any, Literal
|
2018-09-25 12:24:11 +02:00
|
|
|
|
2023-12-12 19:35:16 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed, HttpResponseRedirect
|
2019-02-02 23:53:22 +01:00
|
|
|
from django.shortcuts import render
|
2018-09-25 12:24:11 +02:00
|
|
|
from django.urls import reverse
|
2023-12-12 19:35:16 +01:00
|
|
|
from django.utils.translation import gettext as _
|
2024-07-05 18:00:27 +02:00
|
|
|
from pydantic import AfterValidator, Json
|
2023-11-22 12:44:02 +01:00
|
|
|
|
2023-12-01 10:43:04 +01:00
|
|
|
from corporate.lib.decorator import (
|
|
|
|
authenticated_remote_realm_management_endpoint,
|
|
|
|
authenticated_remote_server_management_endpoint,
|
|
|
|
)
|
2023-12-06 05:56:20 +01:00
|
|
|
from corporate.models import CustomerPlan, get_current_plan_by_customer, get_customer_by_realm
|
2023-12-06 12:33:33 +01:00
|
|
|
from zerver.decorator import process_as_post, require_billing_access, zulip_login_required
|
2023-12-12 19:35:16 +01:00
|
|
|
from zerver.lib.exceptions import JsonableError
|
2021-07-04 08:19:18 +02:00
|
|
|
from zerver.lib.response import json_success
|
2023-12-01 10:43:04 +01:00
|
|
|
from zerver.lib.typed_endpoint import typed_endpoint
|
2024-07-05 18:00:27 +02:00
|
|
|
from zerver.lib.typed_endpoint_validators import check_int_in
|
2023-11-27 13:08:43 +01:00
|
|
|
from zerver.models import UserProfile
|
2023-12-07 15:27:39 +01:00
|
|
|
from zilencer.lib.remote_counts import MissingDataError
|
2023-12-01 10:43:04 +01:00
|
|
|
from zilencer.models import RemoteRealm, RemoteZulipServer
|
2018-09-25 12:24:11 +02:00
|
|
|
|
2024-09-24 23:27:28 +02:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from corporate.lib.stripe import RemoteRealmBillingSession, RemoteServerBillingSession
|
|
|
|
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
billing_logger = logging.getLogger("corporate.stripe")
|
2018-09-25 12:24:11 +02:00
|
|
|
|
2023-12-02 09:09:43 +01:00
|
|
|
ALLOWED_PLANS_API_STATUS_VALUES = [
|
|
|
|
CustomerPlan.ACTIVE,
|
|
|
|
CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE,
|
|
|
|
CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE,
|
|
|
|
CustomerPlan.SWITCH_TO_MONTHLY_AT_END_OF_CYCLE,
|
|
|
|
CustomerPlan.FREE_TRIAL,
|
|
|
|
CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL,
|
|
|
|
CustomerPlan.ENDED,
|
|
|
|
]
|
|
|
|
|
2023-02-13 20:40:51 +01:00
|
|
|
|
2018-09-25 12:24:11 +02:00
|
|
|
@zulip_login_required
|
2023-12-01 10:43:04 +01:00
|
|
|
@typed_endpoint
|
2023-12-01 07:39:05 +01:00
|
|
|
def billing_page(
|
2023-11-13 15:56:10 +01:00
|
|
|
request: HttpRequest,
|
2023-12-01 10:43:04 +01:00
|
|
|
*,
|
|
|
|
success_message: str = "",
|
2021-07-29 19:01:39 +02:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import RealmBillingSession
|
|
|
|
|
2018-09-25 12:24:11 +02:00
|
|
|
user = request.user
|
2021-07-24 20:37:35 +02:00
|
|
|
assert user.is_authenticated
|
|
|
|
|
2023-12-24 15:56:33 +01:00
|
|
|
billing_session = RealmBillingSession(user=user, realm=user.realm)
|
2023-11-27 17:31:39 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {
|
2020-08-21 14:45:43 +02:00
|
|
|
"admin_access": user.has_billing_access,
|
2021-02-12 08:20:45 +01:00
|
|
|
"has_active_plan": False,
|
2024-02-01 05:07:01 +01:00
|
|
|
"org_name": billing_session.org_name(),
|
2023-12-02 09:09:43 +01:00
|
|
|
"billing_base_url": "",
|
2020-08-21 14:45:43 +02:00
|
|
|
}
|
|
|
|
|
2023-11-02 16:34:37 +01:00
|
|
|
if not user.has_billing_access:
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/billing.html", context=context)
|
2023-11-02 16:34:37 +01:00
|
|
|
|
2021-10-18 23:28:17 +02:00
|
|
|
if user.realm.plan_type == user.realm.PLAN_TYPE_STANDARD_FREE:
|
2023-11-02 16:34:37 +01:00
|
|
|
return HttpResponseRedirect(reverse("sponsorship_request"))
|
|
|
|
|
|
|
|
customer = get_customer_by_realm(user.realm)
|
2023-11-04 07:23:15 +01:00
|
|
|
if customer is not None and customer.sponsorship_pending:
|
|
|
|
# Don't redirect to sponsorship page if the realm is on a paid plan
|
2023-11-27 17:31:39 +01:00
|
|
|
if not billing_session.on_paid_plan():
|
2023-11-04 07:23:15 +01:00
|
|
|
return HttpResponseRedirect(reverse("sponsorship_request"))
|
|
|
|
# If the realm is on a paid plan, show the sponsorship pending message
|
|
|
|
context["sponsorship_pending"] = True
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2023-11-08 17:38:47 +01:00
|
|
|
if user.realm.plan_type == user.realm.PLAN_TYPE_LIMITED:
|
|
|
|
return HttpResponseRedirect(reverse("plans"))
|
|
|
|
|
2023-12-06 05:56:20 +01:00
|
|
|
if customer is None or get_current_plan_by_customer(customer) is None:
|
2023-12-01 08:07:26 +01:00
|
|
|
return HttpResponseRedirect(reverse("upgrade_page"))
|
2018-09-25 12:24:11 +02:00
|
|
|
|
2023-11-16 16:14:43 +01:00
|
|
|
main_context = billing_session.get_billing_page_context()
|
|
|
|
if main_context:
|
2024-03-19 13:33:13 +01:00
|
|
|
if main_context.get("current_plan_downgraded") is True:
|
|
|
|
return HttpResponseRedirect(reverse("plans"))
|
2023-11-16 16:14:43 +01:00
|
|
|
context.update(main_context)
|
2023-11-22 12:02:09 +01:00
|
|
|
context["success_message"] = success_message
|
2020-04-03 16:17:34 +02:00
|
|
|
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/billing.html", context=context)
|
2018-09-25 12:24:11 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-12-01 10:43:04 +01:00
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_realm_management_endpoint
|
2023-12-01 10:43:04 +01:00
|
|
|
def remote_realm_billing_page(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteRealmBillingSession",
|
2023-12-01 10:43:04 +01:00
|
|
|
*,
|
|
|
|
success_message: str = "",
|
2023-12-13 12:25:23 +01:00
|
|
|
) -> HttpResponse:
|
2023-12-05 12:35:21 +01:00
|
|
|
realm_uuid = billing_session.remote_realm.uuid
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {
|
2023-12-01 10:43:04 +01:00
|
|
|
# We wouldn't be here if user didn't have access.
|
|
|
|
"admin_access": billing_session.has_billing_access(),
|
|
|
|
"has_active_plan": False,
|
2024-02-01 05:07:01 +01:00
|
|
|
"org_name": billing_session.org_name(),
|
2023-12-06 05:44:12 +01:00
|
|
|
"billing_base_url": billing_session.billing_base_url,
|
2023-12-01 10:43:04 +01:00
|
|
|
}
|
|
|
|
|
2023-12-13 12:25:23 +01:00
|
|
|
if billing_session.remote_realm.plan_type == RemoteRealm.PLAN_TYPE_COMMUNITY: # nocoverage
|
2023-12-05 12:35:21 +01:00
|
|
|
return HttpResponseRedirect(reverse("remote_realm_sponsorship_page", args=(realm_uuid,)))
|
2023-12-01 10:43:04 +01:00
|
|
|
|
|
|
|
customer = billing_session.get_customer()
|
2023-12-13 12:25:23 +01:00
|
|
|
if customer is not None and customer.sponsorship_pending: # nocoverage
|
2023-12-14 09:46:06 +01:00
|
|
|
# Don't redirect to sponsorship page if the remote realm is on a paid plan or scheduled for an upgrade.
|
|
|
|
if (
|
|
|
|
not billing_session.on_paid_plan()
|
|
|
|
and billing_session.get_legacy_remote_server_next_plan_name(customer) is None
|
|
|
|
):
|
2023-12-05 12:35:21 +01:00
|
|
|
return HttpResponseRedirect(
|
|
|
|
reverse("remote_realm_sponsorship_page", args=(realm_uuid,))
|
|
|
|
)
|
2023-12-01 10:43:04 +01:00
|
|
|
# If the realm is on a paid plan, show the sponsorship pending message
|
|
|
|
context["sponsorship_pending"] = True
|
|
|
|
|
2023-12-11 18:00:42 +01:00
|
|
|
if (
|
|
|
|
customer is None
|
|
|
|
or get_current_plan_by_customer(customer) is None
|
|
|
|
or (
|
|
|
|
billing_session.get_legacy_remote_server_next_plan_name(customer) is None
|
2023-12-14 00:17:55 +01:00
|
|
|
and billing_session.remote_realm.plan_type
|
|
|
|
in [
|
|
|
|
RemoteRealm.PLAN_TYPE_SELF_MANAGED,
|
|
|
|
RemoteRealm.PLAN_TYPE_SELF_MANAGED_LEGACY,
|
|
|
|
]
|
2023-12-11 18:00:42 +01:00
|
|
|
)
|
2023-12-13 12:25:23 +01:00
|
|
|
): # nocoverage
|
2023-12-05 12:35:21 +01:00
|
|
|
return HttpResponseRedirect(reverse("remote_realm_plans_page", args=(realm_uuid,)))
|
2023-12-01 10:43:04 +01:00
|
|
|
|
2023-12-07 15:27:39 +01:00
|
|
|
try:
|
|
|
|
main_context = billing_session.get_billing_page_context()
|
2023-12-13 12:25:23 +01:00
|
|
|
except MissingDataError: # nocoverage
|
2023-12-07 15:27:39 +01:00
|
|
|
return billing_session.missing_data_error_page(request)
|
|
|
|
|
2023-12-01 10:43:04 +01:00
|
|
|
if main_context:
|
2024-03-19 13:33:13 +01:00
|
|
|
if main_context.get("current_plan_downgraded") is True:
|
|
|
|
return HttpResponseRedirect(reverse("remote_realm_plans_page", args=(realm_uuid,)))
|
2023-12-01 10:43:04 +01:00
|
|
|
context.update(main_context)
|
|
|
|
context["success_message"] = success_message
|
|
|
|
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/billing.html", context=context)
|
2023-12-01 10:43:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_server_management_endpoint
|
2023-12-01 10:43:04 +01:00
|
|
|
def remote_server_billing_page(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteServerBillingSession",
|
2023-12-01 10:43:04 +01:00
|
|
|
*,
|
|
|
|
success_message: str = "",
|
2023-12-19 12:24:15 +01:00
|
|
|
) -> HttpResponse:
|
2024-07-12 02:30:17 +02:00
|
|
|
context: dict[str, Any] = {
|
2023-12-01 10:43:04 +01:00
|
|
|
# We wouldn't be here if user didn't have access.
|
|
|
|
"admin_access": billing_session.has_billing_access(),
|
|
|
|
"has_active_plan": False,
|
2024-02-01 05:07:01 +01:00
|
|
|
"org_name": billing_session.org_name(),
|
2023-12-06 05:44:12 +01:00
|
|
|
"billing_base_url": billing_session.billing_base_url,
|
2023-12-01 10:43:04 +01:00
|
|
|
}
|
|
|
|
|
2023-12-19 12:24:15 +01:00
|
|
|
if (
|
|
|
|
billing_session.remote_server.plan_type == RemoteZulipServer.PLAN_TYPE_COMMUNITY
|
|
|
|
): # nocoverage
|
2023-12-01 10:43:04 +01:00
|
|
|
return HttpResponseRedirect(
|
|
|
|
reverse(
|
|
|
|
"remote_server_sponsorship_page",
|
|
|
|
kwargs={"server_uuid": billing_session.remote_server.uuid},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
customer = billing_session.get_customer()
|
|
|
|
if customer is not None and customer.sponsorship_pending:
|
2023-12-14 09:46:06 +01:00
|
|
|
# Don't redirect to sponsorship page if the remote realm is on a paid plan or scheduled for an upgrade.
|
|
|
|
if (
|
|
|
|
not billing_session.on_paid_plan()
|
|
|
|
and billing_session.get_legacy_remote_server_next_plan_name(customer) is None
|
|
|
|
):
|
2023-12-01 10:43:04 +01:00
|
|
|
return HttpResponseRedirect(
|
|
|
|
reverse(
|
|
|
|
"remote_server_sponsorship_page",
|
|
|
|
kwargs={"server_uuid": billing_session.remote_server.uuid},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# If the realm is on a paid plan, show the sponsorship pending message
|
2023-12-19 12:24:15 +01:00
|
|
|
context["sponsorship_pending"] = True # nocoverage
|
2023-12-01 10:43:04 +01:00
|
|
|
|
|
|
|
if (
|
2023-12-06 13:37:19 +01:00
|
|
|
customer is None
|
2023-12-06 05:56:20 +01:00
|
|
|
or get_current_plan_by_customer(customer) is None
|
2023-12-06 13:37:19 +01:00
|
|
|
or (
|
2023-12-09 09:00:34 +01:00
|
|
|
billing_session.get_legacy_remote_server_next_plan_name(customer) is None
|
2023-12-14 00:17:55 +01:00
|
|
|
and billing_session.remote_server.plan_type
|
|
|
|
in [
|
|
|
|
RemoteZulipServer.PLAN_TYPE_SELF_MANAGED,
|
|
|
|
RemoteZulipServer.PLAN_TYPE_SELF_MANAGED_LEGACY,
|
|
|
|
]
|
2023-12-06 13:37:19 +01:00
|
|
|
)
|
2023-12-01 10:43:04 +01:00
|
|
|
):
|
|
|
|
return HttpResponseRedirect(
|
|
|
|
reverse(
|
|
|
|
"remote_server_upgrade_page",
|
|
|
|
kwargs={"server_uuid": billing_session.remote_server.uuid},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-12-07 15:27:39 +01:00
|
|
|
try:
|
|
|
|
main_context = billing_session.get_billing_page_context()
|
2023-12-19 12:24:15 +01:00
|
|
|
except MissingDataError: # nocoverage
|
2023-12-07 15:27:39 +01:00
|
|
|
return billing_session.missing_data_error_page(request)
|
|
|
|
|
2023-12-01 10:43:04 +01:00
|
|
|
if main_context:
|
2024-03-19 13:33:13 +01:00
|
|
|
if main_context.get("current_plan_downgraded") is True:
|
|
|
|
return HttpResponseRedirect(
|
|
|
|
reverse(
|
|
|
|
"remote_server_plans_page",
|
|
|
|
kwargs={"server_uuid": billing_session.remote_server.uuid},
|
|
|
|
)
|
|
|
|
)
|
2023-12-01 10:43:04 +01:00
|
|
|
context.update(main_context)
|
|
|
|
context["success_message"] = success_message
|
|
|
|
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/billing.html", context=context)
|
2023-12-01 10:43:04 +01:00
|
|
|
|
|
|
|
|
2018-11-01 11:26:29 +01:00
|
|
|
@require_billing_access
|
2024-07-05 18:00:27 +02:00
|
|
|
@typed_endpoint
|
2020-12-10 18:15:09 +01:00
|
|
|
def update_plan(
|
2021-04-14 15:50:40 +02:00
|
|
|
request: HttpRequest,
|
|
|
|
user: UserProfile,
|
2024-07-05 18:00:27 +02:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
status: Annotated[
|
|
|
|
Json[int], AfterValidator(lambda x: check_int_in(x, ALLOWED_PLANS_API_STATUS_VALUES))
|
|
|
|
]
|
|
|
|
| None = None,
|
|
|
|
licenses: Json[int] | None = None,
|
|
|
|
licenses_at_next_renewal: Json[int] | None = None,
|
|
|
|
schedule: Json[int] | None = None,
|
2021-02-12 08:19:30 +01:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import RealmBillingSession, UpdatePlanRequest
|
|
|
|
|
2023-11-22 12:44:02 +01:00
|
|
|
update_plan_request = UpdatePlanRequest(
|
|
|
|
status=status,
|
|
|
|
licenses=licenses,
|
|
|
|
licenses_at_next_renewal=licenses_at_next_renewal,
|
2023-11-26 15:41:28 +01:00
|
|
|
schedule=schedule,
|
2023-11-13 15:05:56 +01:00
|
|
|
)
|
2023-11-22 12:44:02 +01:00
|
|
|
billing_session = RealmBillingSession(user=user)
|
|
|
|
billing_session.do_update_plan(update_plan_request)
|
|
|
|
return json_success(request)
|
2023-12-02 09:09:43 +01:00
|
|
|
|
|
|
|
|
2023-12-06 12:33:33 +01:00
|
|
|
@process_as_post
|
2024-07-05 18:00:27 +02:00
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_realm_management_endpoint
|
2023-12-02 09:09:43 +01:00
|
|
|
def update_plan_for_remote_realm(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteRealmBillingSession",
|
2024-07-05 18:00:27 +02:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
status: Annotated[
|
|
|
|
Json[int], AfterValidator(lambda x: check_int_in(x, ALLOWED_PLANS_API_STATUS_VALUES))
|
|
|
|
]
|
|
|
|
| None = None,
|
|
|
|
licenses: Json[int] | None = None,
|
|
|
|
licenses_at_next_renewal: Json[int] | None = None,
|
|
|
|
schedule: Json[int] | None = None,
|
2023-12-20 12:22:00 +01:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import UpdatePlanRequest
|
|
|
|
|
2023-12-02 09:09:43 +01:00
|
|
|
update_plan_request = UpdatePlanRequest(
|
|
|
|
status=status,
|
|
|
|
licenses=licenses,
|
|
|
|
licenses_at_next_renewal=licenses_at_next_renewal,
|
|
|
|
schedule=schedule,
|
|
|
|
)
|
|
|
|
billing_session.do_update_plan(update_plan_request)
|
|
|
|
return json_success(request)
|
|
|
|
|
|
|
|
|
2023-12-06 12:33:33 +01:00
|
|
|
@process_as_post
|
2024-07-05 18:00:27 +02:00
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_server_management_endpoint
|
2023-12-02 09:09:43 +01:00
|
|
|
def update_plan_for_remote_server(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteServerBillingSession",
|
2024-07-05 18:00:27 +02:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
status: Annotated[
|
|
|
|
Json[int], AfterValidator(lambda x: check_int_in(x, ALLOWED_PLANS_API_STATUS_VALUES))
|
|
|
|
]
|
|
|
|
| None = None,
|
|
|
|
licenses: Json[int] | None = None,
|
|
|
|
licenses_at_next_renewal: Json[int] | None = None,
|
|
|
|
schedule: Json[int] | None = None,
|
2023-12-19 12:24:15 +01:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import UpdatePlanRequest
|
|
|
|
|
2023-12-02 09:09:43 +01:00
|
|
|
update_plan_request = UpdatePlanRequest(
|
|
|
|
status=status,
|
|
|
|
licenses=licenses,
|
|
|
|
licenses_at_next_renewal=licenses_at_next_renewal,
|
|
|
|
schedule=schedule,
|
|
|
|
)
|
|
|
|
billing_session.do_update_plan(update_plan_request)
|
|
|
|
return json_success(request)
|
2023-12-12 19:35:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_server_management_endpoint
|
2023-12-12 19:35:16 +01:00
|
|
|
def remote_server_deactivate_page(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteServerBillingSession",
|
2023-12-12 19:35:16 +01:00
|
|
|
*,
|
|
|
|
confirmed: Literal[None, "true"] = None,
|
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import (
|
|
|
|
ServerDeactivateWithExistingPlanError,
|
|
|
|
do_deactivate_remote_server,
|
|
|
|
)
|
|
|
|
|
2023-12-12 19:35:16 +01:00
|
|
|
if request.method not in ["GET", "POST"]: # nocoverage
|
|
|
|
return HttpResponseNotAllowed(["GET", "POST"])
|
|
|
|
|
|
|
|
remote_server = billing_session.remote_server
|
2023-12-13 02:44:55 +01:00
|
|
|
context = {
|
|
|
|
"server_hostname": remote_server.hostname,
|
|
|
|
"action_url": reverse(remote_server_deactivate_page, args=[str(remote_server.uuid)]),
|
|
|
|
}
|
2023-12-12 19:35:16 +01:00
|
|
|
if request.method == "GET":
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(
|
|
|
|
request, "corporate/billing/remote_billing_server_deactivate.html", context=context
|
|
|
|
)
|
2023-12-12 19:35:16 +01:00
|
|
|
|
|
|
|
assert request.method == "POST"
|
|
|
|
if confirmed is None: # nocoverage
|
|
|
|
# Should be impossible if the user is using the UI.
|
|
|
|
raise JsonableError(_("Parameter 'confirmed' is required"))
|
|
|
|
|
2023-12-13 02:44:55 +01:00
|
|
|
try:
|
|
|
|
do_deactivate_remote_server(remote_server, billing_session)
|
|
|
|
except ServerDeactivateWithExistingPlanError: # nocoverage
|
|
|
|
context["show_existing_plan_error"] = "true"
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(
|
|
|
|
request, "corporate/billing/remote_billing_server_deactivate.html", context=context
|
|
|
|
)
|
2023-12-13 02:44:55 +01:00
|
|
|
|
2023-12-12 19:35:16 +01:00
|
|
|
return render(
|
|
|
|
request,
|
2024-01-29 15:46:18 +01:00
|
|
|
"corporate/billing/remote_billing_server_deactivated_success.html",
|
2023-12-12 19:35:16 +01:00
|
|
|
context={"server_hostname": remote_server.hostname},
|
|
|
|
)
|