#maka_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ 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/1229532200245006369
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
this is my webhook:
webhook: async (req, res) => {
const sig = req.headers['stripe-signature'];
console.log(req.body)
let event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_WEBHOOK_SECRET_KEY);
} catch (err) {
console.log(`hookError: webhook ${err}`)
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
let {metadata, created} = event.data.object,
Business = require('../../classes/dmv/Business'),
{ioHandler} = require('../../app');
// socketId = businessRooms.get(metadata.businessId);
await Business.incrementCredit(metadata.businessId, metadata.amount)
const businessCredit = await Business.getBusinessCredit(metadata.businessId)
ioHandler.emitToRoom(
'payment_intent.succeeded',
metadata.businessId,
{
amount: metadata.amount,
businessCredit
}
)
// io.sockets.on('payment_intent.succeeded', data => {debugger
// io.to(socketId).emit('test', 'from server')
// })
//update transaction table and return it
// return res.json(handleDataToReturn({
// businessCredit,
// amount: metadata.amount
// }))
break;
default:
console.log(`Unhandled event type ${event.type}`);
}
Can you tell me more about the error that you are getting? Is your server throwing an error at some point?
no server error at all
this from stripe:
Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
I actually see your server responding with our error about signature verification failing
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing```
yes thats it but: it work good on dev
Though I do see that your other servers are processing the event correctly. If your servers all use the same code, you should double check that the key you are using for that server is the correct one for that webhook endpoint
Each endpoint has its own secret, so the signature we sent to each endpoint is different
Also dev vs prod will have different secrets, even if you point both at the same URL
correct
i checked and im using the correct ones
And this is the same code as is on your other servers?
yes i just push from local and pull from live
im using google cloud virtual machine, Does this matters?
i ckeck now and even im getting: req.body as a buffer and const sig = req.headers['stripe-signature'] as t=1713214394,v1=a8b4afad4283dc19f37b6296d795ee2f9f285aaaf57155b38979626305f034d2,v0=deaf3ef6.......................................................da4b45 80b2a2285fa
in the live server
Hi there, stepping in for my teammate
sure thanks
As my teammate said, I recommend double checking your code between your test and live environments as there's clearly something that's not the same. I don't expect the Google Cloud virtual machine to make a difference here unless the raw request body is being handled differently because of it
in the server im using the key giving to me in, Signing secret -> Reveal
I think it's common for devs to run into issues with Express and parsing a request body. Do any of the suggestions mentioned here work? https://github.com/stripe/stripe-node/issues/341