#vlady-_code

1 messages ยท Page 1 of 1 (latest)

exotic pierBOT
#

๐Ÿ‘‹ 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.

ancient topaz
#
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

topaz hull
#

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?

ancient topaz
#

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.

topaz hull
exotic pierBOT
ancient topaz
#

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 ?? '';
    }

};
topaz hull
ancient topaz
#

Great, it works! Thank you very much!