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 = _treasureDataAPI.ProcessNotification(allStatesNotification).Result; if (!success) { _context.Vtex.Logger.Info("Order Broadcast", null, $"Failed to Process Notification {bodyAsText}"); throw new Exception("Failed to Process Notification"); } }
//public async Task<bool> ProcessNotification(AllStatesNotification allStatesNotification) //{ // bool success = true; // // Use our server - side Track API for the following: // // Placed Order - When an order successfully processes on your system // // Ordered Product - An event for each item in a processed order // // Fulfilled Order - When an order is sent to the customer // // Cancelled Order - When a customer cancels their order // // Refunded Order - When a customer’s order is refunded // string orderId = allStatesNotification.OrderId; // TreasureDataEvent treasureDataEvent; // VtexOrder vtexOrder = await _orderFeedAPI.GetOrderInformation(orderId); // switch (allStatesNotification.Domain) // { // case Constants.Domain.Fulfillment: // switch (allStatesNotification.CurrentState) // { // case Constants.Status.ReadyForHandling: // treasureDataEvent = await BuildEvent(vtexOrder, Constants.Events.PlacedOrder); // if (treasureDataEvent != null) // { // success = await SendEvent(treasureDataEvent); // // Send each item as a separate event // foreach (Item item in vtexOrder.Items) // { // VtexOrder order = vtexOrder; // order.Items = new List<Item> { item }; // treasureDataEvent = await BuildEvent(vtexOrder, Constants.Events.OrderedProduct); // success = success && await SendEvent(treasureDataEvent); // } // } // break; // case Constants.Status.Invoiced: // treasureDataEvent = await BuildEvent(vtexOrder, Constants.Events.FulfilledOrder); // if (treasureDataEvent != null) // { // success = await SendEvent(treasureDataEvent); // } // break; // //case Constants.Status.Canceled: // // break; // default: // Console.WriteLine($"State {allStatesNotification.CurrentState} not implemeted."); // _context.Vtex.Logger.Info("ProcessNotification", null, $"State {allStatesNotification.CurrentState} not implemeted."); // break; // } // break; // case Constants.Domain.Marketplace: // break; // default: // Console.WriteLine($"Domain {allStatesNotification.Domain} not implemeted."); // _context.Vtex.Logger.Info("ProcessNotification", null, $"Domain {allStatesNotification.Domain} not implemeted."); // break; // } // return success; //} public async Task <bool> ProcessNotification(AllStatesNotification allStatesNotification) { bool success = true; // Use our server - side Track API for the following: // Placed Order - When an order successfully processes on your system // Ordered Product - An event for each item in a processed order // Fulfilled Order - When an order is sent to the customer // Cancelled Order - When a customer cancels their order // Refunded Order - When a customer’s order is refunded string orderId = allStatesNotification.OrderId; VtexOrder vtexOrder = await _orderFeedAPI.GetOrderInformation(orderId); switch (allStatesNotification.Domain) { case Constants.Domain.Fulfillment: switch (allStatesNotification.CurrentState) { case Constants.Status.ReadyForHandling: success = await this.BuildAndSendEvent(vtexOrder, Constants.Events.PlacedOrder); break; case Constants.Status.Invoiced: success = await this.BuildAndSendEvent(vtexOrder, Constants.Events.FulfilledOrder); break; case Constants.Status.Canceled: success = await this.BuildAndSendEvent(vtexOrder, Constants.Events.CanceledOrder); break; default: Console.WriteLine($"State {allStatesNotification.CurrentState} not implemeted."); _context.Vtex.Logger.Info("ProcessNotification", null, $"State {allStatesNotification.CurrentState} not implemeted."); break; } break; case Constants.Domain.Marketplace: break; default: Console.WriteLine($"Domain {allStatesNotification.Domain} not implemeted."); _context.Vtex.Logger.Info("ProcessNotification", null, $"Domain {allStatesNotification.Domain} not implemeted."); break; } return(success); }
public async Task <bool> ProcessNotification(AllStatesNotification allStatesNotification) { bool success = true; // Use our server - side Track API for the following: // Placed Order - When an order successfully processes on your system // Ordered Product - An event for each item in a processed order // Fulfilled Order - When an order is sent to the customer // Cancelled Order - When a customer cancels their order // Refunded Order - When a customer’s order is refunded string orderId = allStatesNotification.OrderId; DateTimeOffset lastChange = allStatesNotification.LastChangeDate; KlaviyoEvent klaviyoEvent; VtexOrder vtexOrder = await _orderFeedAPI.GetOrderInformation(orderId); switch (allStatesNotification.Domain) { case Constants.Domain.Fulfillment: switch (allStatesNotification.CurrentState) { case Constants.Status.ReadyForHandling: klaviyoEvent = await BuildEvent(vtexOrder, Constants.Events.PlacedOrder, lastChange); if (klaviyoEvent != null) { success = await SendEvent(klaviyoEvent); // Send each item as a separate event foreach (Item item in vtexOrder.Items) { VtexOrder order = vtexOrder; order.Items = new List <Item> { item }; klaviyoEvent = await BuildEvent(vtexOrder, Constants.Events.OrderedProduct, lastChange); success = success && await SendEvent(klaviyoEvent); } } break; case Constants.Status.Invoiced: klaviyoEvent = await BuildEvent(vtexOrder, Constants.Events.FulfilledOrder, lastChange); if (klaviyoEvent != null) { success = await SendEvent(klaviyoEvent); } break; case Constants.Status.Canceled: klaviyoEvent = await BuildEvent(vtexOrder, Constants.Events.Canceled, lastChange); if (klaviyoEvent != null) { success = await SendEvent(klaviyoEvent); } break; default: Console.WriteLine($"State {allStatesNotification.CurrentState} not implemeted."); _context.Vtex.Logger.Info("ProcessNotification", null, $"State {allStatesNotification.CurrentState} not implemeted."); break; } break; case Constants.Domain.Marketplace: break; default: Console.WriteLine($"Domain {allStatesNotification.Domain} not implemeted."); _context.Vtex.Logger.Info("ProcessNotification", null, $"Domain {allStatesNotification.Domain} not implemeted."); break; } return(success); }