如何在 Stripe 中同时为多个项目充电?

Cri*_*an 1 stripe-payments

我正在尝试找到一种方法让 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]);
Run Code Online (Sandbox Code Playgroud)

这仅对数组中的第一项收费。有没有办法同时为多个项目充电?

Pat*_*erg 6

在当前的 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,
  },
],
Run Code Online (Sandbox Code Playgroud)