Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
event_status: Pass billing_base_url to calculate realm specific URLs.
Aman Agrawal9889dc38fe81
diff --git a/corporate/urls.py b/corporate/urls.pyindex f23ade248d1..8f682826fff 100644--- a/corporate/urls.py+++ b/corporate/urls.py@@ -10,6 +10,7 @@ from corporate.views.event_status import (event_status_page,remote_realm_event_status,remote_realm_event_status_page,+ remote_server_event_status_page,)from corporate.views.portico import (app_download_link_redirect,@@ -199,6 +200,11 @@ urlpatterns += [remote_realm_event_status_page,name="remote_realm_event_status_page",),+ path(+ "server/<server_uuid>/billing/event_status",+ remote_server_event_status_page,+ name="remote_server_event_status_page",+ ),# Remote variants of above API endpoints.path("json/realm/<realm_uuid>/sponsorship", remote_realm_sponsorship),path("json/server/<server_uuid>/sponsorship", remote_server_sponsorship),diff --git a/corporate/views/event_status.py b/corporate/views/event_status.pyindex 79486378c64..f0864dc382b 100644--- a/corporate/views/event_status.py+++ b/corporate/views/event_status.py@@ -61,6 +61,7 @@ def event_status_page(context = {"stripe_session_id": stripe_session_id,"stripe_payment_intent_id": stripe_payment_intent_id,+ "billing_base_url": "",}return render(request, "corporate/event_status.html", context=context)@@ -78,5 +79,24 @@ def remote_realm_event_status_page(context = {"stripe_session_id": stripe_session_id,"stripe_payment_intent_id": stripe_payment_intent_id,+ "billing_base_url": f"/realm/{realm_uuid}",+ }+ return render(request, "corporate/event_status.html", context=context)+++@self_hosting_management_endpoint+@typed_endpoint+def remote_server_event_status_page(+ request: HttpRequest,+ *,+ realm_uuid: str = "",+ server_uuid: str = "",+ stripe_session_id: str = "",+ stripe_payment_intent_id: str = "",+) -> HttpResponse: # nocoverage+ context = {+ "stripe_session_id": stripe_session_id,+ "stripe_payment_intent_id": stripe_payment_intent_id,+ "billing_base_url": f"/server/{server_uuid}",}return render(request, "corporate/event_status.html", context=context)diff --git a/templates/corporate/event_status.html b/templates/corporate/event_status.htmlindex d5e1279bb99..28ade3a096c 100644--- a/templates/corporate/event_status.html+++ b/templates/corporate/event_status.html@@ -18,7 +18,7 @@<div class="page-content"><div class="main"><br />- <div id="data" data-stripe-session-id="{{ stripe_session_id}}" data-stripe-payment-intent-id="{{ stripe_payment_intent_id }}"></div>+ <div id="data" data-stripe-session-id="{{ stripe_session_id}}" data-stripe-payment-intent-id="{{ stripe_payment_intent_id }}" data-billing-base-url="{{ billing_base_url }}"></div><div class="alert alert-success" id="webhook-success"></div><div class="alert alert-danger" id="webhook-error"></div><div id="webhook-loading">diff --git a/web/src/billing/event_status.ts b/web/src/billing/event_status.tsindex 5a38f184d3a..e4519c599d0 100644--- a/web/src/billing/event_status.ts+++ b/web/src/billing/event_status.ts@@ -5,6 +5,8 @@ import * as loading from "../loading";import * as helpers from "./helpers";+const billing_base_url = $("#data").attr("data-billing-base-url")!;+const stripe_response_schema = z.object({session: z.object({type: z.string(),@@ -45,6 +47,7 @@ function handle_session_complete_event(session: StripeSession): void {case "card_update_from_upgrade_page":redirect_to = helpers.get_upgrade_page_url(session.is_manual_license_management_upgrade_session,+ billing_base_url,);break;}@@ -52,7 +55,7 @@ function handle_session_complete_event(session: StripeSession): void {}async function stripe_checkout_session_status_check(stripe_session_id: string): Promise<boolean> {- const response: unknown = await $.get(helpers.get_event_status_url(), {+ const response: unknown = await $.get(`/json${billing_base_url}/billing/event/status`, {stripe_session_id,});const response_data = stripe_response_schema.parse(response);diff --git a/web/src/billing/helpers.ts b/web/src/billing/helpers.tsindex 06b3f9beb08..9f34bde76dd 100644--- a/web/src/billing/helpers.ts+++ b/web/src/billing/helpers.ts@@ -160,37 +160,13 @@ export function redirect_to_billing_with_successful_upgrade(): void {);}-export function get_realm_uuid_from_url(): string | undefined {- const url = new URL(window.location.href);- const path_segments = url.pathname.split("/");- const realm_index = path_segments.indexOf("realm");- if (realm_index !== -1 && realm_index < path_segments.length - 1) {- return path_segments[realm_index + 1];- }-- return undefined;-}--export function get_event_status_url(): string {- const realm_uuid = get_realm_uuid_from_url();- if (realm_uuid) {- return `/json/realm/${realm_uuid}/billing/event/status`;- }- return "/json/billing/event/status";-}-export function get_upgrade_page_url(is_manual_license_management_upgrade_session: boolean | undefined,+ billing_base_url: string,): string {let redirect_to = "/upgrade";if (is_manual_license_management_upgrade_session) {redirect_to += "/?manual_license_management=true";}-- const realm_uuid = get_realm_uuid_from_url();- if (realm_uuid) {- return `/realm/${realm_uuid}` + redirect_to;- }-- return redirect_to;+ return billing_base_url + redirect_to;}