Last active
January 15, 2023 23:45
-
-
Save dipeshhkc/38a0ec14c327b4ceec48289299a3887e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 type { ActionFunction } from '@remix-run/node'; | |
import { json } from '@remix-run/node'; | |
import { stripe } from '~/stripe.server'; | |
import { handleStripeEvent } from '~/routes/webhook.server'; | |
//[credit @kiliman to get this webhook working](https://github.com/remix-run/remix/discussions/1978) | |
export const action: ActionFunction = async ({ request }) => { | |
const payload = await request.text(); | |
const sig = request.headers.get('stripe-signature')!; | |
try { | |
const { type, data, id } = stripe.webhooks.constructEvent( | |
payload, | |
sig, | |
process.env.STRIPE_WEBHOOK_ENDPOINT_SECRET! | |
); | |
handleStripeEvent(type, data, id); | |
} catch (err: any) { | |
throw json({ errors: [{ message: err.message }] }, 400); | |
} | |
return new Response(null, { status: 200 }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment