export type GetApiStripeCheckoutArgs = {tier: 'hacker' | 'pro' | 'quant'}; export type GetApiStripeCheckoutOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Start paid subscription checkout * * GET /stripe/checkout */ export const getApiStripeCheckout = async (args: GetApiStripeCheckoutArgs, options?: GetApiStripeCheckoutOptions) => { const {baseUrl = "https://api.brieftape.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.tier != null) query.append("tier", String(args.tier)) const url = `${baseUrl.replace(/\/+$/, '')}/stripe/checkout${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };