MCPcopy
hub / github.com/nextjs/saas-starter / createCheckoutSession

Function createCheckoutSession

lib/payments/stripe.ts:14–47  ·  view source on GitHub ↗
({
  team,
  priceId
}: {
  team: Team | null;
  priceId: string;
})

Source from the content-addressed store, hash-verified

12});
13
14export async function createCheckoutSession({
15 team,
16 priceId
17}: {
18 team: Team | null;
19 priceId: string;
20}) {
21 const user = await getUser();
22
23 if (!team || !user) {
24 redirect(`/sign-up?redirect=checkout&priceId=${priceId}`);
25 }
26
27 const session = await stripe.checkout.sessions.create({
28 payment_method_types: ['card'],
29 line_items: [
30 {
31 price: priceId,
32 quantity: 1
33 }
34 ],
35 mode: 'subscription',
36 success_url: `${process.env.BASE_URL}/api/stripe/checkout?session_id={CHECKOUT_SESSION_ID}`,
37 cancel_url: `${process.env.BASE_URL}/pricing`,
38 customer: team.stripeCustomerId || undefined,
39 client_reference_id: user.id.toString(),
40 allow_promotion_codes: true,
41 subscription_data: {
42 trial_period_days: 14
43 }
44 });
45
46 redirect(session.url!);
47}
48
49export async function createCustomerPortalSession(team: Team) {
50 if (!team.stripeCustomerId || !team.stripeProductId) {

Callers 2

actions.tsFile · 0.90
actions.tsFile · 0.90

Calls 1

getUserFunction · 0.90

Tested by

no test coverage detected