Node.js 在节点js中实现条带时发生身份验证错误
我正在尝试在我的后端节点js中实现stripe。从前端调用时,我遇到以下错误:Node.js 在节点js中实现条带时发生身份验证错误,node.js,stripe-payments,Node.js,Stripe Payments,我正在尝试在我的后端节点js中实现stripe。从前端调用时,我遇到以下错误: You did not provide an API key, though you did set your Authorization header to "null". Using Bearer auth, your Authorization header should look something like \'Authorization: Bearer YOUR_SECRET_KEY\'. See htt
You did not provide an API key, though you did set your Authorization header to "null". Using Bearer auth, your Authorization header should look something like \'Authorization: Bearer YOUR_SECRET_KEY\'. See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.
这是我的密码:
const stripe = require("stripe")(process.env.keySecret);
if(req.body.type == 'stripe') {
const token = req.body.token;
const amount = req.body.amount;
let charge = stripe.charges.create({
amount: amount,
source: token,
currency: 'USD'
},(err, chargeData) => {
if(err) {
console.log('error in buy premium api error... ', err);
return;
}
let payment = [];
payment.push({
amount: chargeData.amount,
address: chargeData.billing_details.address,
email: chargeData.billing_details.email,
payment_method_details: chargeData.payment_method_details.card
})
console.log('charge... ', charge);
if(charge) {
register.findByIdAndUpdate({ _id: therapist._id },
{
$set:
{
payment_details: payment
}
}, {new:true}, (e1, updatedUser) => {
if(e1) {
return;
}
resolve(updatedUser);
})
}
})
}
else {
let err = 'No payment type define..';
return reject(err);
}
我的要求是:
{
"token": "tok_1F2XPBG04BYg8nGtLoWnQwRU", // coming from front end
"amount": "250",
"type":"stripe"
}
密钥是测试密钥,类似于sk\u test\uxxxxxxxxxx
我的前端是角度6,从前端我通过了我的测试可发布密钥,即
pk\u测试\uuxxxxxxxxxxxxxxxx
。我将适当的数据传递到前端和后端。不知道我哪里弄错了。。请帮助我解决问题。您确定process.env.keySecret
包含安全令牌(以sk_test_开头的令牌)吗?为了使其工作,您必须创建一个名为“keySecret”的环境变量。是。。它是以“sk_test_xx”开头的测试密钥,我创建了一个名为“keySecret”的环境变量Hi@JaynaTanawala,您发现这个问题了吗?我也遇到了类似的问题。@YuriyF,是的,这是关键问题。。我给错钥匙了。。