laravel / cashier-stripe

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

Downgrade / upgrade of plan not catched #1035

Closed pr4xx closed 3 years ago

pr4xx commented 3 years ago

Description:

It seems like the handleCustomerSubscriptionUpdated method is not yet able to handle down/upgrade of plans. I am using the stripe billing portal and enabled the option that customers can change plans. I got confused that my app still stated that I am on plan B besides me switching to plan A. After looking into the payload of the customer.subscription.updated webhook, I seems to me that the key previous_attributes in the json is ignored / not yet handled. Here is the json of the webhook: customer_subscription_updated.txt

Steps To Reproduce:

  1. Enable billing portal in stripe with the option to change plans
  2. Subscribe to some plan
  3. Redirect to the billing portal and change plan
  4. Look into database to see that there is no info of a new plan or even a date in ends_at for the old plan
driesvints commented 3 years ago

FYI: haven't gotten to this yet but hoping to check into this on Thursday or Friday.

driesvints commented 3 years ago

I didn't get to this yet sorry... I'll try to next week!

driesvints commented 3 years ago

I can't reproduce this on the latest version sorry. I can swap plans just fine and the existing subscription record is updated as well as its related subscription item record.

pr4xx commented 3 years ago

Damn, I tried again just yet and it did not work again. I did the following:

I can see the webhook in the terminal (stripe cli). But my subscriptions table has not changed at all. Do you have a guess where the info gets lost? When inspecting the payload of the webhook coming from stripe you can see the previous_attributes field. As fas as I understand that contains the info about the old plan etc. But I cannot find any place in cashier-stripe where previous_attributes gets handled.

driesvints commented 3 years ago

Hmm we indeed don't use the previous_attributes at all because we don't need it. We just sync back the existing subscription into the database.

Can you maybe set up a test repo with the minimum amount of code that's needed to reproduce this? Please commit your custom changes separately from the skeleton. And note in the readme how you set up your products/prices etc.