#spicyjungle_code

1 messages ยท Page 1 of 1 (latest)

patent acornBOT
#

๐Ÿ‘‹ 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.

white scarab
keen yew
#

๐Ÿ‘‹
Can you share the webhook endpoint Id ?

white scarab
#

yes, would that be the "Destination ID"?

#

we_1Olg6tHMRTbnSi9asEQeqbdX

#

That's it if so

keen yew
#

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

white scarab
keen yew
#

Also make sure that your endpoint is responding immediatly with 2xx

keen yew
white scarab
#

Yeah I respond immediately after signing, maybe I should do it before?

keen yew
#

That's not the case then. Can you share your webhook endpoint code ?

white scarab
#
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)

  }
);
patent acornBOT
inner ledge
#

๐Ÿ‘‹ 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(..

white scarab
#

ah, .status() doesn't on its own send the response, i guess that makes sense ๐Ÿ˜‚ Thank you

inner ledge
#

Exactly, so as we're not receiving any status, it's resulting in those errors

white scarab
#

One second i'll check if it works now

#

all good ๐Ÿ‘ Thanks!

inner ledge
#

Great!