Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions paystack/services/webhook_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ def webhook_handler(self):
except Exception as e: # If user hasn't declared variable
raise ValidationError(e)

webhook_data = self.request.data
hash = hmac.new(secret, webhook_data, digestmod=hashlib.sha512).hexdigest()
# Use self.request.body instead of self.request.data ==> according to Paystack docs.
# DRF request.data is a bit different from the default request.body
webhook_data = self.request.body

# using the secret key without encoding throws an error.
hash = hmac.new(secret.encode('utf-8'), webhook_data, digestmod=hashlib.sha512).hexdigest()

if hash != self.request.headers["x-paystack-signature"]:
raise ValidationError("MAC authentication failed")
Expand Down