MCPcopy Create free account
hub / github.com/async-labs/async / createSession

Function createSession

api/server/stripe.ts:22–59  ·  view source on GitHub ↗
({
  email,
  customerId,
  mode,
  quantity,
}: {
  email: string;
  customerId: string;
  mode: Stripe.Checkout.SessionCreateParams.Mode;
  quantity: number;
})

Source from the content-addressed store, hash-verified

20const stripeInstance = new Stripe(API_KEY, { apiVersion: '2022-08-01' });
21
22function createSession({
23 email,
24 customerId,
25 mode,
26 quantity,
27}: {
28 email: string;
29 customerId: string;
30 mode: Stripe.Checkout.SessionCreateParams.Mode;
31 quantity: number;
32}) {
33 const params: Stripe.Checkout.SessionCreateParams = {
34 customer_email: customerId ? undefined : email,
35 customer: customerId,
36 payment_method_types: ['card'],
37 mode,
38 success_url: `${URL_API}/stripe/checkout-completed/{CHECKOUT_SESSION_ID}`,
39 cancel_url: `${URL_APP}/settings/my-billing?message=You%20did%20not%20complete%20payment%20at%20the%20Stripe%20Checkout%20page%2E`,
40 metadata: { email },
41 };
42
43 const price_per_seat = dev ? process.env.STRIPE_TEST_PRICE_ID : process.env.STRIPE_LIVE_PRICE_ID;
44
45 if (mode === 'subscription') {
46 params.line_items = [{ price: price_per_seat, quantity }];
47 } else if (mode === 'setup') {
48 if (!customerId) {
49 // logger.info('customerId is required');
50 throw new Error('customerId is required');
51 }
52
53 params.setup_intent_data = {
54 metadata: { customer_id: customerId },
55 };
56 }
57
58 return stripeInstance.checkout.sessions.create(params);
59}
60
61function retrieveSession({ sessionId }: { sessionId: string }) {
62 return stripeInstance.checkout.sessions.retrieve(sessionId, {

Callers 1

team-leader.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected