const notificationService = require('../services/notification.service'); const responseHelper = require('../../../helpers/response.helper'); class NotificationController { static async handle(req, res) { const payload = req.body; try { const callbackToken = req.headers['x-callback-token']; if (callbackToken !== process.env.ROUTER_CALLBACK_TOKEN) { return responseHelper.error(res, "Unauthorized token router gateway", 401); } const isValid = notificationService.verifySignature(payload); if (!isValid) { return responseHelper.error(res, "Invalid Signature Key", 403); } await notificationService.processNotification(payload); return responseHelper.success(res, "Notification Handled"); } catch (error) { console.error("Webhook Error:", error.message); return responseHelper.error(res, error.message); } } } module.exports = NotificationController;