【问题标题】:Polymer POST http://localhost:3000/ 404 (Not Found)聚合物 POST http://localhost:3000/ 404(未找到)
【发布时间】:2015-11-04 16:50:48
【问题描述】:

我正在尝试使用 node.js 为 Stripe 创建费用。所以我关注了Firebase method,看看我能不能让它工作:

为清楚起见,我省略了聚合物元素的导入。假设一切正常。

/charge.html:

<dom-module id="stripe-charge">
  <template>
    <script>
      var firebaseStripe = new Firebase('https://blahblah.firebaseio-demo.com/');

        firebaseStripe.set({
          var stripe = require("stripe")("sk_test_blahblah");
          var stripeToken = request.body.stripeToken;

          var charge = stripe.charges.create({
            amount: 1000, // amount in cents, again
            currency: "gbp",
            source: stripeToken,
            description: "Example charge"
          }, function(err, charge) {
            if (err && err.type === 'StripeCardError') {
              // The card has been declined
            }
        });
    </script>
  </template>
  <script>
    Polymer({
      is: 'stripe-charge',
    });
  </script>
</dom-module>

索引:

<section data-route="charge">
 <stripe-charge></stripe-charge>
</section>

routing.html:

page('/charge', function () {
  app.route = 'charge';
});

page({
  hashbang: true
});

表格:

<form is="iron-form" id="myForm" action="http://localhost:3000/#!/charge" method="post">
   <input type="hidden" is="iron-input" id="amount" name="amount" bind-value="{{total}}">
   <input type="hidden" id="stripeToken" name="stripeToken"/>
   <input type="hidden" is="iron-input" id="stripeEmail" name="stripeEmail" bind-value="{{emailInput}}"/>
</form>
<paper-button class="fullBtn" id="customButton" on-click="stripe">
  <iron-icon icon="icons:credit-card"></iron-icon>
  Pay
</paper-button>

当我按下支付按钮,填写卡详细信息等,然后点击剥离支付按钮时,我得到绿色但当它进入收费页面时,我得到 POST http://localhost:3000/ 404 (Not Found) 不知何故它没有进入页面。有任何想法吗?我觉得会有更多的错误,但现在,我想得到那个页面。 Firebase 问题?

【问题讨论】:

  • 不确定在任何宇宙中 localhost:3000 上的 404 可能是 Firebase 问题。几乎可以肯定 Stripe 的重定向 URL 不正确。
  • 这就是我问这个问题的原因。
  • 首先将问题集减少到minimum viable code that reproduces the error。例如,如果您删除 Firebase 代码并直接发送 Stripe 请求,您可能会遇到相同的情况。

标签: firebase polymer stripe-payments polymer-1.0


【解决方案1】:

将您的网址更改为真实路径,而不是哈希位置:

<form is="iron-form" id="myForm" action="http://localhost:3000/charge" method="post">

您需要运行一个接受帖子的服务器,然后使用您的私钥调用 Stripe,您不能将 Stripe 作为纯客户端进程运行。

浏览器中的第一步调用 stripe 并打包提供的信用卡信息,但随后您需要将该令牌提供给您的服务器。否则任何人都可以代表您提交费用,包括退款!

【讨论】:

  • 浏览器 URL 现在转到http://localhost:3000/charge,页面显示Cannot POST /charge
  • 你需要有一个服务器运行,将发布到条带
猜你喜欢
  • 2016-08-06
  • 2021-10-31
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-19
  • 2022-09-28
相关资源
最近更新 更多