File size: 788 Bytes
65d68f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { apiPost } from "@/lib/api/client";
import type { BillingMe } from "@/lib/api/types";
import type { ActivePaidBillingPlanKey } from "@/lib/billing/activePlans";

export type CheckoutSession = {
  url: string;
  session_id: string;
};

export type BillingPortalSession = {
  url: string;
};

export function createCheckoutSession(plan: ActivePaidBillingPlanKey) {
  return apiPost<CheckoutSession, { plan: ActivePaidBillingPlanKey }>(
    "/billing/create-checkout-session",
    { plan },
  );
}

export function startBillingTrial() {
  return apiPost<BillingMe, Record<string, never>>("/billing/start-trial", {});
}

export function createBillingPortalSession() {
  return apiPost<BillingPortalSession, Record<string, never>>(
    "/billing/create-portal-session",
    {},
  );
}