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

fix: Update default payment method on subscription for user #630

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

ajay-sentry
Copy link
Contributor

@ajay-sentry ajay-sentry commented Jun 21, 2024

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

  • Calls out when this payment method is used vs. the default on the customer

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.

@@ -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(
Copy link
Contributor Author

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-staging
Copy link

codecov-staging bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.52%. Comparing base (555a041) to head (8c3296c).

✅ 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           
Flag Coverage Δ
unit 91.52% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
services/billing.py 92.47% <100.00%> (+0.02%) ⬆️

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

Copy link

codecov-public-qa bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.52%. Comparing base (555a041) to head (8c3296c).

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #630   +/-   ##
=======================================
  Coverage   91.52%   91.52%           
=======================================
  Files         620      620           
  Lines       16473    16474    +1     
=======================================
+ Hits        15077    15078    +1     
  Misses       1396     1396           
Flag Coverage Δ
unit 91.52% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
services/billing.py 92.47% <100.00%> (+0.02%) ⬆️

Impacted file tree graph

Copy link

codecov bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.94%. Comparing base (555a041) to head (8c3296c).

✅ 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           
Flag Coverage Δ
unit 91.52% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@nora-codecov nora-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ajay-sentry ajay-sentry added this pull request to the merge queue Jun 21, 2024
Merged via the queue into main with commit c3824bd Jun 21, 2024
21 of 22 checks passed
@ajay-sentry ajay-sentry deleted the Ajay/update-default-payment-method-bug branch June 21, 2024 22:29
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.

Default Payment Method not honored on Subscription when Payment Update
2 participants