简体   繁体   English

尝试使用带条带的 webhook 将数据发送到 Node.JS 应用程序

[英]Trying to use a webhook with stripe to send data into a Node.JS application

I only need to do a get request with this webhook.我只需要使用这个 webhook 做一个 get 请求。 Stripe is indeed sending information to the webhook i just cant figure out how to retrieve the information in Node.JS. Stripe 确实在向 webhook 发送信息,我只是不知道如何在 Node.JS 中检索信息。 I know i need to setup a webhook listener to watch for requests however i cannot find any good useful tutorials.我知道我需要设置一个 webhook 侦听器来监视请求,但是我找不到任何有用的教程。 I am currently using hook.io as my webhook vendor.我目前使用 hook.io 作为我的 webhook 供应商。 Does anyone have any ideas on how to do this?有没有人对如何做到这一点有任何想法?

First thing first (I'm a bit of a purist) Node.js is not a language but a runtime environment.首先(我有点纯粹主义者)Node.js 不是一种语言,而是一种运行时环境。 So I'll assume that you're using Express.js as your web framework.所以我假设您使用 Express.js 作为您的 Web 框架。

条纹仪表板

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编辑:域不会是 ngrok.io,而是类似于 mysubdomain.ngrok.io

then on your app.js (or any router)然后在您的 app.js(或任何路由器)上


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.如果您不熟悉 webhook,我强烈建议您下载Stripe CLI ,并在上线之前使用Ngrok在本地测试 webhook。 I'm currently writing a dev.to post about Stripe's webhooks, I'll post it once done.我目前正在写一篇关于 Stripe 的 webhooks 的开发文章,我会在完成后发布。

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.只需在您的网络服务器上创建一个新的 PHP 文件,复制并粘贴代码并进行必要的更改以满足您的需求。

https://stripe.com/docs/webhooks/integration-builder https://stripe.com/docs/webhooks/integration-builder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM