Skip to content

Instantly share code, notes, and snippets.

@cjavilla-stripe
Created March 25, 2022 13:11
Show Gist options
  • Save cjavilla-stripe/241682c549292bc21165744401d38793 to your computer and use it in GitHub Desktop.
Save cjavilla-stripe/241682c549292bc21165744401d38793 to your computer and use it in GitHub Desktop.
Handle Stripe webhooks in Remix
import Stripe from 'stripe'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)
export const action = async ({request}) => {
const secret = 'whsec_...' // process.env.WEBHOOK_SIGNING_SECRET
const sig = request.headers.get('stripe-signature')
let event;
const payload = await request.text()
try {
event = stripe.webhooks.constructEvent(payload, sig, secret)
} catch(err) {
return new Response(err.message, {
status: 400,
})
}
if(event.type == 'payment_intent.succeeded') {
const paymentIntent = event.data.object;
console.log("💰 payment success!")
}
return {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment