我正在使用 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
});
最佳答案
您存储在元数据
中的值只能be strings of up to 500 characters 。在这种情况下,您需要将 workspaceId
解析为字符串。看起来您想要运行 toString()
或 toHexString()
在那个 ObjectId
上。
关于javascript - 将元数据添加到 Stripe 客户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54334734/