#gan_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/1283746152033816649
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
What does your webhook code look like?
hi, Hope you having a do day
can i share the screen?
Not here I'm afraid
sure let me share it to you
//router.js
router.post('/webhook',express.raw({ type:'application/json' }), paymentUpdation);
Where are you getting your whsec_xxx from?
wait i send you the controller wait ahh
const paymentUpdation = async (req, res) => {
try {
const sig = req.headers['stripe-signature'];
let event;
const storeId = req.body.data.object.metadata.storeId;
let stripeKey = "";
const store = await Store.findOne({ _id: storeId, isDeleted: 0 });
if (!store) {
return res
.status(400)
.send({ message: "Store not found", success: false });
}
if (
store.generalSettings &&
store.generalSettings.Integrations &&
store.generalSettings.Integrations.enableStripe === true
) {
stripeKey = store.generalSettings.Integrations.stripeSecretKey;
} else {
return res.status(400).send({
message:
"Stripe secret key not found or Stripe integration not enabled for the store",
success: false,
});
}
const stripe = Stripe(stripeKey);
const endpointSecret = store.generalSettings.Integrations.stripeEndPointKey;
try {
// Verify the signature of the event
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
} catch (err) {
console.error('Webhook signature verification failed.', err.message);
return res.status(400).send(`Webhook Error: ${err.message}`);
}
dynamically from DB
Right, but where did you get that value? Is it the correct secret for the webhook from the Dashboard?
yes from dashboard
Can you share the last 4 digits?
jbda
Are you using any other middleware (app.use()) in your Express app?
yes
Can you share the details
app.use("/v1/api/online/payment",onlinePaymentRoutes);
app.use(express.json({ limit: "4mb" }));
both on Index.js
Yeah I suspect that global middleware is the issue
It'll be malforming the event payload which will break the constructEvent method
anyother possibilites?
Can you try and remove that global middleware? Or at least refactor your code to it doesn't apply to your webhook route