#ColonelBudinca
1 messages ยท Page 1 of 1 (latest)
๐ happy to help
hi
I am hosting a netlify function for the stripe webhook so i can not use express to get the raw body necesary for stripeAPI.webhooks.constructEvent
Before that i was using express server and it worked but i had to give up the server because it was hosted on heroku that now in not free anymore
instead of using body, you need to use rawBody
no I meant in the request deconstructor
({ path, httpMethod, headers, queryStringParameters, rawBody }) {
you also need the response parameter
i had it but i was not using that so i removed it
so your code should be like
exports.handler = async function ({ path, httpMethod, headers, queryStringParameters, rawBody }, res) {
it's necessary to respond back with a status 200 so Stripe would know that you properly received the webhook event and wouldn't try to resend it to you later
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
},
body: JSON.stringify({
path,
httpMethod,
queryStringParameters,
headers,
body: JSON.stringify({ message: "YES" }),
}),
};
like this?
i got the same error using the rawBody
it is always 200 but i am getting that error because of the rawbody
I'm taking a look
OK. i see the problem . i can not do this {rawBody} = event
i tried to send the rawbody to see if it exists and it doesnt
} catch(error){
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
},
body: JSON.stringify({
path,
httpMethod,
queryStringParameters,
headers,
// something: JSON.stringify(body),
rawBody : rawBody,
body: JSON.stringify({error: `webhook error ${error.message}` }),
}),
};
I need to get the rawBody in other way than destructuring it from the event
I'm not familiar with netlify but looking into their docs
thank you
please give me a moment
I found this
https://dev.to/stripe/building-an-ecommerce-store-33-webhook-endpoints-and-fulfillment-260j
would you mind taking a quick look?