I'm creating a checkout session where I want to add shipping costs that I created in the Stripe dashboard.
This is my code:
$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, ]);
But it gives error that array is invalid.
If I comment shipping_options
it will work...
What's wrong here?
Now, your code is just passing a hash for
shipping_options
, not an array, so don't do this:You need to move the brackets so that they look like this: