Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 48b2e89

Browse files
fix delete subscription
1 parent bd566d0 commit 48b2e89

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

billing/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
174174
**template_vars,
175175
)
176176

177-
# handler for Stripe event customer.subscription.deleted
178177
def customer_subscription_deleted(self, subscription: stripe.Subscription) -> None:
179178
"""
180179
Stripe customer.subscription.deleted is called when a subscription is deleted.

services/billing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,26 +907,29 @@ def update_plan(self, owner, desired_plan):
907907
),
908908
)
909909

910-
# Delete the existing subscription and payment intent
911910
try:
912-
stripe.PaymentIntent.cancel(payment_intent.id)
911+
# Note that when the subscription is deleted,
912+
# the pending payment method / unverified payment intent are deleted
913913
stripe.Subscription.delete(subscription.id)
914914
log.info(
915-
"Deleted incomplete subscription and payment intent",
915+
"Deleted incomplete subscription",
916916
extra=dict(
917917
subscription_id=subscription.id,
918918
payment_intent_id=payment_intent.id,
919919
),
920920
)
921+
owner.stripe_subscription_id = None
922+
owner.save()
921923
except Exception as e:
922924
log.error(
923-
"Failed to delete subscription and payment intent",
925+
"Failed to delete subscription",
924926
extra=dict(
925927
subscription_id=subscription.id,
926928
payment_intent_id=payment_intent.id,
927929
error=str(e),
928930
),
929931
)
932+
return None
930933

931934
return self.payment_service.create_checkout_session(
932935
owner, desired_plan

0 commit comments

Comments
 (0)