From 44ff8fc2b9f99bab690cc373870b7c2360bf95c9 Mon Sep 17 00:00:00 2001 From: Kayode Date: Thu, 21 Jul 2022 16:51:00 +0100 Subject: [PATCH] Updated webhook_service --- paystack/services/webhook_service.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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")