【发布时间】:2022-01-26 08:57:29
【问题描述】:
当我尝试执行此操作时,我的数据已成功存储在 数据库,但不幸的是,当它带有条带 api 时,它给出了一个错误 我在下面提到的似乎是我不知道的参数丢失错误。谁能告诉我哪里错了
//创建支付的方法
exports.createpayment=async (req,res)=>{
const payment= await paymentdata.create(req.body)
stripe.customers.create({
source: req.body.stripeToken,
fullname: req.body.fullname,
address: req.body.fullname
})
.then((customer) => {
return stripe.charges.create({
amount: req.body.amount, // Charing Rs 25
currency: 'INR',
customer: fullname
});
})
.then((charge) => {
res.send("Success") // If no error occurs
})
.catch((err) => {
res.send(err) // If some error occurs
});
}
//运行条带Api时出错
"type": "StripeInvalidRequestError",
"raw": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: fullname",
"param": "fullname",
"type": "invalid_request_error",
"headers": {
"server": "nginx",
"date": "Mon, 27 Dec 2021 11:04:48 GMT",
"content-type": "application/json",
"content-length": "242",
"connection": "keep-alive",
"access-control-allow-credentials": "true",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS, DELETE",
"access-control-allow-origin": "*",
"access-control-expose-headers": "Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required",
"access-control-max-age": "300",
"cache-control": "no-cache, no-store",
"idempotency-key": "30b9c551-4596-4b35-ad09-abc6dfbb3d58",
"original-request": "req_dcy6NACGsy6EJP",
"request-id": "req_dcy6NACGsy6EJP",
"stripe-version": "2020-08-27",
"strict-transport-security": "max-age=31556926; includeSubDomains; preload"
},
"statusCode": 400,
"requestId": "req_dcy6NACGsy6EJP"
},
"rawType": "invalid_request_error",
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"param": "fullname",
"headers": {
"server": "nginx",
"date": "Mon, 27 Dec 2021 11:04:48 GMT",
"content-type": "application/json",
"content-length": "242",
"connection": "keep-alive",
"access-control-allow-credentials": "true",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS, DELETE",
"access-control-allow-origin": "*",
"access-control-expose-headers": "Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required",
"access-control-max-age": "300",
"cache-control": "no-cache, no-store",
"idempotency-key": "30b9c551-4596-4b35-ad09-abc6dfbb3d58",
"original-request": "req_dcy6NACGsy6EJP",
"request-id": "req_dcy6NACGsy6EJP",
"stripe-version": "2020-08-27",
"strict-transport-security": "max-age=31556926; includeSubDomains; preload"
},
"requestId": "req_dcy6NACGsy6EJP",
"statusCode": 400
}
//这是我的模型架构
const mongoose=require('mongoose');
const paymentSchema = new mongoose.Schema({
fullname:[{
type:mongoose.Schema.ObjectId ,
ref: "userdata",
required:true
}],
cvc:{
type:String
},
country:{
type:String,
},
address:{
type:String,
},
cardnumber:{
type:String,
required:true,
},
expires:{
type:String
},
amount:{
type:String
}
})
module.exports=mongoose.model('paymentdata', paymentSchema);
【问题讨论】:
-
stripe 期望客户对象中的键是
name而不是fullname。有关更多信息,请参见此处:stripe.com/docs/api/customers/create -
@aravind_reddy 您应该将此添加为获得信用的答案。
-
线索在raw.message属性中:“Received unknown parameter: fullname”
标签: node.js mongodb stripe-payments