Add middleware callback function for payload generation