Skip to content

Commit

Permalink
unique webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoor committed Jun 9, 2017
1 parent 55ba0b6 commit 79318a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aa_stripe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ def post(self, request, *args, **kwargs):
"raw_data": json.loads(str(event)),
"id": event["id"],
}
webhook, created = StripeWebhook.objects.get_or_create(id=event["id"])
webhook.raw_data = data["raw_data"]
if created:
# save only if first time
webhook.save()
try:
StripeWebhook.objects.get(pk=event["id"])
return Response(status=400, data={"message": "already received"})
except StripeWebhook.DoesNotExist:
# correct, first time. Create webhook
webhook = StripeWebhook.objects.create(id=event["id"], raw_data=data["raw_data"])

serializer = self.serializer_class(webhook)

Expand Down

0 comments on commit 79318a2

Please sign in to comment.