[Feature]
mjhatami opened this issue · comments
typescript compatibility
hmacValidator.d.ts is not support type NotificationItem in validateHMAC function.
Error description :
Argument of type 'NotificationItem' is not assignable to parameter of type 'NotificationRequestItem'.
Type 'NotificationItem' is missing the following properties from type 'NotificationRequestItem': 'amount', 'pspReference', 'eventCode', 'eventDate', and 3 more.
Hi @mjhatami,
Thanks for raising this issue.
Could you please provide us the library version you are using, as well as a code snippet with the request you are trying to send.
I would also like to see which models you are trying to utilize to do so.
Thanks in advance.
Kind Regards,
Wouter
Adyen
Hi, I tried to deconstruct the webhook request like the guide in this link but I encountered the error regarding "validateHMAC" function's input type that must be NotificationRequestItem. Finally, I wrote the below code and it works for me, I hope it will be helpful :
private notificationValidator(notification: Notification){
try {
const validator = new hmacValidator();
const notificationRequestItems: NotificationItem[] = notification.notificationItems;
notificationRequestItems.forEach(function(notificationItem: NotificationItem) {
if(!validator.validateHMAC(notificationItem.NotificationRequestItem, ADYEN_NOTIFICATION_KEY)) throw new HttpException(401, 'key is not valid.');
});
return notificationRequestItems;
} catch (error) {
throw new HttpException(error.status || 401, error.message);
}
}