将元数据添加到 Stripe 客户对象

til*_*lly 1 javascript node.js stripe-payments

我正在使用 Stripe 设置支付系统,并且我想向客户对象添加一些元数据。我想将我的工作区 ID 添加到客户的元数据属性中。我尝试了下面的代码,但它返回以下错误:

?? Error:
 Error: Invalid val: {:_bsontype=>"ObjectID", :id=>"\\HÉ\u001E??\u000F?=??"} must be a string under 500 characters
Run Code Online (Sandbox Code Playgroud)

我已经记录了我添加到此元数据属性的工作区 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
    });
Run Code Online (Sandbox Code Playgroud)

Pau*_*jes 8

您存储的值metadata只能是最多 500 个字符的字符串。在这种情况下,您希望将您的解析workspaceId为字符串。看起来你想跑toString()toHexString()在那个上ObjectId