예제 #1
0
        public async Task <IActionResult> ProcessNotification()
        {
            return(Ok());

            bool         success = false;
            ActionResult status  = BadRequest();

            if ("post".Equals(HttpContext.Request.Method, StringComparison.OrdinalIgnoreCase))
            {
                string bodyAsText = await new System.IO.StreamReader(HttpContext.Request.Body).ReadToEndAsync();
                Console.WriteLine($"[Hook Notification] : '{bodyAsText}'");
                dynamic notification = JsonConvert.DeserializeObject <dynamic>(bodyAsText);
                if (notification != null && notification.hookConfig != null && notification.hookConfig == Constants.HookPing)
                {
                    status  = Ok();
                    success = true;
                }
                else
                {
                    HookNotification hookNotification = JsonConvert.DeserializeObject <HookNotification>(bodyAsText);
                    success = await _klaviyoAPI.ProcessNotification(hookNotification);

                    status = success ? Ok() : StatusCode(StatusCodes.Status500InternalServerError);
                }

                _context.Vtex.Logger.Info("ProcessNotification", null, $"Success? [{success}] for {bodyAsText}");
            }
            else
            {
                Console.WriteLine($"[Hook Notification] : '{HttpContext.Request.Method}'");
            }

            Console.WriteLine($"[Process Notification] : '{success}'");
            return(Json(status));
        }
예제 #2
0
        public void AllStates(string account, string workspace)
        {
            string bodyAsText = new System.IO.StreamReader(HttpContext.Request.Body).ReadToEndAsync().Result;
            AllStatesNotification allStatesNotification = JsonConvert.DeserializeObject <AllStatesNotification>(bodyAsText);
            bool success = _klaviyoAPI.ProcessNotification(allStatesNotification).Result;

            if (!success)
            {
                _context.Vtex.Logger.Info("Order Broadcast", null, $"Failed to Process Notification {bodyAsText}");
                throw new Exception("Failed to Process Notification");
            }
        }