#vlady-_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1239963606213197927
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
import {loadStripe} from '@stripe/stripe-js'
const stripePromise = loadStripe(`${process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY}`);
const handlePayment = async () => {
const stripe = await stripePromise;
console.log(stripe)
if (stripe) {
const { error } = await stripe.redirectToCheckout({
lineItems: [
{ price: 'price_id', quantity: 1 },
],
mode: 'payment',
successUrl: 'https://yourwebsite.com/success',
cancelUrl: 'https://yourwebsite.com/cancel',
});
if (error) {
console.error('Error:', error);
// Handle error
}
}
};
full code
Hi there ๐ we typically no longer recommend leveraging client-only checkout integrations, can you help me understand what you're seeing. Is "The Checkout client-only integration is not enabled. Enable it in the Dashboard at " an error message you're receiving in response to a request you're making?
Hi toby, I appreciate your time in trying to help me. I was actually following a template, but it seemed like that was kind of outdated and no longer working.
My question is, what endpoint should I use to redirect to the checkout page?
import Stripe from 'stripe';
const stripe = new Stripe(`${process.env.STRIPE_SECRET_KEY ?? 'sk_test_my_key'}`, {
apiVersion: '2024-04-10',
});
const handlePayment = async () => {
let data = await stripe.paymentIntents.create({
amount: 3500,
currency: 'eur',
payment_method_types: ['card'],
})
console.log(data)
};
I haven't been using Stripe in quite a while and I've forgot the way it is used.
Our current guide for creating and using a Checkout Session to accept a payment can be found here:
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=stripe-hosted
It walks through the full process, but let me know if anything in there isn't clear!
Great!
That kinda made it, only one last thing.. is it possible to pass the Product ID?
For example:
const handlePayment = async () => {
let data = await stripe.checkout.sessions.create({
line_items: [
{
price_data: {
currency: 'eur',
product_data: {
name: 'AI Bundle',
},
unit_amount: 1,
recurring: {
interval: 'day',
interval_count: 30,
},
},
quantity: 1,
},
],
mode: 'subscription',
success_url: 'http://localhost:4242/success',
cancel_url: 'http://localhost:4242/cancel',
});
if (data.id !== undefined) {
window.location.href = data.url ?? '';
}
};
Yup, you can pass Price and Product IDs instead of using price_data and product_data:
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-price
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Great, it works! Thank you very much!