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

标签 javascript node.js stripe-payments

我正在使用 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/

相关文章:

javascript - Chai相关错误信息: "AssertionError: expected undefined to deeply equal"

javascript - 通过mongodb文档的property进行映射

node.js - 如何通过 express 使用 Node.js 0.8.x 域?

php - Laravel Cashier paymentMethods() 总是返回空对象结果

api - Stripe Connect - 与语言环境的链接

php - Stripe 此客户没有附加付款来源

javascript - 使用 For-Loop 使隐藏的表行在填充时显示

javascript - 使用 Javascript 的 Unix 到日期时间对象

javascript - 无法动态操作多边形的坐标

node.js - Express 中的根路由未重定向