public async Task <IActionResult> BuildEvent(string orderId, string eventType)
        {
            Console.WriteLine($"[Build Event]");
            VtexOrder vtexOrder = await _orderFeedAPI.GetOrderInformation(orderId);

            bool success = await _treasureDataAPI.BuildAndSendEvent(vtexOrder, eventType);

            return(Json(success));
        }
Exemple #2
0
        public async Task <IActionResult> BuildEvent(string orderId, string eventType)
        {
            Console.WriteLine($"[Build Event]");
            DateTimeOffset dateTimeOffset = new DateTimeOffset(DateTime.Now);
            VtexOrder      vtexOrder      = await _orderFeedAPI.GetOrderInformation(orderId);

            KlaviyoEvent klaviyoEvent = await _klaviyoAPI.BuildEvent(vtexOrder, eventType, dateTimeOffset);

            return(Json(klaviyoEvent));
        }
Exemple #3
0
        //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);
        }
Exemple #4
0
        public async Task <bool> ProcessNotification(HookNotification hookNotification)
        {
            bool success = false;
            // 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    = hookNotification.OrderId;
            DateTimeOffset lastChange = hookNotification.LastChange;
            KlaviyoEvent   klaviyoEvent;
            VtexOrder      vtexOrder = await _orderFeedAPI.GetOrderInformation(orderId);

            switch (hookNotification.Domain)
            {
            case Constants.Domain.Fulfillment:
                switch (hookNotification.State)
                {
                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:
                //    break;
                default:
                    Console.WriteLine($"State {hookNotification.State} not implemeted.");
                    _context.Vtex.Logger.Info("ProcessNotification", null, $"State {hookNotification.State} not implemeted.");
                    break;
                }
                break;

            case Constants.Domain.Marketplace:
                break;

            default:
                Console.WriteLine($"Domain {hookNotification.Domain} not implemeted.");
                _context.Vtex.Logger.Info("ProcessNotification", null, $"Domain {hookNotification.Domain} not implemeted.");
                break;
            }

            return(success);
        }