-
-
Save AlbionaHoti/757544d7953962842bfac5a50f9a6010 to your computer and use it in GitHub Desktop.
e-commerce-starter
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
import Stripe from 'stripe'; | |
const stripe = new Stripe( | |
'YOUR_STRIPE_SECRET_KEY', | |
); | |
export default async (req, res) => { | |
if (req.method === 'POST') { | |
try { | |
const { amount } = req.body; | |
const paymentIntent = await stripe.paymentIntents.create({ | |
amount, | |
currency: 'usd', | |
}); | |
res.status(200).send(paymentIntent.client_secret); | |
} catch (err) { | |
res.status(500).json({ statusCode: 500, message: err.message }); | |
} | |
} else { | |
res.setHeader('Allow', 'POST'); | |
res.status(405).end('Method Not Allowed'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment