-
Notifications
You must be signed in to change notification settings - Fork 28
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
fix: Update default payment method on subscription for user #630
Conversation
@@ -410,8 +423,17 @@ def update_payment_method(self, owner, payment_method): | |||
owner.stripe_customer_id, | |||
invoice_settings={"default_payment_method": payment_method}, | |||
) | |||
stripe.Subscription.modify( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only functional update, everything else is just logs
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. 📢 Thoughts on this report? Let us know! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #630 +/- ##
=======================================
Coverage 91.52% 91.52%
=======================================
Files 620 620
Lines 16473 16474 +1
=======================================
+ Hits 15077 15078 +1
Misses 1396 1396
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found @@ Coverage Diff @@
## main #630 +/- ##
=======================================
Coverage 91.52% 91.52%
=======================================
Files 620 620
Lines 16473 16474 +1
=======================================
+ Hits 15077 15078 +1
Misses 1396 1396
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #630 +/- ##
===========================================
Coverage 95.94000 95.94000
===========================================
Files 798 798
Lines 17790 17791 +1
===========================================
+ Hits 17069 17070 +1
Misses 721 721
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Purpose/Motivation
Stemmed from this sentry feedback that came in: https://sentry.slack.com/archives/C04LZKE8RMJ/p1718994052609629
Long story short, a stripe subscription will use it's default payment method if exists, before using a customer's default payment method. Because we give the default payment method to a subscription at the time of creation, when a user goes to update their default payment method it doesn't update on the subscription, leading to some weird behavior
The fix then is to also update the default payment method on the subscription to the updated payment method, which is also the payment method shown on the portal for the user.
Relevant stripe doc:
https://docs.stripe.com/api/subscriptions/update#update_subscription-default_payment_method
Links to relevant tickets
Closes codecov/engineering-team#1996
What does this PR do?
Adds a stripe subscription modify call to the payment method
Also adds a guard where if the customer_id doesn't exist we return early (and changes that log to a warning as well)
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.