从Firebase函数(Node.js)更新条带客户
我有以下Firebase功能:从Firebase函数(Node.js)更新条带客户,node.js,firebase,stripe-payments,Node.js,Firebase,Stripe Payments,我有以下Firebase功能: exports.updateStripeCustomer = functions.region('europe-west3') .firestore .document('users/{userId}') .onUpdate( async (change, context) => { const oldValue = change.before.data(); const newValue = chan
exports.updateStripeCustomer = functions.region('europe-west3')
.firestore
.document('users/{userId}')
.onUpdate( async (change, context) => {
const oldValue = change.before.data();
const newValue = change.after.data();
if( JSON.stringify(newValue.adresse) != JSON.stringify(oldValue.adresse) ) {
const user = await admin.auth().getUser(change.after.id)
.then((user) => {
return user.displayName
})
const stripe = Stripe(<api-key>)
const customer = await stripe.customers.update(oldValue.stripe_id,
{
shipping: {
address: {
city: newValue.ort,
postal_code: newValue.plz,
line1: newValue.strasse,
line2: newValue.hausnum
},
name: user
},
}
);
return customer
}
return 'no Data changed'
})
完整日志错误:
{
"shipping": {
"0": {
"name": "Testi Tester"
}
}
}
-------------
Response-Text
{
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: shipping[0]",
"param": "shipping[0]",
"type": "invalid_request_error"
}
}
非常感谢你的帮助 您的参数似乎符合
装运的API文档。错误结构表明您的shipping
对象被解释为一个数组,这意味着请求的字符串化不正确
我的直觉是,这与您的name:user
子参数有关。这应该只是一个字符串,但基于代码段前面的行user.displayName
,它似乎是一个复杂的对象。您的意思是在更新请求中使用相同的user.displayName
我建议您尝试输入一个临时测试值name:“test name”
,看看这是否解决了问题,然后从用户
对象中找出您想要使用的属性。嗨,诺兰,感谢您的回答和思考过程;)变量user.displayName返回一个字符串(来自Firebase用户对象)。如果我省略了shipping对象,名称也会被正确解释(输出),我的猜测是shipping对象/数组的格式不正确。但我也没有找到正确的解决方案/格式。不幸的是,在这种情况下,元数据链接中的示例并不正确:(您是否检查了开发人员日志以了解Stripe是如何接收此请求的?这可能有助于说明什么不起作用。去那里查找您在客户更新中的错误,检查Stripe接收到的负载,并在您的问题中分享这些错误。是的,始终选中…编辑原始邮件某些原因会导致将其解释为。)一个数组,这没有多大意义。如果您也硬编码测试地址字段,这会改变吗?除此之外,您可能希望写入条带支持以获得帮助。
{
"shipping": {
"0": {
"name": "Testi Tester"
}
}
}
-------------
Response-Text
{
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: shipping[0]",
"param": "shipping[0]",
"type": "invalid_request_error"
}
}