Skip to content

Instantly share code, notes, and snippets.

@AlbionaHoti
Created October 21, 2020 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbionaHoti/757544d7953962842bfac5a50f9a6010 to your computer and use it in GitHub Desktop.
Save AlbionaHoti/757544d7953962842bfac5a50f9a6010 to your computer and use it in GitHub Desktop.
e-commerce-starter
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