Created
March 25, 2022 13:11
-
-
Save cjavilla-stripe/241682c549292bc21165744401d38793 to your computer and use it in GitHub Desktop.
Handle Stripe webhooks in Remix
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(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