#nikivi_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1254792695243739257
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
import { cors } from '@elysiajs/cors'
import { Elysia, t } from 'elysia'
import { stripe } from '@/api/lib/stripe'
const app = new Elysia()
.onError(({ error }) => {
console.log(error, 'error')
return new Response(error.toString())
})
.use(cors())
.post(
'/create-product',
async ({ body }) => {
const { productRoninId, productTitle, productDescription, productPrice } = body
console.log(process.env.STRIPE_SECRET_KEY!, 'secret key')
console.log('----')
const product = await stripe.products.create({
name: productTitle
// description: productDescription,
// default_price_data: {
// unit_amount: productPrice * 100,
// currency: 'usd'
// }
})
console.log(product, 'stripe product')
},
{
body: t.Object({
productRoninId: t.String(),
productTitle: t.String(),
productDescription: t.String(),
productPrice: t.Number()
})
}
)
my full endpoint
@/api/lib/stripe looks like
import Stripe from 'stripe'
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
// https://github.com/stripe/stripe-node#configuration
apiVersion: '2024-04-10'
})
export const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET!
I essentially want to create a product on demand that will have a checkout page
I thought from docs
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I could use above api for this
but getting
ok this actually works
and I get massive product back
but which field is the checkout url
to show to do payment
because I want to do stripe checkout that has name, description, price filled in
is 200
Hi there ๐ I'm not sure where the response you're sharing is coming from, that doesn't look like the format for a response from our API.
Creating a Product does not provide you with a URL that you can share for customers to check out.
For the latter you either need to create a Checkout Session, where you can use price_data and product_data to create your Price and Product objects adhoc.
I need to create session
Or you'd create a Payment Link for the newly created Product.
but the thing is that
this product can be anything
i.e. a product can have a title etc. that is custom
previous i only used stripe for saas
and there i had products that users bought but here I have to make on demand
checkout sessions
that can be anything
checking thx โค๏ธ
Pretty sure that's the parameter you're looking for
i.e. here
price_1MotwRLkdIwHu7ixYcPLm5uZ
i dont know this
the price can be arbitrary
if that makes sense
i.e. I pass create stripe product with name, description and price and I get back checkout session
and also productId as metadata passed to checkout session
then in web hook when session is complete, I make sure user owns that product for real
thats how I thought i'd do it
but with code above, it wants me to know price_1MotwRLkdIwHu7ixYcPLm5uZ
which I can't know as that price_1MotwRLkdIwHu7ixYcPLm5uZ is fixed to a price
perhaps I misunderstand things
const session = await stripe.checkout.sessions.create({
success_url: 'https://solbond.co/payment-success',
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: productTitle,
description: productDescription
},
unit_amount: Math.round(Number(productPrice) * 100)
},
quantity: 1
}
],
mode: 'payment',
metadata: {
productRoninId: productRoninId
}
})
sonnet said to do this potentially, will try now
ok i get back 200 and session back
how do I get checkoutSession from it
i do get events
trying to make sense of https://docs.stripe.com/api/checkout/sessions/line_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
const checkoutSessionUrl = session.
thought I can get it from line_items
but its not on session
I don't understand what the current question is. You say you get a session back, but don't know how to get the session from that?
yes
async ({ body }) => {
const { productTitle, productDescription, productPrice, productRoninId } = body
console.log(process.env.STRIPE_SECRET_KEY!, 'secret key')
console.log('----')
const session = await stripe.checkout.sessions.create({
success_url: 'https://solbond.co/payment-success',
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: productTitle,
description: productDescription
},
unit_amount: Math.round(Number(productPrice) * 100)
},
quantity: 1
}
],
mode: 'payment',
metadata: {
productRoninId: productRoninId
}
})
The response to the request is a Checkout Session object.
this creates what I think is a product
yes
basically i need a checkout session tied to productId
and at that point
i need to get the session url
so when user presses
it will open stripe checkout
user pays there, and on web hook i update my own db to unlock product
if that makes sense
i still am confused how to get checkout url
i get big object back from await stripe.checkout.sessions.create
but it doesn't seem to have checkout url
apologize if its unclear, I can expand more
The Checkout Session should absolutely have a url field on it. The full structure of our object types can always be referenced from our API reference:
https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-url
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
thank you that seems to work
will do web hooks now but will open new thread if stuck
appreciate the help a lot
Any time!