Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
import logging
|
|
from typing import TYPE_CHECKING
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
from django.shortcuts import render
|
|
|
|
from corporate.lib.decorator import (
|
|
authenticated_remote_realm_management_endpoint,
|
|
authenticated_remote_server_management_endpoint,
|
|
self_hosting_management_endpoint,
|
|
)
|
|
from zerver.decorator import require_billing_access, zulip_login_required
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.typed_endpoint import typed_endpoint
|
|
from zerver.models import UserProfile
|
|
|
|
if TYPE_CHECKING:
|
|
from corporate.lib.stripe import RemoteRealmBillingSession, RemoteServerBillingSession
|
|
|
|
billing_logger = logging.getLogger("corporate.stripe")
|
|
|
|
|
|
@require_billing_access
|
|
@typed_endpoint
|
|
def event_status(
|
|
request: HttpRequest,
|
|
user: UserProfile,
|
|
*,
|
|
stripe_session_id: str | None = None,
|
|
stripe_invoice_id: str | None = None,
|
|
) -> HttpResponse:
|
|
from corporate.lib.stripe import EventStatusRequest, RealmBillingSession
|
|
|
|
event_status_request = EventStatusRequest(
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
|
)
|
|
billing_session = RealmBillingSession(user)
|
|
data = billing_session.get_event_status(event_status_request)
|
|
return json_success(request, data)
|
|
|
|
|
|
@typed_endpoint
|
|
@authenticated_remote_realm_management_endpoint
|
|
def remote_realm_event_status(
|
|
request: HttpRequest,
|
|
billing_session: "RemoteRealmBillingSession",
|
|
*,
|
|
stripe_session_id: str | None = None,
|
|
stripe_invoice_id: str | None = None,
|
|
) -> HttpResponse:
|
|
from corporate.lib.stripe import EventStatusRequest
|
|
|
|
event_status_request = EventStatusRequest(
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
|
)
|
|
data = billing_session.get_event_status(event_status_request)
|
|
return json_success(request, data)
|
|
|
|
|
|
@typed_endpoint
|
|
@authenticated_remote_server_management_endpoint
|
|
def remote_server_event_status(
|
|
request: HttpRequest,
|
|
billing_session: "RemoteServerBillingSession",
|
|
*,
|
|
stripe_session_id: str | None = None,
|
|
stripe_invoice_id: str | None = None,
|
|
) -> HttpResponse: # nocoverage
|
|
from corporate.lib.stripe import EventStatusRequest
|
|
|
|
event_status_request = EventStatusRequest(
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
|
)
|
|
data = billing_session.get_event_status(event_status_request)
|
|
return json_success(request, data)
|
|
|
|
|
|
@zulip_login_required
|
|
@typed_endpoint
|
|
def event_status_page(
|
|
request: HttpRequest,
|
|
*,
|
|
stripe_session_id: str = "",
|
|
stripe_invoice_id: str = "",
|
|
) -> HttpResponse:
|
|
context = {
|
|
"stripe_session_id": stripe_session_id,
|
|
"stripe_invoice_id": stripe_invoice_id,
|
|
"billing_base_url": "",
|
|
}
|
|
return render(request, "corporate/billing/event_status.html", context=context)
|
|
|
|
|
|
@self_hosting_management_endpoint
|
|
@typed_endpoint
|
|
def remote_realm_event_status_page(
|
|
request: HttpRequest,
|
|
*,
|
|
realm_uuid: str = "",
|
|
server_uuid: str = "",
|
|
stripe_session_id: str = "",
|
|
stripe_invoice_id: str = "",
|
|
) -> HttpResponse: # nocoverage
|
|
context = {
|
|
"stripe_session_id": stripe_session_id,
|
|
"stripe_invoice_id": stripe_invoice_id,
|
|
"billing_base_url": f"/realm/{realm_uuid}",
|
|
}
|
|
return render(request, "corporate/billing/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_invoice_id: str = "",
|
|
) -> HttpResponse: # nocoverage
|
|
context = {
|
|
"stripe_session_id": stripe_session_id,
|
|
"stripe_invoice_id": stripe_invoice_id,
|
|
"billing_base_url": f"/server/{server_uuid}",
|
|
}
|
|
return render(request, "corporate/billing/event_status.html", context=context)
|