diff --git a/aa_stripe/models.py b/aa_stripe/models.py index af7a9a7..b2b933e 100644 --- a/aa_stripe/models.py +++ b/aa_stripe/models.py @@ -201,7 +201,9 @@ def save(self, force_retrieve=False, *args, **kwargs): if self._previous_is_deleted != self.is_deleted and self.is_deleted: try: stripe_coupon = stripe.Coupon.retrieve(self.coupon_id) - stripe_coupon.delete() + # make sure to delete correct coupon + if self.created == timestamp_to_timezone_aware_date(stripe_coupon["created"]): + stripe_coupon.delete() except stripe.error.InvalidRequestError: # means that the coupon has already been removed from stripe pass diff --git a/tests/test_webhooks.py b/tests/test_webhooks.py index d314875..43a240e 100644 --- a/tests/test_webhooks.py +++ b/tests/test_webhooks.py @@ -371,7 +371,7 @@ def test_coupon_delete(self, m): "type": "coupon.deleted" }""") payload["data"]["object"]["created"] = coupon.stripe_response["created"] - m.register_uri("GET", "https://api.stripe.com/v1/coupons/nicecoupon", text=json.dumps({ + m.register_uri("GET", "https://api.stripe.com/v1/coupons/nicecoupon", status_code=404, text=json.dumps({ "error": { "type": "invalid_request_error" }