条带:502(错误网关)
Stripe: 502 (Bad Gateway)
我收到 Stripe 的 502(错误网关)错误。付款成功地从卡中扣款并显示在 Stripe 仪表板中,但它没有在前端显示成功,而是我收到 502 错误。
我是否应该在下面添加一些东西让前端显示支付成功?在此处使用文档:
https://stripe.com/docs/stripe-js/elements/payment-request-button
// Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})
.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});
服务器端代码
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)
});
});
如评论中所述,问题是请求服务器端没有 return 任何状态代码,因此客户端代码不知道它已成功!
我收到 Stripe 的 502(错误网关)错误。付款成功地从卡中扣款并显示在 Stripe 仪表板中,但它没有在前端显示成功,而是我收到 502 错误。
我是否应该在下面添加一些东西让前端显示支付成功?在此处使用文档: https://stripe.com/docs/stripe-js/elements/payment-request-button
// Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})
.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});
服务器端代码
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)
});
});
如评论中所述,问题是请求服务器端没有 return 任何状态代码,因此客户端代码不知道它已成功!