#its_richard_

1 messages · Page 1 of 1 (latest)

paper jacinthBOT
rocky fractal
#

hi, I'd try some of the solutions from https://github.com/stripe/stripe-node/issues/341 , or download that exact example project from the error message and upload that directly to your server to use , and then begin adding your own logic to it

jaunty oriole
#

I don't think I can use the whole example Express project into Firebase functions but I'll solutions from this github issue

jaunty oriole
#

Nothing works here. I tired to convert req.body to string with JSON.stringify() and toString() but it doesn't work. Also I tried to use req.rawBody but then I got this error:

Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? 
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
rocky fractal
#

yeah unfortunately it's a really common and difficult problem

jaunty oriole
#

Which is kinda wierd becuase Stripe says it wants String or Buffer and req.rawBody returns Buffer

rocky fractal
#

yeah but then it's not getting the raw body, for example another middleware might have already consumed and replaced the body

jaunty oriole
#

Oh, right

rocky fractal
#

you kind of just have to keep trying things and adding extensive logging to see exactly what values you're getting

#

note that the raw string that Stripe sends will include whitespace like

{
  "object": {
    "id": "po_1NuPdvJoUivz182DKWzqPizT",
    "object": "payout",
    "amount": 28689,
...
#

so if you see something more 'compact' that's a good sign some other middleware has already JSON.stringified the incoming request(which will modify it and make the signature not match)

jaunty oriole
#

Oh wait. If that's the case then I might used JSON.stringify() wrong.

rocky fractal
#

you definitely never want to use that here

#

you need to pass the exact, raw, HTTP POST body. Parsing it into an object or with a JSON parser and then using the toString representation of that parrsed object is not the same raw body(for example it removes the whitespace)

jaunty oriole
#

I understand