2021-08-29 15:33:29 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
2023-11-30 14:04:36 +01:00
|
|
|
from pydantic import Json
|
2021-08-29 15:33:29 +02:00
|
|
|
|
2023-12-01 06:44:59 +01:00
|
|
|
from corporate.lib.decorator import (
|
|
|
|
authenticated_remote_realm_management_endpoint,
|
|
|
|
authenticated_remote_server_management_endpoint,
|
|
|
|
)
|
|
|
|
from corporate.lib.stripe import (
|
|
|
|
RealmBillingSession,
|
|
|
|
RemoteRealmBillingSession,
|
|
|
|
RemoteServerBillingSession,
|
|
|
|
)
|
2021-08-29 15:33:29 +02:00
|
|
|
from zerver.decorator import require_billing_access, require_organization_member
|
|
|
|
from zerver.lib.response import json_success
|
2023-11-30 14:04: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_billing_access
|
|
|
|
def start_card_update_stripe_session(request: HttpRequest, user: UserProfile) -> HttpResponse:
|
2023-11-06 13:52:12 +01:00
|
|
|
billing_session = RealmBillingSession(user)
|
2023-12-02 09:09:43 +01:00
|
|
|
session_data = billing_session.create_card_update_session()
|
|
|
|
return json_success(
|
|
|
|
request,
|
|
|
|
data=session_data,
|
2021-08-29 15:33:29 +02:00
|
|
|
)
|
2023-12-02 09:09:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
@authenticated_remote_realm_management_endpoint
|
|
|
|
def start_card_update_stripe_session_for_remote_realm(
|
|
|
|
request: HttpRequest, billing_session: RemoteRealmBillingSession
|
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
session_data = billing_session.create_card_update_session()
|
2021-08-29 15:33:29 +02:00
|
|
|
return json_success(
|
2022-01-31 13:44:02 +01:00
|
|
|
request,
|
2023-12-02 09:09:43 +01:00
|
|
|
data=session_data,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@authenticated_remote_server_management_endpoint
|
|
|
|
def start_card_update_stripe_session_for_remote_server(
|
|
|
|
request: HttpRequest, billing_session: RemoteServerBillingSession
|
|
|
|
) -> HttpResponse: # nocoverage
|
|
|
|
session_data = billing_session.create_card_update_session()
|
|
|
|
return json_success(
|
|
|
|
request,
|
|
|
|
data=session_data,
|
2021-08-29 15:33:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@require_organization_member
|
2023-11-30 14:04:36 +01:00
|
|
|
@typed_endpoint
|
2023-11-18 11:29:04 +01:00
|
|
|
def start_card_update_stripe_session_for_realm_upgrade(
|
2023-11-21 12:41:38 +01:00
|
|
|
request: HttpRequest,
|
|
|
|
user: UserProfile,
|
2023-11-30 14:04:36 +01:00
|
|
|
*,
|
|
|
|
manual_license_management: Json[bool] = False,
|
2023-12-18 13:02:36 +01:00
|
|
|
tier: Json[int],
|
2021-08-29 15:33:29 +02:00
|
|
|
) -> HttpResponse:
|
2023-11-06 13:52:12 +01:00
|
|
|
billing_session = RealmBillingSession(user)
|
2023-12-18 13:02:36 +01:00
|
|
|
session_data = billing_session.create_card_update_session_for_upgrade(
|
|
|
|
manual_license_management, tier
|
|
|
|
)
|
2023-11-30 14:06:41 +01:00
|
|
|
return json_success(
|
|
|
|
request,
|
2023-12-01 03:51:05 +01:00
|
|
|
data=session_data,
|
2023-11-30 14:06:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@authenticated_remote_realm_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def start_card_update_stripe_session_for_remote_realm_upgrade(
|
|
|
|
request: HttpRequest,
|
|
|
|
billing_session: RemoteRealmBillingSession,
|
|
|
|
*,
|
|
|
|
manual_license_management: Json[bool] = False,
|
2023-12-18 13:02:36 +01:00
|
|
|
tier: Json[int],
|
2023-12-13 12:25:23 +01:00
|
|
|
) -> HttpResponse:
|
2023-12-18 13:02:36 +01:00
|
|
|
session_data = billing_session.create_card_update_session_for_upgrade(
|
|
|
|
manual_license_management, tier
|
|
|
|
)
|
2021-08-29 15:33:29 +02:00
|
|
|
return json_success(
|
2022-01-31 13:44:02 +01:00
|
|
|
request,
|
2023-12-01 03:51:05 +01:00
|
|
|
data=session_data,
|
2021-08-29 15:33:29 +02:00
|
|
|
)
|
2023-12-01 06:44:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
@authenticated_remote_server_management_endpoint
|
|
|
|
@typed_endpoint
|
|
|
|
def start_card_update_stripe_session_for_remote_server_upgrade(
|
|
|
|
request: HttpRequest,
|
|
|
|
billing_session: RemoteServerBillingSession,
|
|
|
|
*,
|
|
|
|
manual_license_management: Json[bool] = False,
|
2023-12-18 13:02:36 +01:00
|
|
|
tier: Json[int],
|
2023-12-19 12:24:15 +01:00
|
|
|
) -> HttpResponse:
|
2023-12-18 13:02:36 +01:00
|
|
|
session_data = billing_session.create_card_update_session_for_upgrade(
|
|
|
|
manual_license_management, tier
|
|
|
|
)
|
2023-12-01 06:44:59 +01:00
|
|
|
return json_success(
|
|
|
|
request,
|
|
|
|
data=session_data,
|
|
|
|
)
|