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.
This PR adopts the new recommended
default_incomplete
payment behavior that Stripe now recommends. The main adjustments here are the transition to the newdefault_incomplete
value when passing thepayment_behavior
when creating or updating subscriptions or subscription items and confirming the payment intents server-side before throwing theIncompletePayment
exception.I've extracted the logic to handle payment failures in a new
HandlesPaymentFailures
trait. In here, we'll check if a subscription has a failed payment. If so, we'll check if it needs confirmation and when it does we'll confirm it server-side. If a payment method has been provided as well (usually when creating a subscription) we'll pass it along. After confirming the payment we'll need to update the subscription status. If no confirmation is needed and there is an incomplete payment we'll cascade the exception immediately.I managed to made this PR backwards compatible for existing integrations. Existing integrations are expected to handle failing payments anyway so it should be a smooth upgrade.
The next step I want to take is to update our docs with the flow of how Stripe recommends to handle collecting payment details which is after a subscription has been already created.
More info: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#create-subscription