diff --git a/webhook/views.py b/webhook/views.py index 842f55b5..84e53724 100644 --- a/webhook/views.py +++ b/webhook/views.py @@ -17,10 +17,15 @@ logger = logging.getLogger(__name__) @csrf_exempt def handle_invoice_webhook(request): payload = request.body - sig_header = request.META['HTTP_STRIPE_SIGNATURE'] event = None try: + if 'HTTP_STRIPE_SIGNATURE' in request.META: + sig_header = request.META['HTTP_STRIPE_SIGNATURE'] + else: + logger.error("No HTTP_STRIPE_SIGNATURE header") + # Invalid payload + return HttpResponse(status=400) event = stripe.Webhook.construct_event( payload, sig_header, settings.INVOICE_WEBHOOK_SECRET )