#spicyjungle_code
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/1425780684374413335
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐
Can you share the webhook endpoint Id ?
yes, would that be the "Destination ID"?
we_1Olg6tHMRTbnSi9asEQeqbdX
That's it if so
yes
Thanks for sharing checking...
Checking one of the events that was sent to your endpoint:
evt_1SGGJTHMRTbnSi9a6Eevs8hA
It's a timed_out error
Firstly you need to make sure that your endpoint is accessible from Stripe infrastructure
Please make sure that these IPs are allowed:
https://docs.stripe.com/ips#webhook-notifications
meaning? fwiw I do recieve the webhook events on my server, and they get processed as they should
Also make sure that your endpoint is responding immediatly with 2xx
Ah ok, then your endpoint isn't responding quickly
Yeah I respond immediately after signing, maybe I should do it before?
That's not the case then. Can you share your webhook endpoint code ?
router.post(
"/webhook",
express.raw({ type: "application/json" }),
async (req, res) => {
const sig = req.headers["stripe-signature"];
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, webhook_secret);
} catch (err) {
console.log(err.message);
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
res.status(200)
switch (event.type) {
case "checkout.session.completed":
const session = event.data.object as Stripe.Checkout.Session;
const sessionMetadata = session.metadata;
if (session.mode === "payment") {
console.log("โค๏ธ Lifetime purchased! โค๏ธ");
// db logic
}
break;
case "customer.subscription.created":
const newSubscription = event.data.object as Stripe.Subscription;
const newSubscriptionMetadata = newSubscription.metadata;
console.log("๐จ Subscription created!");
// db logic
break;
case "customer.subscription.deleted":
const deletedSubscription = event.data.object as Stripe.Subscription;
const deletedSubscriptionMetadata = deletedSubscription.metadata;
console.log("๐ Subscription ended");
// db logic
break;
default:
console.log(`Unhandled event type ${event.type}`);
return res.status(200)
}
return res.status(200)
}
);
๐ Hey, taking over here, just taking a look
I think there might be an issue with how you're setting the status here. You're doing it correctly in your try/catch block, where you call .send after setting the status, but the subsequent calls are probably not behaving as you expect. The res.status(200) call on it's own is probably redundant, and where you return res.status(200), you should use the same pattern as when you return the 400 response earlier, i.e. res.status(200).send(..
ah, .status() doesn't on its own send the response, i guess that makes sense ๐ Thank you
Exactly, so as we're not receiving any status, it's resulting in those errors
Great!