From cf8278997ff7ec076c7b3b5346513aad26e17b29 Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Thu, 10 Mar 2016 10:29:45 +0000 Subject: [PATCH] Prefer @require_POST over explicit check Signed-off-by: Chris Lamb --- zebra/views.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/zebra/views.py b/zebra/views.py index 4becfe4..9392fb9 100644 --- a/zebra/views.py +++ b/zebra/views.py @@ -9,6 +9,7 @@ from zebra.conf import options from zebra.signals import * from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_POST import logging log = logging.getLogger("zebra.%s" % __name__) @@ -25,15 +26,13 @@ def _try_to_get_customer_from_customer_id(stripe_customer_id): return None @csrf_exempt +@require_POST def webhooks(request): """ Handles all known webhooks from stripe, and calls signals. Plug in as you need. """ - if request.method != "POST": - return HttpResponse("Invalid Request.", status=400) - json = simplejson.loads(request.POST["json"]) if json["event"] == "recurring_payment_failed": @@ -60,13 +59,12 @@ def webhooks(request): return HttpResponse(status=200) @csrf_exempt +@require_POST def webhooks_v2(request): """ Handles all known webhooks from stripe, and calls signals. Plug in as you need. """ - if request.method != "POST": - return HttpResponse("Invalid Request.", status=400) try: event_json = simplejson.loads(request.body)