Skip to content

Instantly share code, notes, and snippets.

@yurist38
Created August 1, 2020 20:38
Show Gist options
  • Save yurist38/7d53e82bb489b52dd743ba1107941c81 to your computer and use it in GitHub Desktop.
Save yurist38/7d53e82bb489b52dd743ba1107941c81 to your computer and use it in GitHub Desktop.
const { stripe_secret_key, stripe_webhook_secret } = privateConfig;
const stripe = new Stripe(stripe_secret_key);
let event: events.IEvent | undefined;
try {
const sig = req.headers['stripe-signature'] as string;
const reqBody = req.rawBody.toString();
event = stripe.webhooks.constructEvent(reqBody, sig, stripe_webhook_secret);
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment