Stripe Checkout会话总价,而不是Unit_price

发布于 2025-02-07 20:30:23 字数 650 浏览 0 评论 0原文

我目前正在从事一个项目。而且我正在利用Stripe.checkout.session.treate功能完美效果。

const session = await stripe.checkout.sessions.create({
  line_items: [
    {
      price_data: {
        currency: "usd",
        unit_amount: 500,
        product_data: {
          name: "name of the product",
        },
      },
      quantity: 1,
    },
  ],
  mode: "payment",
  success_url: "http://example.com/success",
  cancel_url: "http://example.com/",
});

但是我唯一的问题是它仅收到单价。

但是我想要一个只能通过总价,原因是我的代码,如果用户将折扣应用到产品中,则它将其从产品总价中扣除,同时每种产品的单价稳定。

我的问题基本上是有一个我可以通过总价的领域。

I'm working on a project currently. and I'm making use of stripe, the stripe.checkout.session.create function works perfectly.

const session = await stripe.checkout.sessions.create({
  line_items: [
    {
      price_data: {
        currency: "usd",
        unit_amount: 500,
        product_data: {
          name: "name of the product",
        },
      },
      quantity: 1,
    },
  ],
  mode: "payment",
  success_url: "http://example.com/success",
  cancel_url: "http://example.com/",
});

but the only issue i have is it receives only unit price.

but i want a field where i can pass only total Price, cause in my code , if the users applys a discount to a product , it deducts it from the product total price meanwhile the unit price for each product is stable.

My question is basically is there a field where i can pass total price.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2025-02-14 20:30:23

简短的答案是您不能。您需要使用line_items 并通过价格对象ID(PRISE_XXX)或使用Price_data参数使用临时定价。然后,结帐将计算所有订单项中的总数,以任何您提供的。

您有几个选项可以实现所需的行为:

  • 重新计算PRICE_DATA.UNIT_AMOUNT值,以反映客户所应用的折扣。
  • 利用条纹优惠券适用于结帐会话为你。

Short answer is that you can't. You need to use the line_items parameter and either pass a Price object ID (price_xxx) or use ad-hoc pricing with the price_data parameter. Checkout will then compute the total from all line items, factoring in any discounts that you provide.

You have a couple of options to achieve the behaviour you want:

  • Re-calculate the price_data.unit_amount value to reflect the discount applied by your customers.
  • Utilise Stripe coupons to apply to the Checkout Session which will take care of the dedication for you.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文