我正在创建一个结账会话,我想在其中添加我在 Stripe 仪表板中创建的运费。
这是我的代码:
$charge = $stripeClient->checkout->sessions->create([ 'payment_method_types' => ['card', 'sepa_debit', 'giropay', 'sofort', 'alipay'], 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'shipping_address_collection' => [ 'allowed_countries' => ['DE'], ], 'shipping_options' => [ 'shipping_rate' => [env('SHIPPING_KEY')], ], 'line_items' => [$lineItems], 'automatic_tax' => [ 'enabled' => true, ], 'mode' => 'payment', 'allow_promotion_codes' => true, ]);
但它给出了数组无效的错误。
如果我评论 shipping_options
它会起作用...
这里出了什么问题?
P粉5236250802024-03-29 09:37:54
现在,您的代码只是为 shipping_options
传递一个散列,而不是一个数组,因此不要这样:
'shipping_options' => [ 'shipping_rate' => [env('SHIPPING_KEY')], ],
您需要移动括号,使其看起来像这样:
'shipping_options' => [ ['shipping_rate' => env('SHIPPING_KEY'),], ],