29 lines
778 B
TypeScript
29 lines
778 B
TypeScript
import { useMutation, useQuery } from '@tanstack/react-query';
|
|||
|
|
import { api, type ApiError } from '@/lib/api';
|
||
|
|
|
||
|
|
export interface BillingStatus {
|
||
|
|
configured: boolean;
|
||
|
|
plan: 'starter' | 'pro' | 'lifetime';
|
||
|
|
hasSubscription: boolean;
|
||
|
|
hasCustomer: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useBillingStatus() {
|
||
|
|
return useQuery<BillingStatus>({
|
||
|
|
queryKey: ['billing', 'status'],
|
||
|
|
queryFn: () => api.get('/api/billing/status'),
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useStartCheckout() {
|
||
|
|
return useMutation<{ url: string }, ApiError, { plan: 'pro' | 'lifetime' }>({
|
||
|
|
mutationFn: (body) => api.post('/api/billing/checkout', body),
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useOpenPortal() {
|
||
|
|
return useMutation<{ url: string }, ApiError, void>({
|
||
|
|
mutationFn: () => api.post('/api/billing/portal'),
|
||
|
|
});
|
||
|
|
}
|