'Stripe webhooks - checking request from Stripe
I want to check if request on my endpoint is from Stripe. I can do this, I can check this but the problem is - my code after try catch blocks is not triggering.
Even if I write all this console logs in try block AFTER I assing response from Promise to event variable. All of my code AFTER event = await stripe.webhooks.constructEvent(payload, sig, endpointSecret); is not working. Also I dont have any errors...
I want to send response 200 and continue with more complicated code on server but it stops working after checking req from stripe.
pixelRouter.post("/payments", async (req, res) => {
//Checking if request is from STRIPE
const payload = req.body;
const sig = req.headers["stripe-signature"];
const endpointSecret =
"my secret endpoint here";
let event;
try {
event = await stripe.webhooks.constructEvent(payload, sig, endpointSecret);
} catch (err) {
return res.status(400).send(`Webhook Error: ${err.message}`);
console.log(err.message);
}
//********************************* */
switch (event.type) {
case "checkout.session.completed":
console.log("Code for checkout session completed");
break;
case "payment_intent.succeeded":
console.log("Payment succeeeded");
break;
default:
console.log("???");
}
console.log("ndkndnn");
res.json({ success: true });
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
