Reputation: 135
I only need to do a get request with this webhook. Stripe is indeed sending information to the webhook i just cant figure out how to retrieve the information in Node.JS. I know i need to setup a webhook listener to watch for requests however i cannot find any good useful tutorials. I am currently using hook.io as my webhook vendor. Does anyone have any ideas on how to do this?
Upvotes: 1
Views: 2144
Reputation: 135
Sorry for posting this answer late, I figured this out awhile ago. If you visit this link and follow it step by step it worked like a charm for me. Just create a new PHP file on your webserver copy and paste the code and make the changes necessary to fit your needs.
https://stripe.com/docs/webhooks/integration-builder
Upvotes: 0
Reputation: 8737
You can find an Express-based example here: https://github.com/stripe/stripe-node/tree/master/examples/webhook-signing/node-express
Upvotes: 0
Reputation: 411
First thing first (I'm a bit of a purist) Node.js is not a language but a runtime environment. So I'll assume that you're using Express.js as your web framework.
Then you'll have to Add an endpoint, select the appropriates events, and you'll be good to go. Stripe will POST events to your endpoint. You'll be then able to parse the body of the request to handle them.
Edit : domain won't be ngrok.io but something like mysubdomain.ngrok.io
then on your app.js (or any router)
app.post('/my-endpoint', (req, res, next) => {
// Do whatever you want with req.body
// Fetching a database, send a email to customer...
res.sendStatus(200)
// ALWAYS answer 2XX to Stripe otherwise it'll be considered as failed on Stripe's end.
})
If you're new to webhook, I highly suggest you to download Stripe CLI, and use Ngrok to test webhooks locally before going live. I'm currently writing a dev.to post about Stripe's webhooks, I'll post it once done.
Upvotes: 1