【发布时间】:2020-06-20 20:35:47
【问题描述】:
我正在尝试使用 reactJS 和 expressJS 创建条带支付应用程序,但出现此错误:
代理错误:无法将请求/付款从 localhost:3000 代理到 https://localhost:5000/
请参阅https://nodejs.org/api/errors.html#errors_common_system_errors 了解更多信息(EPROTO)
在 package.json 文件中,我将代理设置为 -
"proxy": "https://localhost:5000"
在我的反应组件中我有 -
const onToken = token => {
axios({
url: "payment",
method: "post",
data: {
amount: priceForStripe,
token: token
}
})
.then(response => {
alert("succesful payment");
})
.catch(error => {
console.log("Payment Error: ", error);
alert(
"There was an issue with your payment! Please make sure you use the provided credit card."
);
});
};
在我的 server.js 中我有 -
const stripe = require("stripe")("sk_test_...");
app.post("/payment", (req, res) => {
const body = {
source: req.body.token.id,
amount: req.body.amount,
currency: "usd"
};
stripe.charges.create(body, (stripeErr, stripeRes) => {
if (stripeErr) {
res.status(500).send({ error: stripeErr });
} else {
res.status(200).send({ success: stripeRes });
}
});
});
每当我提交任何付款时都会出错 -
我尝试了所有链接here 的方法,但无法解决该问题。如果有人解释该问题的任何解决方案,我衷心感谢。
【问题讨论】:
-
您确定监听
localhost:5000的服务使用的是HTTPS吗?也许您需要http://localhost:5000而不是https://localhost:5000? -
尝试在不使用前端的情况下使用邮递员之类的东西来测试后端
-
好主意。让我测试一下@GregM
-
我也试过
http://localhost:5000@CherryDT -
@NajmunNahar 这表明错误与条纹有关,并且可能与您发送的信息有关。我认为您可能会遗漏正文中的 customer.id。这篇帖子arjunphp.com/node-stripe-express-js 将charges.create 请求的主体显示为
{ // charge the customer amount, description: "Sample Charge", currency: "usd", customer: customer.id }