diff --git a/paystack/services/webhook_service.py b/paystack/services/webhook_service.py index 1c6bde4..0fcff07 100644 --- a/paystack/services/webhook_service.py +++ b/paystack/services/webhook_service.py @@ -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")