Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoshMountain's avatar

Passing shipping options into Laravel Cashier

Is it possible to send shipping info into Laravel Cashier for Stripe Checkout? I tried something like this but I get an Invalid Object exception:

Route::get('/checkout', function (Request $request) {
    $stripePriceId = 'price_xxx';

    $quantity = 1;

    return auth()->user()->checkout([$stripePriceId => $quantity], [
        'shipping_options' => ['shr_xxx'],
        'success_url' => route('checkout-success'),
        'cancel_url' => route('checkout-cancel'),
    ]);
})->name('checkout');
0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

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:

  1. Shipping Address Collection: Use shipping_address_collection to specify which countries you allow for shipping. This is necessary if you want to collect shipping addresses.

  2. Shipping Options: The shipping_options array should contain objects with a shipping_rate key, where each value is a valid shipping rate ID created in your Stripe dashboard.

  3. 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.

1 like

Please or to participate in this conversation.