Handle presence of HTTP_STRIPE_SIGNATURE header in META

This commit is contained in:
PCoder 2019-04-14 01:36:03 +02:00
parent d71bf87470
commit 3b84d6f646

View file

@ -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
)