#took a few days off so im remembering

1 messages · Page 1 of 1 (latest)

tender badge
#

Hey if it helps you

#

I'm just gonna paste my stripe checkout code

#
export const createStripeCheckoutSession = async (
  user: UserEntity,
  team: TeamEntity,
  knex: Knex,
): Promise<Stripe.Response<Stripe.Checkout.Session>> => {
  const noTrial = user.hasUsedTrial || team.demoTeam;

  const session = await stripe.checkout.sessions.create({
    mode: `subscription`,
    success_url: getAppUrl(getDashboardRouteTeamRedirect(team.id)),
    cancel_url: getAppUrl(getDashboardRoute()),
    // consent_collection: {
    //   terms_of_service: `required`,
    // },
    billing_address_collection: `auto`,
    customer_email: user.email,
    currency: `usd`,
    allow_promotion_codes: true,
    line_items: [
      {
        price: process.env.STRIPE_PRO_PRICE,
        quantity: 1,
      },
      {
        price: process.env.STRIPE_TEAM_MEMBER_PRICE,
        quantity: await countTeamMembers({ teamId: team.id }, knex),
      },
    ],
    subscription_data: noTrial
      ? undefined
      : {
          trial_period_days: TRIAL_PERIOD_DAYS,
        },
    metadata: {
      teamId: team.id,
      isTrial: noTrial ? `false` : `true`,
    },
  });

  return session;
};
#

all that's needed is the stripe on the server

#

the session object will have a url that you can then redirect your user to

#

either through a http 3xx redirect or by getting the url in the browser and triggering a url change

distant dagger
#

o i just made a different post on the help forum .. hold on lemme back track

#

ok so i Have 2 files, loadStripe which returns the stripe promise, and the Stripe(secret key) object

tender badge
#

I gotta go, just wanted to make sure I share some code if it helps you

distant dagger
#

thanks it does i appreciate it

#

np

tender badge
#

but i'll respond in the proper forum post

#

when im back

distant dagger
#

your help is graciousl, thank you