laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

[14.x] Fix array merge for checkout #1579

Closed driesvints closed 11 months ago

driesvints commented 11 months ago

Makes sure the payload for checkout is recursively merged instead of overwritten. The create method of the builder doesn't suffers from this because the default payload doesn't have multidimensional options.

Fixes https://github.com/laravel/cashier-stripe/issues/1578

edalzell commented 11 months ago

Thanks @driesvints!

I was heading back here to do a PR (did the issue at the end of my day) only to find you'd done it already! You rock.

bjarn commented 11 months ago

Just dropping this here as this PR might be a breaking change to others like it was for me:

When I first used Cashier, I had to (or at least read in Stripe or Cashier's docs) that I had to set mode to subscription in the checkout attributes. Because of this change, the mode gets merged and changed into an array instead of string, causing this error: CleanShot 2023-10-14 at 13 04 48

Fixed by removing the mode attribute from my checkout builder.

driesvints commented 11 months ago

@bjarn can you share the code that causes this?

bjarn commented 11 months ago

@driesvints Sure!

I used the following builder:

        $builder = $team->newSubscription(
            'default',
            $plan->priceId($data->billing_cycle)
        );

        // ...

        return $builder->checkout([
            'mode' => 'subscription',
            'client_reference_id' => $team->id,
            'customer_update' => [
                'name' => 'auto',
                'address' => 'auto',
                'shipping' => 'never',
            ],
            'billing_address_collection' => 'required',
            'allow_promotion_codes' => true,
            'success_url' => xxx,
            'cancel_url' => xxx
        ])->asStripeCheckoutSession()->url;

I'm not sure why the mode ended up here, but I saw it was also set here: https://github.com/laravel/cashier-stripe/pull/1579/files#diff-6ddbc0726400777bbee69d4448fa971720fb206f613abda0e165fffd8a340316L356

Now it is recursively merged, I think it's appended instead of overwritten of course. Probably have overlooked something when diving into the Stripe docs to see all available parameters not thinking about Cashier's abstractions.

Removed the mode from the builder and it was all fine again.

driesvints commented 11 months ago

Yeah, I'm sorry but I don't feel we can consider this an issue since the builder already adds this for you.

bjarn commented 11 months ago

Yeah, I'm sorry but I don't feel we can consider this an issue since the builder already adds this for you.

Yea, no worries at all! It definitely was an error on my end, just sharing in case anyone else made the same mistake :)

Thanks!