Skip to content

Commit

Permalink
Remove already canceled subscriptions (hacktoolkit#428)
Browse files Browse the repository at this point in the history
Handle to remove already `canceled` Stripe subscriptions that happened
may be due to `Stripe Payment Failure` or other reasons.
  • Loading branch information
aarthi-axim committed May 21, 2024
1 parent 88ef63d commit 3bac698
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/stripe_lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,15 @@ def cancel(self):
subscription = self.retrieve()

if subscription:
args = (subscription.get('id'),)
obj = safe_stripe_call(self.STRIPE_API_CLASS.delete, *args)
was_deleted = obj is not None and obj.get('status') == 'canceled'
# Subscription `status` set to `canceled` already
# may be due to `Stripe Payment Failure` or other reasons
was_deleted = subscription.get('status') == 'canceled'

# Subscription is `active` and should be deleted
if not was_deleted:
args = (subscription.get('id'),)
obj = safe_stripe_call(self.STRIPE_API_CLASS.delete, *args)
was_deleted = obj is not None and obj.get('status') == 'canceled'
else:
was_deleted = False

Expand Down

0 comments on commit 3bac698

Please sign in to comment.