我正在建立結帳會話,我想在其中新增我在 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'),], ],