Add webhook app and create_webhook management command
This commit is contained in:
parent
68538ac981
commit
9b32290964
5 changed files with 91 additions and 0 deletions
36
webhook/views.py
Normal file
36
webhook/views.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import logging
|
||||
import stripe
|
||||
|
||||
# Create your views here.
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@require_POST
|
||||
@csrf_exempt
|
||||
def handle_invoice_webhook(request):
|
||||
payload = request.body
|
||||
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
|
||||
event = None
|
||||
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload, sig_header, settings.INVOICE_WEBHOOK_SECRET
|
||||
)
|
||||
except ValueError as e:
|
||||
logger.error("Invalid payload details = " + str(e))
|
||||
# Invalid payload
|
||||
return HttpResponse(status=400)
|
||||
except stripe.error.SignatureVerificationError as e:
|
||||
logger.error("SignatureVerificationError details = " + str(e))
|
||||
# Invalid signature
|
||||
return HttpResponse(status=400)
|
||||
|
||||
# Do something with event
|
||||
logger.debug("Passed invoice signature verification")
|
||||
|
||||
return HttpResponse(status=200)
|
||||
Loading…
Add table
Add a link
Reference in a new issue