I’m looking to fetch a value from my Node.js backend within a JavaScript file.
Here is the backend code snippet:
(async () => { const orderSession = await stripe.checkout.sessions.create({ payment_method_types: [‘card’], line_items: [{ name: ‘T-shirt’, description: ‘Comfortable cotton t-shirt’, images: [‘https://example.com/t-shirt.png’], amount: 500, currency: ‘eur’, quantity: ((req.body.tickets - 0) + (req.body.tickets_kid - 0)), }], success_url: ‘http://localhost:3000/thank-you?session_id={orderSession.id}’, cancel_url: ‘https://localhost:3000/tickets’, }); res.send(orderSession); })();
And here’s my frontend code:
const stripeClient = Stripe(‘secretkey’); const orderSession = ? console.log(orderSession); async function initiateCheckout() { console.log(‘Checkout initiated’); const { error } = await stripeClient.redirectToCheckout({ sessionId: ‘{{orderSession.id}}’ }); window.alert(error.message); };
I’m attempting to pass the session ID to the JavaScript file. Any assistance would be appreciated.