admin管理员组文章数量:1266572
I am setting up a payment system with Stripe and I would like to add some metadata to the customer object. I would like to add my workspace id to the metadata property of the customer. I tried the below code, but it returns the following error:
⛔️ Error:
Error: Invalid val: {:_bsontype=>"ObjectID", :id=>"\\HÉ\u001E��\u000F�=��"} must be a string under 500 characters
I've logged the workspace Id that I add to this metadata property, but it seems like it's just a regular mongodb ObjectId. Can anyone see what I did wrong?
The code that is supposed to add metadata to the customer I create
// 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 plete',
subscription: adjustedSubscription
});
I am setting up a payment system with Stripe and I would like to add some metadata to the customer object. I would like to add my workspace id to the metadata property of the customer. I tried the below code, but it returns the following error:
⛔️ Error:
Error: Invalid val: {:_bsontype=>"ObjectID", :id=>"\\HÉ\u001E��\u000F�=��"} must be a string under 500 characters
I've logged the workspace Id that I add to this metadata property, but it seems like it's just a regular mongodb ObjectId. Can anyone see what I did wrong?
The code that is supposed to add metadata to the customer I create
// 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 plete',
subscription: adjustedSubscription
});
Share
Improve this question
asked Jan 23, 2019 at 19:55
tillytilly
2,61010 gold badges42 silver badges73 bronze badges
2 Answers
Reset to default 12The values you store in metadata
can only be strings of up to 500 characters. In this case you'd want to parse your workspaceId
as a string. Looks like you'd want to run toString()
or toHexString()
on that ObjectId
.
I ran into the same problem and found Paul's response. Finally works!
router.post("/create-checkout-session", async (req, res) => {
const customer = await stripe.customers.create({
metadata: {
userId: req.body.userId.toString(),
cart: JSON.stringify(req.body.cartItems.toString()),
},
});
本文标签: javascriptAdding metadata to a Stripe customer objectStack Overflow
版权声明:本文标题:javascript - Adding metadata to a Stripe customer object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740995015a2321023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论