To pass shipping options into Laravel Cashier for Stripe Checkout, you need to ensure that you are using the correct parameters and structure as expected by Stripe's API. The checkout method in Laravel Cashier allows you to pass additional options, but they must be formatted correctly.
Here's how you can modify your code to include shipping options:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/checkout', function (Request $request) {
$stripePriceId = 'price_xxx';
$quantity = 1;
return auth()->user()->checkout([$stripePriceId => $quantity], [
'success_url' => route('checkout-success'),
'cancel_url' => route('checkout-cancel'),
'shipping_address_collection' => [
'allowed_countries' => ['US', 'CA'], // Specify allowed countries for shipping
],
'shipping_options' => [
[
'shipping_rate' => 'shr_xxx', // Replace with your actual shipping rate ID
],
],
]);
})->name('checkout');
Key Points:
-
Shipping Address Collection: Use
shipping_address_collectionto specify which countries you allow for shipping. This is necessary if you want to collect shipping addresses. -
Shipping Options: The
shipping_optionsarray should contain objects with ashipping_ratekey, where each value is a valid shipping rate ID created in your Stripe dashboard. -
Stripe Dashboard: Ensure that the shipping rate ID (
shr_xxx) is correctly set up in your Stripe account. You can create shipping rates in the Stripe Dashboard under the "Products" section.
By following these steps, you should be able to pass shipping options into Laravel Cashier for Stripe Checkout successfully.