[9.0] Handle incomplete subscriptions upon creation #631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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