#aleksfr
1 messages · Page 1 of 1 (latest)
Hello! Is this with Stripe Checkout?
If so, you can use price_data to specify arbitrary Price and Product information instead of using an existing Price: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Not sure, im new to stripe haha.
heres an example:
User1 lists a bike on my website
User2 wants to purchase the bike
How can i make stripe work with that so i dont have to make a product for each new item listed, so User2 pays me i see User2 is trying to buy User1 bike and then do all the processes that are needed to be done
It depends on what products/APIs you're using in your integration.
Im working in a nextjs envirourment and i cant really go manually set a product for each time a user lists on my website.
I mean what Stripe APIs you're using.
Are you creating Checkout Sessions? Payment Links? Payment Intents? Something else? The answer is different based on what you're using.
checkout sessions i must guess
I just followed this https://stripe.com/docs/checkout/quickstart
Okay, then my original answer above applies.
im still a bit confused
import {NextApiRequest, NextApiResponse} from "next";
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'POST') {
try {
// Create Checkout Sessions from body params.
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'ID',
quantity: 1,
},
],
mode: 'payment',
success_url: `${req.headers.origin}/?success=true`,
cancel_url: `${req.headers.origin}/?canceled=true`,
automatic_tax: {enabled: true},
});
res.redirect(303, session.url);
//@ts-ignore
} catch (err: Error) {
res.status(err.statusCode || 500).json(err.message);
}
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
}
this is my current checkout_session
but what if the user wants to pay for what a user listed on the website? the price will be diffrent each time
how would i be able to set it so i can just charge the user a price with my own unique identifier possibly, or is their another way?