Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0] Handle incomplete subscriptions upon creation #631

Merged
merged 2 commits into from
Apr 12, 2019

Conversation

driesvints
Copy link
Member

@driesvints driesvints commented Apr 9, 2019

Stripe changed the way failed payments for subscriptions are handled in their 2019-03-14 API update: https://stripe.com/docs/upgrades#2019-03-14

This means subscriptions still get created if the payment fails but they get an incomplete status which gives the customer 23 hours to pay. Since Cashier expects a subscription to be properly paid for we should handle this scenario gracefully.

In the previous API version a card exception was thrown when a payment failed so the only thing that changes with this change is that it's a different exception that's thrown. What also happens is that the subscription gets cancelled immediately if we detect an incomplete subscription so the invoice is voided and the customer isn't billed anymore. No subscription gets added to the billable entity so the developer implementing the feature only needs to handle the exception.

Since this is a bugfix it should be tagged as a patch release but since this also introduces a breaking change a minor release might be more appropriate. An entry to the upgrade guide might be worth considering. Doing a major update for this is overkill since we're actually fixing a bug here.

I'm also planning on working on #621 which should resolve these issues in general so we can incrementally do upgrades instead of fixing these problems ad-hoc whenever Stripe performs an update to their API.

Todo:

  • Handle plan swapping
  • Add entry to upgrade guide

Update: turns out that plan swapping doesn't needs to accommodate for this as it already throws a card declines error. However, I did notice that the subscription was updated regardless of the plan swapping or not. Maybe we need to look into this.

Fixes #628

@driesvints driesvints force-pushed the handle-incomplete-subscriptions branch 3 times, most recently from 03dca54 to ff1aa39 Compare April 9, 2019 22:43
Stripe changed the way failed payments for subscriptions are handled in their 2019-03-14 API update: https://stripe.com/docs/upgrades#2019-03-14

This means subscriptions still get created if the payment fails but they get an incomplete status which gives the customer 23 hours to pay. Since Cashier expects a subscription to be properly paid for we should handle this scenario gracefully.

In the previous API version a card exception was thrown when a payment failed so the only thing that changes with this change is that it's a different exception that's thrown. What also happens is that the subscription gets cancelled immediately if we detect an incomplete subscription so the invoice is voided and the customer isn't billed anymore. No subscription gets added to the billable entity so the developer implementing the feature only needs to handle the exception.
@driesvints driesvints force-pushed the handle-incomplete-subscriptions branch from ff1aa39 to c114b94 Compare April 11, 2019 12:32
@driesvints driesvints marked this pull request as ready for review April 11, 2019 13:36
@pulkitjalan
Copy link

Awesome! Looks great, I guess in older api versions it will just throw a stripe exception as normal.

@driesvints
Copy link
Member Author

driesvints commented Apr 11, 2019

@pulkitjalan yeah older api versions will behave as before.

@pulkitjalan
Copy link

Thanks for the quick turn around on this @driesvints 😄

@taylorotwell taylorotwell merged commit fa03914 into 9.0 Apr 12, 2019
@driesvints driesvints deleted the handle-incomplete-subscriptions branch April 12, 2019 16:10
@driesvints driesvints mentioned this pull request Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stripe Subscriptions Change
3 participants