Skip to content

Updated Webhook Service #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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