代码之家  ›  专栏  ›  技术社区  ›  tilly

向条带客户对象添加元数据

  •  0
  • tilly  · 技术社区  · 7 年前

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

    ⛔️ Error:
     Error: Invalid val: {:_bsontype=>"ObjectID", :id=>"\\HÉ\u001E��\u000F�=��"} must be a string under 500 characters
    

    我已经记录了添加到这个元数据属性中的工作区ID,但它似乎只是一个常规的MongoDB对象ID。有人知道我做错了什么吗?

    应该向我创建的客户添加元数据的代码

        // 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
        });
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Paul Asjes    7 年前

    你储存的价值观 metadata 只能 be strings of up to 500 characters . 在这种情况下,您需要分析 workspaceId 作为字符串。看起来你想跑 toString() toHexString() 在那 ObjectId .