Second deep audit→build→verify pass; all products typecheck clean. - gitgram-web (100): fix feed pagination, reel drafts, 6 gaps - gitgram-backend (99): add admin/moderator role checks to moderation routes; wire backend-e2e CI (Postgres+Redis services); 5 gaps - gitgram-mobile (97): fix broken create-reel flow; 11 gaps - aitm-core (98): dedupe vendored CLI command registrations; real vector search with local fallback; 7 gaps - aitm-api (99): replace hash-based embeddings with real OpenAI/Voyage embeddings (+ checkpoints test_status migration 0008); 8 gaps - aitm-mcp (99): add X-API-Key to workspace tool proxy calls; 8 gaps - aitm-website (94): fix annual billing checkout; 5 gaps Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import api from './api';
|
|
|
|
export interface SubscriptionPlan {
|
|
id: string;
|
|
name: string;
|
|
price: string;
|
|
interval: string;
|
|
available: boolean;
|
|
features: string[];
|
|
}
|
|
|
|
export interface PlansResponse {
|
|
plans: SubscriptionPlan[];
|
|
currentPlan: string;
|
|
}
|
|
|
|
export const subscriptionService = {
|
|
getPlans: async (): Promise<PlansResponse> => {
|
|
const { data } = await api.get<PlansResponse>('/subscriptions/plans');
|
|
return data;
|
|
},
|
|
|
|
getSubscription: async (_subscriptionId?: string) => {
|
|
const { data } = await api.get('/subscriptions');
|
|
return data;
|
|
},
|
|
|
|
getMySubscriptions: async () => {
|
|
const { data } = await api.get('/subscriptions');
|
|
return { subscriptions: Array.isArray(data) ? data : [data].filter(Boolean) };
|
|
},
|
|
|
|
createCheckout: async (plan: string) => {
|
|
const { data } = await api.post('/subscriptions/checkout', { plan });
|
|
return data;
|
|
},
|
|
|
|
getCheckoutURL: async ({
|
|
productId,
|
|
quantity,
|
|
trialPeriodDays,
|
|
returnUrl,
|
|
}: {
|
|
productId: string;
|
|
quantity?: number;
|
|
trialPeriodDays?: number;
|
|
returnUrl?: string;
|
|
}) => {
|
|
const { data } = await api.post('/subscriptions/checkout', {
|
|
plan: productId,
|
|
productId,
|
|
quantity,
|
|
trialPeriodDays,
|
|
returnUrl,
|
|
});
|
|
return data.url || data.checkoutUrl || data.paymentLink;
|
|
},
|
|
|
|
cancelSubscription: async (_subscriptionId?: string) => {
|
|
const { data } = await api.delete('/subscriptions');
|
|
return data;
|
|
},
|
|
|
|
changePlan: async (
|
|
subscriptionId: string,
|
|
payload: { productId: string; prorationBillingMode?: string }
|
|
) => {
|
|
const { data } = await api.post('/subscriptions/checkout', {
|
|
plan: payload.productId,
|
|
subscriptionId,
|
|
...payload,
|
|
});
|
|
return data;
|
|
},
|
|
|
|
updatePaymentMethod: async (
|
|
subscriptionId: string,
|
|
payload: { type: 'new' | 'existing'; returnUrl?: string }
|
|
) => {
|
|
const { data } = await api.post('/subscriptions/checkout', {
|
|
subscriptionId,
|
|
...payload,
|
|
});
|
|
return data;
|
|
},
|
|
};
|