gpt4 book ai didi

ios - Stripe : 502 (Bad Gateway)

转载 作者:行者123 更新时间:2023-11-28 23:41:49 25 4
gpt4 key购买 nike

我在使用 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)
});
});

最佳答案

正如评论中所讨论的,问题是请求服务器端不返回任何状态代码,因此客户端代码不知道它已成功!

关于ios - Stripe : 502 (Bad Gateway),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53200929/

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