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

后端 未结 9 1897
故里飘歌
故里飘歌 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 03:55

    There's now another option: you can now use the Stripe CLI to seamlessly test webhooks locally without the need for a 3rd party tool.

    In this case you would just do something like this to plumb your Stripe events through to your local webhook handler code:

    stripe listen --forward-to localhost/stripe/webhook.php
    
    0 讨论(0)
  • 2021-02-12 03:57

    Like Matt said, you will need to put that somewhere online - preferably using https://. For your reference, I put up an example mail webhook 2 months ago here: https://github.com/pnommensen/Stripe-Webhook-Emails.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-12 04:11

    How to use ngrok and set up Stripe Webhooks url

    Source Link

    1. First Download ngrok and extract it on your computer
    2. Double click ngrok.exe
    3. Try typing ngrok.exe http 80 at this terminal prompt to expose port 80

    4. For example if we you have Stripe webhooks url on localhost like so http://localhost/stripeproject/webhook.php

    5. Just specify your ngrok url as the endpoint with your webhooks service and you’re almost done.

    6. You can set up this url http://f253021b.ngrok.io/stripeproject/webhook.php to send test webhooks to your integration’s endpoint within your account’s webhooks settings.

    It's working fine for me.

    More details click here

    0 讨论(0)
  • No this won't work. Stripe servers have to be able to contact your server to send the webhook. Stripe won't know how to contact your "localhost" . You need a web accessible address or IP address for this to work

    0 讨论(0)
  • 2021-02-12 04:12

    Yes It is Possible to to test a strip web hook on local host Go to this URL https://dashboard.stripe.com/test/webhooks/ and Open your End point For i.e https://test.com/api/StripeHook and Now Open your Webhook atempt which is succeeded by strip and copy all json code.

    Now Run your project in local host and open postman and hit https://localhost/api/StripeHook and put all copied json text in body data of post man.

    0 讨论(0)
提交回复
热议问题