How to use the stripe.webhooks function in stripe

To help you get started, we’ve selected a few stripe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rangle / stripe-eventbridge / handler.js View on Github external
module.exports.stripeWebhook = async event => {
  let err = null
  try 
  {
    const signature = event.headers["Stripe-Signature"]
    const secret = (await client.fetchSecret({ SecretId: secretName })).SecretString
    const eventReceived = stripe.webhooks.constructEvent(event.body, signature, secret)
    await eventbridge.sendToEventBridge(process.env.EVENT_BRIDGE, eventReceived)
  } 
  catch (e) 
  {
    err = e
    await sns.notifyFailure(e.message)
  }
  const body = err ? JSON.stringify(err) : ""
  const statusCode = err ? 500 : 200
  return { statusCode, body }
};