Skip to content

Commit

Permalink
Make sure correct coupon is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
poxip committed Sep 7, 2017
1 parent 271093e commit 0f00884
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 0f00884

Please sign in to comment.