You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Stripe prices.update更新价格时遇“Received unknown parameter: unit_amount”错误

解决Stripe Prices更新时"Received unknown parameter: unit_amount"错误

Stripe的Price对象是不可变的,创建后无法修改unit_amount字段,这是Stripe API的设计规则。你调用stripe.prices.update时传入该参数,自然会触发"未知参数"的错误。

正确解决方案

因为无法修改已有Price的单价,你需要创建一个新的Price对象关联到同一个产品,之后业务逻辑里改用这个新的Price ID。示例代码:

stripe.prices.create(
  {
    product: "你的产品ID", // 关联原Price所属的产品ID
    unit_amount: setUpAmount,
    currency: "usd", // 替换为你的实际货币代码(如cny、eur等)
  },
  function (err, newPrice) {
    if (err) {
      console.log(err, "创建新Price失败");
    } else {
      console.log("新Price创建成功:", newPrice);
      // 将newPrice.id替换原setUPFee_Id,用于后续业务逻辑
    }
  }
);

若需更新现有订阅的价格

如果你的场景是修改正在进行的订阅收费金额,需更新订阅对象,将其关联的订阅项替换为新创建的Price:

stripe.subscriptions.update(
  "目标订阅ID",
  {
    items: [
      {
        id: "订阅项ID", // 可从订阅对象的items数组中获取对应项ID
        price: newPrice.id, // 传入新创建的Price ID
      },
    ],
  },
  function (err, updatedSubscription) {
    if (err) {
      console.log(err, "更新订阅失败");
    } else {
      console.log("订阅更新成功:", updatedSubscription);
    }
  }
);

内容的提问来源于stack exchange,提问作者isal dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 20:22:18