MCPcopy
hub / github.com/PostHog/posthog / patch

Method patch

ee/api/billing.py:196–224  ·  view source on GitHub ↗
(self, request: Request, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

194
195 @action(methods=["PATCH"], detail=False, url_path="/")
196 def patch(self, request: Request, *args: Any, **kwargs: Any) -> Response:
197 distinct_id = None if self.request.user.is_anonymous else self.request.user.distinct_id
198 license = License.objects.first_valid()
199 if not license:
200 raise Exception("There is no license configured for this instance yet.")
201
202 org = self._get_org_required()
203 if license and org: # for mypy
204 billing_service_token = build_billing_token(license, org)
205
206 custom_limits_usd = request.data.get("custom_limits_usd")
207 if custom_limits_usd:
208 res = requests.patch(
209 f"{BILLING_SERVICE_URL}/api/billing/",
210 headers={"Authorization": f"Bearer {billing_service_token}"},
211 json={"custom_limits_usd": custom_limits_usd},
212 )
213
214 handle_billing_service_error(res)
215
216 if distinct_id:
217 posthoganalytics.capture(distinct_id, "billing limits updated", properties={**custom_limits_usd})
218 posthoganalytics.group_identify(
219 "organization",
220 str(org.id),
221 properties={f"billing_limits_{key}": value for key, value in custom_limits_usd.items()},
222 )
223
224 return self.list(request, *args, **kwargs)
225
226 @action(methods=["GET"], detail=False)
227 def activation(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:

Callers

nothing calls this directly

Calls 8

_get_org_requiredMethod · 0.95
listMethod · 0.95
build_billing_tokenFunction · 0.85
first_validMethod · 0.80
getMethod · 0.65
patchMethod · 0.65
captureMethod · 0.65

Tested by

no test coverage detected