Closed yagasta closed 1 year ago
backend
app.post("/checkout", async (req, res) => { try { const cartItems = req.body; const sanityData = await sanityClient.fetch( '*[_type in ["games", "gears"]]{"name":title, "id": _id, price, "poster": poster.asset->url, currency }' ); let line_items = validateCartItems(sanityData, cartItems); const params = { submit_type: "pay", mode: "payment", payment_method_types: ["card"], billing_address_collection: "auto", line_items, success_url: `http://127.0.0.1:5173/`, cancel_url: `http://127.0.0.1:5173/`, }; const session = await stripe.checkout.sessions.create(params); res.status(200).json(session); } catch (error) { res.status(500).json({ message: "While communicating with Stripe, we encountered an error.", error: error.message, }); } });
I was able to solve it by replacing redirectToCheckout with window.location = response.url. Is there any downside to doing it this way?
Ahh... I forgot change the successUrl in CartProvider component.
backend
I was able to solve it by replacing redirectToCheckout with window.location = response.url. Is there any downside to doing it this way?