Ios 条带:502(坏网关)

Ios 条带:502(坏网关),ios,node.js,express,stripe-payments,payment,Ios,Node.js,Express,Stripe Payments,Payment,我收到一个带条带的502(坏网关)错误。付款成功地向卡收费并显示在Stripe仪表板上,但它在前端没有显示成功,而是显示502错误 我想在下面添加一些东西,使前端显示付款成功吗?使用此处的文档: 服务器端代码 app.post('/apple-pay', function(req, res, next) { // Set your secret key: remember to change this to your live secret key in production var str

我收到一个带条带的502(坏网关)错误。付款成功地向卡收费并显示在Stripe仪表板上,但它在前端没有显示成功,而是显示502错误

我想在下面添加一些东西,使前端显示付款成功吗?使用此处的文档:

服务器端代码

app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
 var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
  amount: 499,
  currency: 'usd',
  description: 'Example charge',
  source: token,
}, function(err, charge) {
  // asynchronously called
  console.log(err)
});
});

正如注释中所讨论的,问题在于请求服务器端不返回任何状态代码,因此客户端代码不知道它成功了

问题可能来自代码服务器端,而您尚未共享它。您需要向代码中添加日志,以跟踪返回的值exactly@koopajah补充说,但你之前有另一个问题,你说指控无效。您是否将日志添加到您读取并能够调试的代码中?例如,现在您的代码以异步方式创建费用,并且从不返回任何内容、无响应、无200等。您需要处理请求properly@koopajah对我设法解决了这个问题。现在付款成功完成。我可以在仪表板上看到它。然而,在前端,它看起来并没有完成…太棒了!我在上面解释了要寻找什么。您需要确保代码等待费用创建完成,然后才返回值。您可能想了解Node.js、异步流、如何处理服务器上的请求等。
app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
 var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
  amount: 499,
  currency: 'usd',
  description: 'Example charge',
  source: token,
}, function(err, charge) {
  // asynchronously called
  console.log(err)
});
});