Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ee/api/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ def deactivate(self, request: Request, *args: Any, **kwargs: Any) -> HttpRespons

return self.list(request, *args, **kwargs)

@action(methods=["POST"], detail=False, url_path="subscription/switch-plan")
def subscription_switch_plan(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
organization = self._get_org_required()
billing_manager = self.get_billing_manager()
res = billing_manager.switch_plan(organization, request.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a validation here, similar to this?

return Response(res, status=status.HTTP_200_OK)

@action(methods=["GET"], detail=False)
def portal(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
license = get_cached_instance_license()
Expand Down
12 changes: 12 additions & 0 deletions ee/billing/billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,18 @@ def authorize_status(self, organization: Organization, data: dict[str, Any]):

return res.json()

def switch_plan(self, organization: Organization, data: dict[str, Any]) -> dict[str, Any]:
res = requests.post(
f"{BILLING_SERVICE_URL}/api/subscription/switch-plan/",
headers=self.get_auth_headers(organization),
json=data,
)

handle_billing_service_error(res)
self.update_available_product_features(organization)

return res.json()

def apply_startup_program(self, organization: Organization, data: dict[str, Any]) -> dict[str, Any]:
res = requests.post(
f"{BILLING_SERVICE_URL}/api/startups/apply",
Expand Down
Loading