[英]Adding metadata to a Stripe customer object
我正在使用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個字符的字符串 。 在這種情況下,您需要將workspaceId
ID解析為字符串。 看起來您想在該ObjectId
上運行toString()
或toHexString()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.