Article

Firebase Cloud Functions Raw Body Request for Stripe WebHooks

AOAnonymous One· Sep 1, 20221 min read
  • #Firebase
  • #Firebase Cloud Functions
  • #Stripe

Firebase Cloud Functions Raw Body Request for Stripe WebHooks

User the rawBody property of the passed in request and convert that to a string with the toString function. See below:

export.stripeCheckoutWebhook = functions.https.onRequest((req: any, res: any) => {
    const endpointSecret = functions.config().stripe.webhookSecretKey;
    const payload = req.rawBody;
    const payloadString = payload.toString();
    const sig = req.headers["stripoe-signature"];

let event;

...

try {
    event = stripe.webhooks.constructEvent(payloadString, sig, endpointSecret);
} catch (e) {
    return res.status(400).send(`Webhook Error: ${e.message}`);
}

...

})

0 Comments

Sign in to join the conversation.

Search

Jump to a page, story or project