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 card failure in plan swap #641

Merged
merged 1 commit into from
Apr 13, 2019

Conversation

driesvints
Copy link
Member

Previously, when a plan swap was attempted and payment failed, the exception was cascaded to the end user and the update to the subscription in the app was not performed. However, the update to the subscription in Stripe itself was performed and the two states would be out of sync unless you implemented webhooks.

We've decided to catch the card failure exception and allow the plan swap to continue regardless of the failed payment. This leaves the subscription in a "past_due" state. This is because payment failure will be handled by Stripe and Stripe may attempt to retry the payment later on. When payment finally fails on its last attempt Stripe will send out a webhook to update the subscription in the way you specified in its settings: https://stripe.com/docs/billing/lifecycle#settings

Previously, when a plan swap was attempted and payment failed, the exception was cascaded to the end user and the update to the subscription in the app was not performed. However, the update to the subscription in Stripe itself was performed and the two states would be out of sync unless you implemented webhooks.

We've decided to catch the card failure exception and allow the plan swap to continue regardless of the failed payment. This leaves the subscription in a "past_due" state. This is because payment failure will be handled by Stripe and Stripe may attempt to retry the payment later on. When payment finally fails on its last attempt Stripe will send out a webhook to update the subscription in the way you specified in its settings: https://stripe.com/docs/billing/lifecycle#settings
@taylorotwell taylorotwell merged commit 2edac28 into 9.0 Apr 13, 2019
@driesvints driesvints deleted the handle-failed-card-payments-on-plan-swap branch April 15, 2019 13:00
@hlorofos
Copy link

@driesvints what if a developer want to catch this specific event and perform its own business logic about failed plan update? Like in my case I want to revert back to previously used plan.

@driesvints
Copy link
Member Author

@hlorofos unfortunately we can't provide for two cases. You'll have to roll your own solution and override the method. We encourage making use of webhooks to let Stripe retry the payments first.

@hlorofos
Copy link

Understandable and this is exactly how I did it. Just to explain this to anyone reading this thread, you have to create custom Billable trait and use your own Subscription model as the relationship. Then you can define any custom logic.
My reasonale is the following - a customer is on plan and trying to upgrade to a better plan, however the charge isn't successful (like there is no funds for such a costly plan). In my case I'm rolling back previous plan, so that customer could continue using it and potentially be re-billed with the usual price.

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.

3 participants