#shakilkhan496_api

1 messages ยท Page 1 of 1 (latest)

echo sundialBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1319018035276943421

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

shrewd horizon
#

Hello

#

What's the exact error you see?

tall spindle
#

Webhook error: Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the raw request body.Payload was provided as a parsed JavaScript object instead. \nSignature verification is impossible without access to the original signed material. \n\nLearn more about webhook signing and explore webhook integration examples for various frameworks at https://docs.stripe.com/webhooks/signature\n

#

I am using express js server as firebase functions

#

as express js server it is working fine but when I deploy to firebase function it is not working as expected

shrewd horizon
#

Yeah the issue is likely that you are using app.use(express.json());

#

The body has to be the raw body, it can't be manipulated.

#

Try instead doing something like:

app.use((req, res, next) => {
    if (req.originalUrl === '/webhook') {
      next(); // Do nothing with the body because I need it in a raw state.
    } else {
      express.json()(req, res, next);  // ONLY do express.json() if the received request is NOT a WebHook from Stripe.
    }
  });
tall spindle
#

checking

shrewd horizon
#

Yep that looks good to me. Try it out.

tall spindle
#

checking..

#

As express js server it is working fine , But it is actually firebase functions , and with firebase functions it was giving that error , I have updated the code let me check it

#

Again same issue with updated code

#

It is not a normal Express.js server; it is Firebase Functions as an Express.js server.

#

And it is with typescript

shrewd horizon
#

Okay well somehow the Firebase server is manipulating the request body

#

Mostly you need to figure out how to get the raw request body in your endpoint

#

So log out the request body

#

If you see binary (a buffer data type) then that is the correct raw request body

#

If you see JSON then it has been manipulated by your server and thus verification will fail

tall spindle
#

same issue again , i cannot log because it is firebase functions

shrewd horizon
#

That said, I really don't know much about Firebase

#

But the issue is that you don't have the raw body

#

Maybe try:

The Firebase SDK preserves the original wire format with a rawBody property on functions.https.Request that extends express.Request.

echo sundialBOT