Setup Stripe webhook

hi

I like to move my stripe-webhook to mongodb. Currently I have a nodejs server where I can get the raw body from the request like (because stripe needs the raw request body)

app.post(’/webhook’, bodyParser.raw({ type: ‘application/json’ }), (request, response)

Is it possible to get the raw body request somehow in a mongodb webhook?

thx

Do these docs help - https://docs.mongodb.com/realm/functions/json-and-bson/ ?
Sounds like you may want to use one of the parse functions.

hm sadly not. Non of them were successfully.

the raw body on my nodejs application was like:

<Buffer 7b 0a 20 20 22 63 72 65 61 74 65 64 22 3a 20 31 33 32 36 38 35 33 34 37 38 2c 0a 20 20 22…

and stripe error is like:

“Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing

Hi @rouuuge.

For some general examples of working with Stripe from Realm. you could take a look at this eCommerce app that I built a while back: https://github.com/mongodb-appeng/eCommerce-Realm For example, this function creates a Stripe checkout session: https://github.com/mongodb-appeng/eCommerce-Realm/blob/main/functions/stripeCreateCheckoutSession/source.js

The frontend (Vue.js) app is here: https://github.com/mongodb-appeng/eCommerce

2 Likes

hi andrew, thx for the example! Good to know that at least the stripe api seems to work! But for me its not really a option, because I use the UI-Forms directly from Stripe directly: https://stripe.com/docs/payments/checkout

to get data into mongodb I need their webhook. Of course I could run a own nodejs server like now. But I would like ot move as much code as possible to the same place.