#nikivi
1 messages · Page 1 of 1 (latest)
try {
const data = await stripe.checkout.sessions.create({
success_url: "http://localhost:3000/success",
mode: "subscription",
})
return { url: data.url }
} catch (error) {
console.log(error)
}
so i have this now
i get this error back
i kind of get it
but the thing is that i have the product here
like shouldn't i be referncing it
basically I want to setup a payment page for 10$/month
i started reading this doc
line_items: [{
# For metered billing, do not pass quantity
quantity: 1,
price: price_id,
}],
it wants me to do this
const data = await stripe.checkout.sessions.create({
success_url: "http://localhost:3000/success",
mode: "subscription",
line_items: [{
quantity: 1,
price: "10",
}],
})
so this in my case i guess
or wait its id
This is a Checkout Session, and it needs a Price.
Just as in this snippet you just shared.
But this is a Payment Link, a different Stripe product.
You need to create a Product (contains name, images, description) and a Price (contains amount, currency, recurrent settings) - https://stripe.com/docs/products-prices/how-products-and-prices-work
ok i have this
The Price has an ID price_xxx, you need to pass it in line_items
this right?
ok that returns something
i thought ```
try {
const data = await stripe.checkout.sessions.create({
success_url: "http://localhost:3000/success",
mode: "subscription",
line_items: [
{
quantity: 1,
price: "price_1N4NrWKmRnbuc3WvWhmp93hl",
},
],
})
return {
suggestedTasks: null,
stripeCheckoutUrl: data.url,
}
the .url will contain the url to the checkout session
like for context
this is an endpoint that checks if user can do an action, if not, it returns with a stripe payment url
thats what I thought should happen
basing it of this
ok that actually seems to return the thing, issue is on grafbase side
thank you @junior coyote
Please don't share your Secret key.
oops
i thought i was on test thing
i pressed the test button
can i rotate it?
or should i create new product now to be safe
It's only a part of it and it's Test mode, so deleting the screenshot should be fine.
Happy to help. Please, let me know if you have any other questions.
@junior coyote if you can help more would be grateful
im now doing this basically
there is surprisingly now js snippet
im using this as my front end
i thought the code would look something like this
above is for google sign in callback
i created my route
then this i assume should be this
but i need to get checkout_session_id somehow 🤔
Hey, sorry, this is a bit too much info. Let's go step by step 😉
What are you trying to achieve?
so i managed to show this
when users pay, they will go to success_url
when they go to that URL, I in my case should do a graphql query to my db saying that this user now has paid
i don't know how to do last part
essentially this value flipped
not sure if it should be boolean
and i should check monthly to flip it or it should be a date
until the subscription is valid, probably date is more sensible
but in any way, not really sure how to approach solving this
This is a bad setup. You should not perform any business logic based on users going to your success URL. What if they close the page right after payment?
Please use webhooks for this: https://stripe.com/docs/webhooks
oh thats smarter
so web hook will do graphql query
if I do a web hook
the success page can just info basically, hey thanks for paying
For webhook you will need to create a REST endpoint. And within it you can update your DB directly.
no more logic done there
For webhook you will need to create a REST endpoint
is my database essentially
there is no rest endpoint
there is a resolver i can create
but that would be a graphql too
will it work?
I don't know exactly how GraphQL works, but you can follow our guide and see if you run into any issues: https://stripe.com/docs/webhooks
Please, let me know if you have any other questions.