gpt4 book ai didi

javascript - 无法 POST/付款(Node.js 和 Stripe)

转载 作者:行者123 更新时间:2023-12-02 16:49:42 26 4
gpt4 key购买 nike

我已在名为 payment.ejs 的文件中嵌入了 stripes checkout

<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>

我访问该页面并输入一张被接受的信用卡。但是,我收到错误

Cannot POST /payment

在我的 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: "payinguser@example.com"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
console.log("CARD DECLINED");
res.send('error')
}
else {
console.log("CARD ACCEPTED");
res.send('ok')

}
});
});

按照说明。我不明白这里有什么问题。有任何想法吗?

最佳答案

路线应包含前面的/:

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

// ...
});

ExpressJS 的路由部分基于匹配 path requested url的,其中包括来自“root”(主机名和端口之后)的每个 /。另一部分是method .

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

注意:是否需要尾随 / 或缺少来匹配取决于是否 strict routing路由器strict option已启用。

Enable strict routing, by default "/foo" and "/foo/" are treated the same by the router.

关于javascript - 无法 POST/付款(Node.js 和 Stripe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26788525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com