2021-08-29 15:33:29 +02:00
|
|
|
import logging
|
2024-09-24 23:27:28 +02:00
|
|
|
from typing import TYPE_CHECKING
|
2021-08-29 15:33:29 +02:00
|
|
|
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
2023-11-30 14:06:41 +01:00
|
|
|
from corporate.lib.decorator import (
|
|
|
|
authenticated_remote_realm_management_endpoint,
|
2023-12-01 06:44:59 +01:00
|
|
|
authenticated_remote_server_management_endpoint,
|
2023-11-30 14:06:41 +01:00
|
|
|
self_hosting_management_endpoint,
|
|
|
|
)
|
2021-08-29 15:33:29 +02:00
|
|
|
from zerver.decorator import require_organization_member, zulip_login_required
|
|
|
|
from zerver.lib.response import json_success
|
2023-11-30 12:43:36 +01:00
|
|
|
from zerver.lib.typed_endpoint import typed_endpoint
|
2021-08-29 15:33:29 +02:00
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
2024-09-24 23:27:28 +02:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from corporate.lib.stripe import RemoteRealmBillingSession, RemoteServerBillingSession
|
|
|
|
|
2021-08-29 15:33:29 +02:00
|
|
|
billing_logger = logging.getLogger("corporate.stripe")
|
|
|
|
|
|
|
|
|
|
|
|
@require_organization_member
|
2023-11-30 14:03:25 +01:00
|
|
|
@typed_endpoint
|
2021-08-29 15:33:29 +02:00
|
|
|
def event_status(
|
|
|
|
request: HttpRequest,
|
|
|
|
user: UserProfile,
|
2023-11-30 14:03:25 +01:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
stripe_session_id: str | None = None,
|
|
|
|
stripe_invoice_id: str | None = None,
|
2021-08-29 15:33:29 +02:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import EventStatusRequest, RealmBillingSession
|
|
|
|
|
2023-11-27 11:07:03 +01:00
|
|
|
event_status_request = EventStatusRequest(
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
2023-11-27 11:07:03 +01:00
|
|
|
)
|
|
|
|
billing_session = RealmBillingSession(user)
|
|
|
|
data = billing_session.get_event_status(event_status_request)
|
|
|
|
return json_success(request, data)
|
2021-08-29 15:33:29 +02:00
|
|
|
|
|
|
|
|
2023-11-30 14:06:41 +01:00
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_realm_management_endpoint
|
2023-11-30 14:06:41 +01:00
|
|
|
def remote_realm_event_status(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteRealmBillingSession",
|
2023-11-30 14:06:41 +01:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
stripe_session_id: str | None = None,
|
|
|
|
stripe_invoice_id: str | None = None,
|
2023-12-13 12:25:23 +01:00
|
|
|
) -> HttpResponse:
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import EventStatusRequest
|
|
|
|
|
2023-11-30 14:06:41 +01:00
|
|
|
event_status_request = EventStatusRequest(
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
2023-11-30 14:06:41 +01:00
|
|
|
)
|
|
|
|
data = billing_session.get_event_status(event_status_request)
|
|
|
|
return json_success(request, data)
|
|
|
|
|
|
|
|
|
2023-12-01 06:44:59 +01:00
|
|
|
@typed_endpoint
|
2024-09-24 23:27:28 +02:00
|
|
|
@authenticated_remote_server_management_endpoint
|
2023-12-01 06:44:59 +01:00
|
|
|
def remote_server_event_status(
|
|
|
|
request: HttpRequest,
|
2024-09-24 23:27:28 +02:00
|
|
|
billing_session: "RemoteServerBillingSession",
|
2023-12-01 06:44:59 +01:00
|
|
|
*,
|
2024-07-12 02:30:23 +02:00
|
|
|
stripe_session_id: str | None = None,
|
|
|
|
stripe_invoice_id: str | None = None,
|
2023-12-01 06:44:59 +01:00
|
|
|
) -> HttpResponse: # nocoverage
|
2024-09-24 23:27:28 +02:00
|
|
|
from corporate.lib.stripe import EventStatusRequest
|
|
|
|
|
2023-12-01 06:44:59 +01:00
|
|
|
event_status_request = EventStatusRequest(
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_session_id=stripe_session_id, stripe_invoice_id=stripe_invoice_id
|
2023-12-01 06:44:59 +01:00
|
|
|
)
|
|
|
|
data = billing_session.get_event_status(event_status_request)
|
|
|
|
return json_success(request, data)
|
|
|
|
|
|
|
|
|
2021-08-29 15:33:29 +02:00
|
|
|
@zulip_login_required
|
2023-11-30 12:43:36 +01:00
|
|
|
@typed_endpoint
|
2021-08-29 15:33:29 +02:00
|
|
|
def event_status_page(
|
|
|
|
request: HttpRequest,
|
2023-11-30 12:43:36 +01:00
|
|
|
*,
|
|
|
|
stripe_session_id: str = "",
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_invoice_id: str = "",
|
2021-08-29 15:33:29 +02:00
|
|
|
) -> HttpResponse:
|
|
|
|
context = {
|
|
|
|
"stripe_session_id": stripe_session_id,
|
2024-02-10 07:47:32 +01:00
|
|
|
"stripe_invoice_id": stripe_invoice_id,
|
2023-12-01 04:45:05 +01:00
|
|
|
"billing_base_url": "",
|
2021-08-29 15:33:29 +02:00
|
|
|
}
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/event_status.html", context=context)
|
2023-11-30 14:06:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
@self_hosting_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def remote_realm_event_status_page(
|
|
|
|
request: HttpRequest,
|
|
|
|
*,
|
|
|
|
realm_uuid: str = "",
|
|
|
|
server_uuid: str = "",
|
|
|
|
stripe_session_id: str = "",
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_invoice_id: str = "",
|
2023-11-30 14:06:41 +01:00
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
context = {
|
|
|
|
"stripe_session_id": stripe_session_id,
|
2024-02-10 07:47:32 +01:00
|
|
|
"stripe_invoice_id": stripe_invoice_id,
|
2023-12-01 04:45:05 +01:00
|
|
|
"billing_base_url": f"/realm/{realm_uuid}",
|
|
|
|
}
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/event_status.html", context=context)
|
2023-12-01 04:45:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
@self_hosting_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def remote_server_event_status_page(
|
|
|
|
request: HttpRequest,
|
|
|
|
*,
|
|
|
|
realm_uuid: str = "",
|
|
|
|
server_uuid: str = "",
|
|
|
|
stripe_session_id: str = "",
|
2024-02-10 07:47:32 +01:00
|
|
|
stripe_invoice_id: str = "",
|
2023-12-01 04:45:05 +01:00
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
context = {
|
|
|
|
"stripe_session_id": stripe_session_id,
|
2024-02-10 07:47:32 +01:00
|
|
|
"stripe_invoice_id": stripe_invoice_id,
|
2023-12-01 04:45:05 +01:00
|
|
|
"billing_base_url": f"/server/{server_uuid}",
|
2023-11-30 14:06:41 +01:00
|
|
|
}
|
2024-01-29 15:46:18 +01:00
|
|
|
return render(request, "corporate/billing/event_status.html", context=context)
|