Skip to content

Commit

Permalink
fix delete subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Jan 24, 2025
1 parent bd566d0 commit 48b2e89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion billing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
**template_vars,
)

# handler for Stripe event customer.subscription.deleted
def customer_subscription_deleted(self, subscription: stripe.Subscription) -> None:
"""
Stripe customer.subscription.deleted is called when a subscription is deleted.
Expand Down
11 changes: 7 additions & 4 deletions services/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,26 +907,29 @@ def update_plan(self, owner, desired_plan):
),
)

# Delete the existing subscription and payment intent
try:

Check warning on line 910 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L910

Added line #L910 was not covered by tests
stripe.PaymentIntent.cancel(payment_intent.id)
# Note that when the subscription is deleted,
# the pending payment method / unverified payment intent are deleted
stripe.Subscription.delete(subscription.id)
log.info(

Check warning on line 914 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L913-L914

Added lines #L913 - L914 were not covered by tests
"Deleted incomplete subscription and payment intent",
"Deleted incomplete subscription",
extra=dict(
subscription_id=subscription.id,
payment_intent_id=payment_intent.id,
),
)
owner.stripe_subscription_id = None
owner.save()
except Exception as e:
log.error(

Check warning on line 924 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L921-L924

Added lines #L921 - L924 were not covered by tests
"Failed to delete subscription and payment intent",
"Failed to delete subscription",
extra=dict(
subscription_id=subscription.id,
payment_intent_id=payment_intent.id,
error=str(e),
),
)
return None

Check warning on line 932 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L932

Added line #L932 was not covered by tests

return self.payment_service.create_checkout_session(

Check warning on line 934 in services/billing.py

View check run for this annotation

Codecov Notifications / codecov/patch

services/billing.py#L934

Added line #L934 was not covered by tests
owner, desired_plan
Expand Down

0 comments on commit 48b2e89

Please sign in to comment.