Add subcription feature 9

This commit is contained in:
Urtzi Alfaro
2026-01-16 20:25:45 +01:00
parent fa7b62bd6c
commit 3a7d57ef90
19 changed files with 1833 additions and 985 deletions

View File

@@ -252,8 +252,12 @@ export class SubscriptionService {
return apiClient.get<PlanUpgradeValidation>(`/tenants/${tenantId}/subscription/validate-upgrade/${planKey}`);
}
async upgradePlan(tenantId: string, planKey: string): Promise<PlanUpgradeResult> {
return apiClient.post<PlanUpgradeResult>(`/tenants/${tenantId}/subscription/upgrade`, { new_plan: planKey });
async upgradePlan(tenantId: string, planKey: string, billingCycle: BillingCycle = 'monthly'): Promise<PlanUpgradeResult> {
// The backend expects new_plan and billing_cycle as query parameters
return apiClient.post<PlanUpgradeResult>(
`/tenants/${tenantId}/subscription/upgrade?new_plan=${planKey}&billing_cycle=${billingCycle}`,
{}
);
}
async canAddLocation(tenantId: string): Promise<{ can_add: boolean; reason?: string; current_count?: number; max_allowed?: number }> {

View File

@@ -261,11 +261,16 @@ export interface PlanUpgradeResult {
success: boolean;
message: string;
new_plan: SubscriptionTier;
effective_date: string;
effective_date?: string;
old_plan?: string;
new_monthly_price?: number;
validation?: any;
requires_token_refresh?: boolean; // Backend signals that token should be refreshed
// Trial handling fields
is_trialing?: boolean;
trial_ends_at?: string;
stripe_updated?: boolean;
trial_preserved?: boolean;
}
export interface SubscriptionInvoice {