[英]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)
});
});
如評論中所述,問題在於請求服務器端不返回任何狀態代碼,因此客戶端代碼不知道它成功!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.