I am migrating from Express to serverless functions on Zeit Now.
The Stripe webhook docs asks for a raw body request, When using Express I could get it via bodyParser, but how does it work on serverless functions? How can I receive the body in a string format in order to validate the stripe signature?
The support team redirected me to this documentation link, I'm confused, as I understand, I have to pass text/plain
into the request header, but I don't have control over it since Stripe is the one sending the webhook.
export default async (req, res) => {
let sig = req.headers["stripe-signature"];
let rawBody = req.body;
let event = stripe.webhooks.constructEvent(rawBody, sig, process.env.STRIPE_SIGNING_SECRET);
...
}
In my function, I'm receiving req.body
as an object, how can I fix this issue?