Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
poxip committed Aug 23, 2017
1 parent 72ac6e1 commit b4b8f3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
19 changes: 18 additions & 1 deletion aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from jsonfield import JSONField

from aa_stripe.exceptions import StripeMethodNotAllowed
from aa_stripe.signals import stripe_webhook_post_save

USER_MODEL = getattr(settings, "STRIPE_USER_MODEL", settings.AUTH_USER_MODEL)

Expand Down Expand Up @@ -400,4 +399,22 @@ class StripeWebhook(models.Model):
raw_data = JSONField()


def stripe_webhook_post_save(sender, instance, created, **kwargs):
if not created:
return

event_type = instance.raw_data.get("type")
if "." not in event_type:
return

event_model, event_action = event_type.split(".")
if event_model == "coupon":
if event_action == "deleted":
coupon_id = instance.raw_data["data"]["object"]["id"]
StripeCoupon.objects.filter(coupon_id=coupon_id).update(is_deleted=True)

instance.is_parsed = True
instance.save()


post_save.connect(stripe_webhook_post_save, sender=StripeWebhook)
10 changes: 0 additions & 10 deletions aa_stripe/signals.py

This file was deleted.

0 comments on commit b4b8f3d

Please sign in to comment.