I use the same code as in the stripe tutorial:
def webhook(request):
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
event = None
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
raise(e)
return HttpResponse(status=400)
except stripe.error.SignatureVerificationError as e:
raise(e)
return HttpResponse(status=400)
# ...
but when I try to test the webhook with the stripe CLI (stripe trigger payment_intent.created
) I have this error:
Internal Server Error: /payment/webhook/
Traceback (most recent call last):
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/rouizi/django-ecommerce/payment/views.py", line 99, in webhook
raise(e)
File "/home/rouizi/django-ecommerce/payment/views.py", line 88, in webhook
payload, sig_header, endpoint_secret
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/stripe/webhook.py", line 23, in construct_event
WebhookSignature.verify_header(payload, sig_header, secret, tolerance)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/stripe/webhook.py", line 78, in verify_header
payload,
stripe.error.SignatureVerificationError: No signatures found matching the expected signature for payload
I tried to decode the payload like this:
payload = request.body.decode('utf-8')
but I still have the same error.
Any ideas where the error may come from ?