我正试图找到一种方法,使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]);
这仅对数组中的第一项收费。是否可以同时为多个商品收费?
答案 0 :(得分:1)
您不能以这种方式向多个项目收费。相反,您有一些选择:
我建议您采用第一种方法,您可以使用费用metadata来记录费用中包括哪些项目,以供您自己参考。
答案 1 :(得分:0)
在当前的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,
},
],