public ResponseProcessor(WebhookNotificationBody _WebhookBody, ILogger logger, AppSettings appSettings)
 {
     this._WebhookBody       = _WebhookBody;
     this._Logger            = logger;
     this._ClassName         = this.GetType().Name;
     this._AppSettings       = appSettings;
     this._MockRequestHelper = new MockRequestHelper(this._AppSettings);
 }
        public IActionResult Post([FromBody] JObject data)
        {
            _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - [STARTS]");

            // Checking if the request payload is null
            if (data != null)
            {
                _Logger.LogInformation("[" + _ClassName + "]  - POST - api/webhook -  Received Webhook Notification at ");

                var webhookSecret      = _AppSettings.WebhookSecret;
                var requestSignature   = Request.Headers["Elli-Signature"].ToString();
                var requestEnvironment = Request.Headers["Elli-Environment"].ToString();

                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Request Elli-Signature - " + requestSignature);
                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Request Elli-Environment - " + requestEnvironment);

                // generate the webhook token from the payload and secret using HMACSHA
                var webHookToken = WebHookHelper.GetWebhookNotificationToken(data.ToString(Formatting.None), webhookSecret);

                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Data - " + data.ToString(Formatting.Indented));
                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Token - " + webHookToken);

                // Check if the generated WebHook token is similar to the request signature received in the header.
                if (WebHookHelper.IsValidWebhookToken(requestSignature, webHookToken))
                {
                    var webHookBody = new WebhookNotificationBody()
                    {
                        eventId   = data.GetValue <string>("eventId"),
                        eventTime = data.GetValue <DateTime>("eventTime"),
                        eventType = data.GetValue <string>("eventType"),
                        meta      = data.GetValue <Meta>("meta")
                    };

                    var requestProcessor = new RequestProcessor(webHookBody, _Logger, _AppSettings);

                    // processing the webhook request here.
                    requestProcessor.ProcessWebhookRequest();
                }
                else
                {
                    _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Token is Invalid ");
                }
            }

            _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - [ENDS]");

            return(Ok());
        }
        public void Post([FromBody] JObject data)
        {
            _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - [STARTS]");

            // Checking if the request payload is null
            if (data != null)
            {
                _Logger.LogInformation("[" + _ClassName + "]  - POST - api/webhook -  Received Webhook Notification at ");

                var webhookSecret      = _AppSettings.WebhookSecret;
                var requestSignature   = Request.Headers["Elli-Signature"].ToString();
                var requestEnvironment = Request.Headers["Elli-Environment"].ToString();

                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Request Elli-Signature - " + requestSignature);
                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Request Elli-Environment - " + requestEnvironment);

                // generate the webhook token from the payload and secret using HMACSHA
                var webHookToken = WebHookHelper.GetWebhookNotificationToken(data.ToString(Formatting.None), webhookSecret);

                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Data - " + data.ToString(Formatting.Indented));
                _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Token - " + webHookToken);

                // Check if the generated WebHook token is similar to the request signature received in the header.
                if (WebHookHelper.IsValidWebhookToken(requestSignature, webHookToken))
                {
                    var webHookBody = new WebhookNotificationBody()
                    {
                        eventId   = data.GetValue <string>("eventId"),
                        eventTime = data.GetValue <DateTime>("eventTime"),
                        eventType = data.GetValue <string>("eventType"),
                        meta      = data.GetValue <Meta>("meta")
                    };

                    var transactionId = webHookBody.meta != null ? webHookBody.meta.resourceId : string.Empty;

                    _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Transaction ID - " + transactionId);

                    var partnerAPIWrapper = new PartnerAPIWrapper(this._AppSettings);

                    // executing the Get Request Partner API Call here
                    var requestData = partnerAPIWrapper.GetRequest(transactionId);

                    if (requestData != null)
                    {
                        _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - Get Request Data is not null ");

                        var loanInformation = requestData;

                        // if the requestData is not null then the Partner will validate it against their business rules and if it is valid then they have to build their request here and submit it
                        // the response that they receive from their request will go back into the Partner API as a CreateResponse Partner API call

                        var validationInfo = MockResponseHelper.ValidateLoanData(requestData);

                        if (validationInfo != null && validationInfo["success"] != null)
                        {
                            var response = MockRequestHelper.SubmitToPartner(requestData, transactionId);

                            // This method will build the payload required for Creating Response in the Partner API
                            SubmitAcknowledgementToPartnerAPI(response, loanInformation, transactionId);
                        }
                        else
                        {
                            TransactionStatusCache.Instance.Add(transactionId, validationInfo);
                        }
                    }
                }
                else
                {
                    _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - WebHook Token is Invalid ");
                }
            }

            _Logger.LogInformation("[" + _ClassName + "] - POST - api/webhook - [ENDS]");
        }