【问题标题】:Stripe payments not going through with React JS条纹支付不通过 React JS
【发布时间】:2018-09-24 02:16:07
【问题描述】:

我在本地主机上使用 Stripe,一切运行良好,但是当我尝试切换所有密钥以在 Netlify 上运行和运行时,付款似乎没有通过。它仅在条带仪表板中显示为日志。

这似乎是我遇到问题的以下代码块。

fetch('/stripe-charge', {
          method: 'POST',
          body: JSON.stringify(bodyObject)
        })

如果我将上面的条带地址更改为http://localhost:9000/stripe-charge,则一切正常。我只是没有正确定位文件夹吗?

文件夹结构:

main site folder
    - src
        - components
        - layouts
        - pages
        - images
    - functions
        - stripe-charge.js

【问题讨论】:

  • /stripe-charge 是您支持的服务的终点。这不是您拥有的文件夹名称。您的后端服务在本地主机 9000 端口上运行,并且您的 Api 路径是 /stripe-charge,因此在进行 fetch 时,您需要指定绝对路径,如 localhost:9000/stripe-charge 才能正常工作。我猜你到目前为止所理解的并不正确

标签: reactjs stripe-payments


【解决方案1】:

正如@Think-Twice 所提到的,/stripe-charge 应该提供服务器端 API 端点而不是文件名。

你可以做什么来为stripe-charge.js服务express.js [0]

 const express = require('express')
  const app = express()
  const port = 3000
  app.post('/stripe-charge', (req, res) => {
    // Move y=your stripe-charge.js logic 
  })
  app.listen(port, () => console.log(Example app listening on port ${port}!))

然后按照Netlify docs 进行部署[1]

[0]http://expressjs.com/en/starter/hello-world.html

[1]https://www.netlify.com/docs/

【讨论】:

    猜你喜欢
    • 2017-09-14
    • 2021-08-02
    • 2020-12-30
    • 2015-05-25
    • 2021-11-19
    • 2021-10-08
    • 2016-08-02
    • 2020-03-06
    • 2018-08-20
    相关资源
    最近更新 更多