2014-11-06 32 views
0

我已經嵌入條紋結帳在一個名爲payment.ejs不能發佈/支付(Node.js和受條紋)

<form action="" method="POST"> 
    <script 
    src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
    data-key="pk_test_ODW7OJfVhlRJEgFY0ppWzwEE" 
    data-amount="2000" 
    data-name="Demo Site" 
    data-description="2 widgets ($20.00)" 
    data-image="/128x128.png"> 
    </script> 
</form> 

我訪問該頁面,並在被接受信用卡進入。不過,我當時得到的錯誤

不能發佈/支付

我app.js

我有

app.post('payment', function(req, res){ 
    //stripe 
     console.log('posted') 

    var stripeToken = req.body.stripeToken; 
    var charge = stripe.charges.create({ 
     amount: 1000, // amount in cents, again 
     currency: "usd", 
     card: stripeToken, 
     description: "[email protected]" 
    }, function(err, charge) { 
     if (err && err.type === 'StripeCardError') { 
     console.log("CARD DECLINED"); 
     res.send('error') 
     } 
     else { 
      console.log("CARD ACCEPTED"); 
      res.send('ok') 

     } 
    }); 
}); 

按照說明進行操作。我看不出這裏有什麼問題。有任何想法嗎?

回答

2

路線應包括前述/

app.post('/payment', function (req, res) { 
    // ^

    // ... 
}); 

ExpressJS」路由部分地基於匹配requested url,其中包括從‘根’(主機名和端口之後)每/path。另一部分是method

app.use(function (req, res, next) { 
    console.log(req.method); // "POST" 
    console.log(req.path); // "/payment" 
          //^
    next(); 
}); 

注:無論是尾隨/或缺乏,需要匹配取決於是否strict routingRouterstrict option啓用。

啓用嚴格路由,默認情況下,路由器對「/ foo」和「/ foo /」進行相同處理。