【问题标题】:How to Charge Multiple Items at once in Stripe?如何在 Stripe 中一次为多件商品充电?
【发布时间】:2018-07-29 20:38:48
【问题描述】:

我正在尝试找到一种方法让 Stripe 一次充电即可为多个项目充电。我想它看起来像这样:

$totalitems = [];
if ( $item1 == "true" ) {
    $currentitem = array(
    "amount" => 19999,
    "currency" => "usd",
    "description" => "Item 1",
    "customer" => $customer->id,
    );
    array_push($totalitems, $currentitem);
}

if ( $item2 == "true" ) {
    $currentitem = array(
    "amount" => 29999,
    "currency" => "usd",
    "description" => "Item 2",
    "customer" => $customer->id,
    );
    array_push($totalitems, $currentitem);
}

$charge = \Stripe\Charge::create([$totalitems]);

这仅对数组中的第一项收费。有没有办法一次为多件商品充电?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    在当前的 Stripe checkout.session.create 中,您可以在 line_item 属性中添加多个项目:

    line_items: [
      // ONE ITEM
    
      // {
      //   name: product.name,
      //   description: product.description,
      //   images: [product.image],
      //   amount: product.amount,
      //   currency: product.currency,
      //   quantity: validatedQuantity,
      // },
    
      // MULTIPLE ITEMS
      {
        name: 'F02',
        images: [
          '',
        ],
        amount: '74900',
        currency: 'sek',
        quantity: 2,
      },
      {
        name: 'F01',
        images: [
          '',
        ],
        amount: '74900',
        currency: 'sek',
        quantity: 1,
      },
    ],
    

    【讨论】:

    • 为什么这个旁边有一点胖零?接受你的投票,好先生。这就是我的解决方案。如果我第一次看到这个,本可以节省 1.5 天的头痛。 ?
    • 谢谢@RalphTheWonderLlama。是的,我记得那个头痛。组织良好的文档,然后只是人们一遍又一遍地做的这些小的基本事情,并且在通过示例显示时应该非常清楚。祝你开店好运。
    【解决方案2】:

    您不能以这种方式对多个项目收费。相反,您有几个选择:

    • 只需将您身边的项目相加,并为总金额创建一项费用。
    • 为每件商品单独收费。
    • 使用Orders API

    我建议使用第一种方法,您可以使用费用metadata记录费用中包含哪些项目以供您自己参考。

    【讨论】:

    • 您介意为什么建议第一种方法吗?
    • 嗯,与替代方案相比,快速连续进行多次收费可能会导致某些交易被某些银行标记;并且使用 Stripe 的 Orders API 可能会有点限制或麻烦,因为您必须提前定义所有产品和价格。
    猜你喜欢
    • 2021-11-28
    • 2021-09-01
    • 1970-01-01
    • 2012-12-21
    • 2016-11-17
    • 2021-02-24
    • 2014-06-06
    • 2014-02-14
    • 1970-01-01
    相关资源
    最近更新 更多