#teevee_14010

1 messages · Page 1 of 1 (latest)

tropic harborBOT
edgy plover
#

You should check your server logs to determine what causes the 400 errors.

gaunt kite
#

sometimes it says no payload other times it just says 400

edgy plover
#

Do you have an event ID that I can take a look?

gaunt kite
#

I believe this is an event ID

req_S8qTXcjsTnU7Qg

edgy plover
#

I just checked the webhook endpoint that you hosted in smee.io, and I don't see any recent errors

gaunt kite
#

Correct, but on my server it cannot receive/process the payload

edgy plover
#

What's the error?

gaunt kite
#

Is there something wrong with server code for receiving the payload:

returning a 400 error code. This is my endpoint code:

router.post('/webhook', bodyParser.raw({ type: 'application/json' }), async (req, res) => {
const sig = req.headers['stripe-signature'];

let event;

try {
const buf = Buffer.from(req.body);
event = stripe.webhooks.constructEvent(buf, sig, endpointSecret);
} catch (err) {
return res.status(400).send(Webhook Error: ${err.message});
}

edgy plover
#

But based on what I saw in your Dashboard, your server is returning 200, which means your server is processing the webhook events successfully

gaunt kite
tropic harborBOT
gaunt kite
#

I think its something wrong with the way the server is parsing the body of the payload.

#

This is a previous a server log message:

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.
Signature verification is impossible without access to the original signed material.

Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing

POST http://localhost:3000/webhook - 400

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

hot dagger
#

The webhook secrets on the local server and the one in Dashboard are different. Can you ensure that you use the correct Webhook secret?

gaunt kite
#

And it is connected and working properly. I am not using CLI with this endpoint.

hot dagger
#

This is a public channel and sensitive information such as webhook secret shouldn't be shared. I've removed the screenshot above.

#

Does your node middleware configure parse all the requests to JSON somewhere? For example,

app.use(express.json());
gaunt kite
#

Yes in my server.js file

hot dagger
#

If you have this, it'll parse the requests in all JSON, not in raw form before reaching to your webhook function

#

Can you remove it can and see if it solves the problem?

gaunt kite
#

I removed the code and ran another transaction. I still got a 400 error in my server log

#

this was response:

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

POST http://localhost:3000/webhook - 400

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

edgy plover
#

Are you using the webhook secret generated by the stripe listen command?

gaunt kite
#

I am using the webhook secret from the webhook dashboard

edgy plover
#

No. If you running the webhook locally, you should use the secret generated from Stripe CLI

gaunt kite
#

Ok thank you, where is that located? Also I am using smee.io so the webhook payloads are being forwarded from the smee address to my local server at the endpoint localhost:3000/webhook

gaunt kite
#

Did i lose you?

edgy plover
#

Thanks for waiting. discord is busy today

#

If you are not using Stripe CLI, then you should use the webhook secret from your Dashboard

gaunt kite
#

When I use the webhook secret and run a transaction this is what my server log returns:

Webhook Error: No webhook payload was provided.
POST http://localhost:3000/webhook - 400

edgy plover
#

Wha'ts the webhook event ID?

gaunt kite
#

evt_3Obdy7KqO403i8Jl1aYQL0fz
There is something wrong with how the raw request body is being handled by my server code but I cant figure out what.

edgy plover
#

Your endpoint responded with 200

gaunt kite
#

Stripe is sending the code and my server is receiving it but its not able to convert the payload

edgy plover
#

What do you mean by "not able to convert the payload" ?

gaunt kite
#

the body of the json file being sent in the webhook is not being read by my server.

edgy plover
#

Do you see any errors in server log?

gaunt kite
#

Yes

edgy plover
#

Hmm, can you do a console.log(req.body) and see what it prints out?

gaunt kite
#

Yes this is what the console printed:

<Buffer 7b 22 69 64 22 3a 22 65 76 74 5f 33 4f 62 65 44 50 4b 71 4f 34 30 33 69 38 4a 6c 30 48 77 70 42 79 4f 50 22 2c 22 6f 62 6a 65 63 74 22 3a 22 65 76 65 ... 1309 more bytes>
Webhook Error: No webhook payload was provided.
POST http://localhost:3000/webhook - 400

edgy plover
#

That's very strange

#

This is going to require a bit more investigation. Sorry to redirect you, but can you write in to https://support.stripe.com/contact/email with a test proejct that we can run and reprouce the problem? We'll respond via email/ticket after looking into it further.

gaunt kite
#

Sure thank you for your time, this is a great service/feature.