#nikivi

1 messages ยท Page 1 of 1 (latest)

open ferryBOT
wild prawn
#

Hi ๐Ÿ‘‹ what settings/parameters are you unsure about?

open ferryBOT
mossy spade
#

@wild prawn what are the minimal options to create this url

#

grafbase devs said i should somehow use JWT sub

#

but not sure where that goes

#

im reading this and its very unclear what is actually needed to be passed

#
import Stripe from "stripe"

// eslint-disable-next-line turbo/no-undeclared-env-vars
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
  apiVersion: "2022-11-15",
  typescript: true,
})

export default async function Resolver(_: any, { input }: any) {
  const { customerId } = input

  try {
    const data = await stripe.checkout.sessions.create({
      success_url: "https://kuskus.app/success",
      mode: "subscription",
      customer: customerId,
    })
    return { url: data.url }
  } catch (error) {
    console.log(error)
    return {
      url: "test",
    }
  }
}

#

code i have now

#

resolver is basically a function that gets called

#

i just need to know what is needed as input

#

and what object to return

#

the page i need is basically subscription page

#

with 7 day free trial

wild prawn
#

The required parameters are flagged in our API reference for that endpoint:
https://stripe.com/docs/api/checkout/sessions/create

Is there functionality you want to see that isn't being included? Is your code encountering an error saying parameters are missing?

That code is at least missing the line_items parameter, and it will return a Checkout Session object.

mossy spade
#

oh so line_items is needed for subscriptions too

#

my bad, thought it was only for one time payments

#

i started with this article but i got error

#

saying i need it to be mode 'subscription'

#

ok

#

so this url

#
import Stripe from "stripe"

// eslint-disable-next-line turbo/no-undeclared-env-vars
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
  apiVersion: "2022-11-15",
  typescript: true,
})

export default async function Resolver(_: any, { input }: any) {
  const { lineItems } = input

  try {
    const data = await stripe.checkout.sessions.create({
      success_url: "https://kuskus.app/success",
      line_items: lineItems,
      mode: "subscription",
    })
    return { url: data.url }
  } catch (error) {
    console.log(error)
    return {
      url: "test",
    }
  }
}

wild prawn
#

Yes, line_items is required for any mode other than setup. What was the error? They're usually pretty good about explicitly pointing to the problem.

mossy spade
#

basically says this should be good

#

ok trying this now

#

to see if it works

#

ok that worked

#

ok i need a setting for free trial

#

looking now

#

cant find it here ๐Ÿค”

shrewd quest
mossy spade
#

ok that worked, thank you