mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	event_status: Pass billing_base_url to calculate realm specific URLs.
This commit is contained in:
		@@ -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),
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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">
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user