我正在使用 Stripe 设置支付系统,我想向客户对象添加一些元数据。我想将我的工作区 ID 添加到客户的元数据属性中。我尝试了下面的代码,但它返回以下错误:
⛔️ Error:
Error: Invalid val: {:_bsontype=>"ObjectID", :id=>"\\HÉ\u001E��\u000F�=��"} must be a string under 500 characters
我已经记录了添加到此元数据属性的工作区 ID,但它似乎只是一个常规的 mongodb ObjectId。谁能看到我做错了什么吗?
应该向我创建的客户添加元数据的代码
// find the current User and use his workspace ID
const user = await User.findOne({ _id: req.userId });
const workspaceId = user._workspace;
// get the payment plan
const plan = await stripe.plans.retrieve('plan_EK1uRUJLJcDS6e');
// // then we create a new customer
const customer = await stripe.customers.create({
email,
source,
metadata: {
workspace_id: workspaceId
}
});
res.status(200).json({
message: 'payment complete',
subscription: adjustedSubscription
});
您存储的值metadata
只可以是最多 500 个字符的字符串 https://stripe.com/docs/api/metadata?lang=node。在这种情况下,您需要解析您的workspaceId
作为字符串。看来你想跑步toString()
or toHexString() https://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html在那ObjectId
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)