This commit is contained in:
imeepos
2026-01-28 14:39:46 +08:00
parent b46ad76161
commit ca63868282
4 changed files with 733 additions and 64 deletions

View File

@@ -70,10 +70,54 @@ export interface BillingPortalResponse {
redirect: boolean
}
export interface PlansParams {
query: {
id: string
key: string
}
}
export interface CreateSubscriptionParams {
priceId: string
productId: string
successUrl: string
cancelUrl: string
}
export interface UpgradeSubscriptionParams {
plan: string
subscriptionId: string
successUrl: string
cancelUrl: string
}
export interface CancelSubscriptionParams {
subscriptionId: string
referenceId: string
}
export interface TopupParams {
amount: number
priceId: string
successUrl: string
cancelUrl: string
}
export interface CheckoutResponse {
url?: string
}
export interface ISubscription {
list: (params?: SubscriptionListParams) => Promise<{ data?: SubscriptionListItem[]; error?: ApiError }>
plans: (params: PlansParams) => Promise<{ data?: any; error?: ApiError }>
create: (params: CreateSubscriptionParams) => Promise<{ data?: CheckoutResponse; error?: ApiError }>
upgrade: (params: UpgradeSubscriptionParams) => Promise<{ data?: any; error?: ApiError }>
cancel: (params: CancelSubscriptionParams) => Promise<{ data?: any; error?: ApiError }>
restore: (params?: SubscriptionRestoreParams) => Promise<{ data?: SubscriptionRestoreResponse; error?: ApiError }>
billingPortal: (params?: BillingPortalParams) => Promise<{ data?: BillingPortalResponse; error?: ApiError }>
credit: {
topup: (params: TopupParams) => Promise<{ data?: CheckoutResponse; error?: ApiError }>
}
}
// 统一的 Token 存储键名(与 fetch-logger.ts 保持一致)
export const getAuthToken = async () => (await storage.getItem(TOKEN_KEY)) || ''