Skip to content

Commit

Permalink
fix: (#764) fundraising: 'customer.subscription.deleted' webhook even…
Browse files Browse the repository at this point in the history
…t gets 404 response
  • Loading branch information
Neer-Pathak committed Nov 2, 2024
1 parent 87c48e7 commit 8e4235d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion fundraising/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_cancel_donation(self, retrieve_customer):
)
retrieve_customer.assert_called_once_with("54321")
donation = Donation.objects.get(id=donation.id)
self.assertEqual("", donation.stripe_subscription_id)
self.assertEqual("cancel12345", donation.stripe_subscription_id)

@patch("stripe.Customer.retrieve")
def test_cancel_already_cancelled_donation(self, retrieve_customer):
Expand Down Expand Up @@ -200,6 +200,9 @@ def test_record_payment(self, event):
@patch("stripe.Event.retrieve")
def test_subscription_cancelled(self, event):
event.return_value = self.stripe_data("subscription_cancelled")
donation = Donation.objects.get(id=self.donation.id)
donation.stripe_subscription_id = "cancel" + donation.stripe_subscription_id
donation.save()
self.post_event()
donation = Donation.objects.get(id=self.donation.id)
self.assertEqual(donation.stripe_subscription_id, "")
Expand Down
7 changes: 5 additions & 2 deletions fundraising/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def cancel_donation(request, hero):
customer = stripe.Customer.retrieve(donation.stripe_customer_id)
customer.subscriptions.retrieve(donation.stripe_subscription_id).delete()

donation.stripe_subscription_id = ""
donation.stripe_subscription_id = "cancel" + donation.stripe_subscription_id
donation.save()

messages.success(request, "Your donation has been canceled.")
Expand Down Expand Up @@ -232,7 +232,10 @@ def payment_succeeded(self):

def subscription_cancelled(self):
subscription = self.event.data.object
donation = get_object_or_404(Donation, stripe_subscription_id=subscription.id)
cancelled_subscription_id = "cancel" + subscription.id
donation = get_object_or_404(
Donation, stripe_subscription_id=cancelled_subscription_id
)
donation.stripe_subscription_id = ""
donation.save()

Expand Down

0 comments on commit 8e4235d

Please sign in to comment.