Skip to content

Instantly share code, notes, and snippets.

@AlbionaHoti
Created October 11, 2020 22:37
Show Gist options
  • Save AlbionaHoti/f3a8fb683ca6f0adbae83361a77db6e0 to your computer and use it in GitHub Desktop.
Save AlbionaHoti/f3a8fb683ca6f0adbae83361a77db6e0 to your computer and use it in GitHub Desktop.
webiny-starter-e-commerce-nextjs-stripe
import Stripe from 'stripe'
const stripe = new Stripe(
'STRIPE_SECRET_KEY_HERE'
)
export default async (req, res) => {
if (req.method === 'POST') {
try {
const { amount, paymentIntentId } = JSON.parse(req.body)
const updatedPaymentIntent = await stripe.paymentIntents.update(
paymentIntentId,
{ amount }
)
res.status(200).json({ updatedPaymentIntent })
} 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