Is it possible to set localhost as a Stripe webhook URL?

后端 未结 9 1896
故里飘歌
故里飘歌 2021-02-12 03:36

I am creating a payment gateway using Stripe.

I want to set my localhost url localhost/stripe/webhook.php as my webhook url. Is it possible to set a localho

9条回答
  •  隐瞒了意图╮
    2021-02-12 04:02

    Even simpler, add this endpoint to your app when running locally (not in prod!):

    const eventsSeen = new Set();
    
    app.post("/test/simulate-stripe-webhook", async (req, res) => {
      const events = await stripe.events.list({ limit: req.query.limit || 10 });
      for (const event of events) {
        if (eventsSeen.has(event.id)) continue;
        await processStripeEvent(event);
        eventsSeen.add(event.id);
      }
      return res.status(200).end();
    });
    
    

    ...where processStripeEvent is whatever logic your webhook triggers.

    Then there's no need to manage webhooks in stripe.

提交回复
热议问题