feat: add subscription cancellation functionality to OrganizationSettings component

This commit is contained in:
Usman Baig
2026-02-09 10:25:10 +01:00
parent fe2eaa53b1
commit d39f9231c0
2 changed files with 123 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ export interface SubscriptionDetails {
billing_interval: string
pageview_limit: number
has_payment_method: boolean
/** True when subscription is set to cancel at the end of the current period. */
cancel_at_period_end?: boolean
/** Number of sites for the org (billing usage). Present when backend supports usage API. */
sites_count?: number
/** Pageviews in current billing period (when pageview_limit > 0). Present when backend supports usage API. */
@@ -50,6 +52,18 @@ export async function createPortalSession(): Promise<{ url: string }> {
})
}
export interface CancelSubscriptionParams {
/** If true (default), cancel at end of billing period; if false, cancel immediately. */
at_period_end?: boolean
}
export async function cancelSubscription(params?: CancelSubscriptionParams): Promise<{ ok: boolean; at_period_end: boolean }> {
return await billingFetch<{ ok: boolean; at_period_end: boolean }>('/api/billing/cancel', {
method: 'POST',
body: JSON.stringify({ at_period_end: params?.at_period_end ?? true }),
})
}
export interface CreateCheckoutParams {
plan_id: string
interval: string