Created
October 20, 2022 07:08
-
-
Save cagdasyetkin/b34d7b166f57028e0da00418ebc66b79 to your computer and use it in GitHub Desktop.
Stripe checkout session modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY); | |
export default async (req, res) => { | |
const { items, email } = req.body; | |
const transformedItems = items.map((item) => ({ | |
quantity: 1, | |
price_data: { | |
//description: item.description, | |
currency: "gbp", | |
unit_amount: item.price * 100, | |
product_data: { | |
name: item.title, | |
//images: [item.image], | |
}, | |
}, | |
})); | |
const session = await stripe.checkout.sessions.create({ | |
//payment_method_types: ["card"], | |
//shipping_rates: ["shr_1LttqDGAsA90AlEHZODUNj5P"], | |
//shipping_address_collection: { | |
// allowed_countries: ["GB", "US", "CA"], | |
//}, | |
line_items: transformedItems, | |
mode: "payment", | |
success_url: `${process.env.HOST}/success`, | |
cancel_url: `${process.env.HOST}/checkout`, | |
metadata: { | |
email, | |
images: JSON.stringify(items.map((item) => item.image)), | |
}, | |
}); | |
res.status(200).json({ id: session.id }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment