diff --git a/fundraising/tests/test_views.py b/fundraising/tests/test_views.py index 74a923d0d..e1d59aa8a 100644 --- a/fundraising/tests/test_views.py +++ b/fundraising/tests/test_views.py @@ -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): @@ -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, "") diff --git a/fundraising/views.py b/fundraising/views.py index 73fb63edb..e3c18633d 100644 --- a/fundraising/views.py +++ b/fundraising/views.py @@ -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.") @@ -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()