将运费添加到结帐会话会导致'无效数组”异常
P粉403549616
P粉403549616 2024-03-28 11:04:59
0
1
466

我正在创建一个结账会话,我想在其中添加我在 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粉403549616
P粉403549616

全部回复(1)
P粉523625080

现在,您的代码只是为 shipping_options 传递一个散列,而不是一个数组,因此不要这样:

'shipping_options' => [
          'shipping_rate' => [env('SHIPPING_KEY')],
        ],

您需要移动括号,使其看起来像这样:

'shipping_options' => [
          ['shipping_rate' => env('SHIPPING_KEY'),],
        ],
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板