Add subcription feature 2
This commit is contained in:
@@ -402,6 +402,26 @@ export class SubscriptionService {
|
||||
return apiClient.get(`/subscriptions/${tenantId}/invoices`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current payment method for a subscription
|
||||
*/
|
||||
async getCurrentPaymentMethod(
|
||||
tenantId: string
|
||||
): Promise<{
|
||||
brand: string;
|
||||
last4: string;
|
||||
exp_month?: number;
|
||||
exp_year?: number;
|
||||
} | null> {
|
||||
try {
|
||||
const response = await apiClient.get(`/subscriptions/${tenantId}/payment-method`);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Failed to get current payment method:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the default payment method for a subscription
|
||||
*/
|
||||
@@ -416,10 +436,55 @@ export class SubscriptionService {
|
||||
last4: string;
|
||||
exp_month?: number;
|
||||
exp_year?: number;
|
||||
requires_action?: boolean;
|
||||
client_secret?: string;
|
||||
payment_intent_status?: string;
|
||||
}> {
|
||||
return apiClient.post(`/subscriptions/${tenantId}/update-payment-method?payment_method_id=${paymentMethodId}`, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete subscription creation after SetupIntent confirmation
|
||||
*
|
||||
* This method is called after the frontend successfully confirms a SetupIntent
|
||||
* (with or without 3DS authentication). It verifies the SetupIntent and creates
|
||||
* the subscription with the verified payment method.
|
||||
*
|
||||
* @param setupIntentId - The SetupIntent ID that was confirmed by Stripe
|
||||
* @param subscriptionData - Data needed to complete subscription creation
|
||||
* @returns Promise with subscription creation result
|
||||
*/
|
||||
async completeSubscriptionAfterSetupIntent(
|
||||
setupIntentId: string,
|
||||
subscriptionData: {
|
||||
customer_id: string;
|
||||
plan_id: string;
|
||||
payment_method_id: string;
|
||||
trial_period_days?: number;
|
||||
user_id: string;
|
||||
billing_interval: string;
|
||||
}
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
message: string;
|
||||
data: {
|
||||
subscription_id: string;
|
||||
customer_id: string;
|
||||
status: string;
|
||||
plan: string;
|
||||
billing_cycle: string;
|
||||
trial_period_days?: number;
|
||||
current_period_end: string;
|
||||
user_id: string;
|
||||
setup_intent_id: string;
|
||||
};
|
||||
}> {
|
||||
return apiClient.post('/subscriptions/complete-after-setup-intent', {
|
||||
setup_intent_id: setupIntentId,
|
||||
...subscriptionData
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// NEW METHODS - Usage Forecasting & Predictive Analytics
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user