2021-08-29 15:33:29 +02:00
|
|
|
import logging
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
2023-12-01 06:44:59 +01:00
|
|
|
from corporate.lib.stripe import (
|
|
|
|
EventStatusRequest,
|
|
|
|
RealmBillingSession,
|
|
|
|
RemoteRealmBillingSession,
|
|
|
|
RemoteServerBillingSession,
|
|
|
|
)
|
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
|
|
|
|
|
|
|
|
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
|
|
|
*,
|
|
|
|
stripe_session_id: Optional[str] = None,
|
|
|
|
stripe_payment_intent_id: Optional[str] = None,
|
2021-08-29 15:33:29 +02:00
|
|
|
) -> HttpResponse:
|
2023-11-27 11:07:03 +01:00
|
|
|
event_status_request = EventStatusRequest(
|
|
|
|
stripe_session_id=stripe_session_id, stripe_payment_intent_id=stripe_payment_intent_id
|
|
|
|
)
|
|
|
|
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
|
|
|
@authenticated_remote_realm_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def remote_realm_event_status(
|
|
|
|
request: HttpRequest,
|
|
|
|
billing_session: RemoteRealmBillingSession,
|
|
|
|
*,
|
|
|
|
stripe_session_id: Optional[str] = None,
|
|
|
|
stripe_payment_intent_id: Optional[str] = None,
|
2023-12-13 12:25:23 +01:00
|
|
|
) -> HttpResponse:
|
2023-11-30 14:06:41 +01:00
|
|
|
event_status_request = EventStatusRequest(
|
|
|
|
stripe_session_id=stripe_session_id, stripe_payment_intent_id=stripe_payment_intent_id
|
|
|
|
)
|
|
|
|
data = billing_session.get_event_status(event_status_request)
|
|
|
|
return json_success(request, data)
|
|
|
|
|
|
|
|
|
2023-12-01 06:44:59 +01:00
|
|
|
@authenticated_remote_server_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def remote_server_event_status(
|
|
|
|
request: HttpRequest,
|
|
|
|
billing_session: RemoteServerBillingSession,
|
|
|
|
*,
|
|
|
|
stripe_session_id: Optional[str] = None,
|
|
|
|
stripe_payment_intent_id: Optional[str] = None,
|
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
event_status_request = EventStatusRequest(
|
|
|
|
stripe_session_id=stripe_session_id, stripe_payment_intent_id=stripe_payment_intent_id
|
|
|
|
)
|
|
|
|
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 = "",
|
|
|
|
stripe_payment_intent_id: str = "",
|
2021-08-29 15:33:29 +02:00
|
|
|
) -> HttpResponse:
|
|
|
|
context = {
|
|
|
|
"stripe_session_id": stripe_session_id,
|
|
|
|
"stripe_payment_intent_id": stripe_payment_intent_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 = "",
|
|
|
|
stripe_payment_intent_id: str = "",
|
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
context = {
|
|
|
|
"stripe_session_id": stripe_session_id,
|
|
|
|
"stripe_payment_intent_id": stripe_payment_intent_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 = "",
|
|
|
|
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}",
|
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)
|