Ejemplo n.º 1
0
        static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File(logPath)
                         .CreateLogger();
            Log.Information("Program started");

            try
            {
                // Call the Orders API to get orders that are in 'Awaiting Fulfillment' status
                JArray ordersAwaitingFulfillment = BigCommerceController.GetOrdersAwaitingFulfillment();

                if (ordersAwaitingFulfillment.Count() == 0)
                {
                    Log.Information("No orders to import");
                    return;
                }

                ImportOrdersToNetSuite(ordersAwaitingFulfillment);

                if (ordersMissingProId.Count > 0)
                {
                    AlertB2BTeam();
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error: {ex}");
                string      title        = "Error in NestProOrderImporter";
                string      text         = $"Error message: {ex.Message}";
                string      color        = "red";
                TeamsHelper teamsMessage = new TeamsHelper(title, text, color, errorLogsUrl);
                teamsMessage.LogToMicrosoftTeams(teamsMessage);
            }
        }
        public static string GetNestProId()
        {
            RestClient  client  = new RestClient($@"https://api.bigcommerce.com/stores/v68kp5ifsa/v2/customers/{customerId}");
            RestRequest request = BigCommerceHelper.CreateNewGetRequest();

            IRestResponse       customerApiResponse = client.Execute(request);
            BigCommerceCustomer parsedCustomer      = JsonConvert.DeserializeObject <BigCommerceCustomer>(customerApiResponse.Content);
            string nestProId = "";

            if (parsedCustomer.form_fields == null)
            {
                string      errorMessage = $"No Nest Pro Id found for Big Commerce customer {customerId}";
                string      title        = "Error in ImportOrdersToNetSuite";
                string      color        = "red";
                TeamsHelper teamsMessage = new TeamsHelper(title, errorMessage, color, Program.errorLogsUrl);
                teamsMessage.LogToMicrosoftTeams(teamsMessage);
            }
            else
            {
                foreach (var formField in parsedCustomer.form_fields)
                {
                    if (formField.name.ToLower().Contains("nest pro id"))
                    {
                        nestProId = formField.value;
                    }
                }
            }

            return(nestProId);
        }
Ejemplo n.º 3
0
        private static void ImportOrdersToNetSuite(JArray ordersAwaitingFulfillment)
        {
            try
            {
                foreach (var order in ordersAwaitingFulfillment)
                {
                    Order parsedOrder = JsonConvert.DeserializeObject <Order>(order.ToString());

                    if (parsedOrder.is_deleted == true)
                    {
                        Log.Information($"Skipping order {parsedOrder.customer_id} because it is marked as deleted/archived.");
                        continue;
                    }

                    BigCommerceController.customerId = parsedOrder.customer_id;
                    int bigCommerceOrderId = parsedOrder.id;
                    Log.Information($"bigCommerceOrderId Id {bigCommerceOrderId}");

                    // Get the shipping information
                    string          shippingAddressUrl      = parsedOrder.shipping_addresses.url;
                    ShippingAddress customerShippingAddress = BigCommerceController.GetCustomerShippingAddress(shippingAddressUrl);

                    // Format the request object to send to CreateCustomerRESTlet
                    OrderToImport netsuiteRequest = NetSuiteController.CreateNetSuiteRequest(parsedOrder, customerShippingAddress);

                    if (netsuiteRequest.NestProId == "")
                    {
                        // We alert these to B2B so they can contact the customer
                        ordersMissingProId.Add(bigCommerceOrderId);
                        continue;
                    }

                    netsuiteCustomerId         = NetSuiteController.GetNetSuiteCustomerId(netsuiteRequest);
                    netsuiteRequest.CustomerId = Convert.ToInt32(netsuiteCustomerId);

                    // Call the Products API to get the products on the order
                    string productsUrl = parsedOrder.products.url;
                    netsuiteRequest.Items = BigCommerceController.GetProductsOnOrder(productsUrl);

                    NetSuiteController.SetNetSuiteItemIdAndPersonalItemFlag(netsuiteRequest);

                    // Import order to Netsuite
                    string netsuiteOrderId = NetSuiteController.ImportOrderToNetSuite(netsuiteRequest);

                    // Set the Big Commerce status to 'awaiting shipment' and add the NetSuite order ID to 'staff notes'
                    BigCommerceController.SetOrderStatus(bigCommerceOrderId, netsuiteOrderId);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error: {ex}");
                string      title        = "Error in ImportOrdersToNetSuite";
                string      text         = $"Error message: {ex.Message}";
                string      color        = "red";
                TeamsHelper teamsMessage = new TeamsHelper(title, text, color, errorLogsUrl);
                teamsMessage.LogToMicrosoftTeams(teamsMessage);
            }
        }
Ejemplo n.º 4
0
        private static void AlertB2BTeam()
        {
            var ordersMissingProIdJSON = JsonConvert.SerializeObject(ordersMissingProId);
            var warningMessage         = $"The following orders cannot import because the customer is missing a Nest Pro ID: {ordersMissingProIdJSON}";

            Log.Warning(warningMessage);

            string      title        = "Error Importing Nest Pro Orders";
            string      text         = warningMessage;
            string      color        = "red";
            TeamsHelper teamsMessage = new TeamsHelper(title, text, color, nestTeamUrl);

            teamsMessage.LogToMicrosoftTeams(teamsMessage);
        }
Ejemplo n.º 5
0
        static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File(logPath)
                         .CreateLogger();
            Log.Information("Program started");

            try
            {
                // Pull orders in 'Awaiting Shipment' and 'Partially Shipped' status
                JArray ordersAwaitingShipment = BigCommerceController.GetOrdersByStatus(awaitingShipmentStatusId);
                JArray partiallyShippedOrders = BigCommerceController.GetOrdersByStatus(partiallyShippedStatusId);

                // Merge the two JArray's
                JArray allOrdersAwaitingShipments = MergeJArrays(ordersAwaitingShipment, partiallyShippedOrders);

                // Create shipments in Big Commerce if any new item fulfillments are found in NetSuite
                if (allOrdersAwaitingShipments.Count() == 0)
                {
                    Log.Information("No shipments to import");
                    return;
                }

                ImportShipmentsToBigCommerce(allOrdersAwaitingShipments);

                return;
            }
            catch (Exception ex)
            {
                Log.Error("Error: {@ex}", ex);
                string      title        = "Error in NestProShipments";
                string      text         = $"Error message: {ex.Message}";
                string      color        = "red";
                TeamsHelper teamsMessage = new TeamsHelper(title, text, color, teamsUrl);
                teamsMessage.LogToMicrosoftTeams(teamsMessage);
            }
        }
Ejemplo n.º 6
0
        public static void ImportShipmentsToBigCommerce(JArray allOrdersAwaitingShipments)
        {
            try
            {
                foreach (var order in allOrdersAwaitingShipments)
                {
                    Order parsedOrder = JsonConvert.DeserializeObject <Order>(order.ToString());
                    BigCommerceController.bigCommerceOrderId = parsedOrder.id;
                    Log.Information($"Big Commerce Order Id: {BigCommerceController.bigCommerceOrderId}");

                    // Query NetSuite to get any matching item fulfillments
                    string netsuiteSalesOrderId = parsedOrder.staff_notes;

                    /* Get a list of NetSuite item fulfillment ids (partially shipped orders only) that already exist
                     *  in Big Commerce to exclude so we do not create duplicate shipments.
                     */
                    List <string> importedItemFulfillmentIds = new List <string>();
                    if (parsedOrder.status.ToLower() == "partially shipped")
                    {
                        importedItemFulfillmentIds = BigCommerceController.GetImportedItemFulfillments();
                    }

                    var itemFulfillmentGroupsToImport = NetSuiteController.GetItemFulfillmentsNotImported(netsuiteSalesOrderId, importedItemFulfillmentIds);

                    // Skip line if no item fulfillments are found
                    if (itemFulfillmentGroupsToImport.Count() == 0)
                    {
                        Log.Information($"No item fulfillments to import.");
                        continue;
                    }

                    // Send each item fulfillment group to Big Commerce as a Shipment
                    foreach (var itemFulfillmentGroupToImport in itemFulfillmentGroupsToImport)
                    {
                        Log.Information($"Itfil ID: {itemFulfillmentGroupToImport.Key}");

                        BigCommerceController.currentItemFulfillment = itemFulfillmentGroupToImport;

                        Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroupToImport);

                        // Big Commerce will throw exception if shipment does not have a tracking number
                        if (shipmentToCreate.TrackingNumber == "")
                        {
                            Log.Warning($"No tracking numbers found. Shipment not created.");
                            continue;
                        }

                        // Create the Shipment in Big Commerce
                        try
                        {
                            Shipment shipmentCreated = BigCommerceController.PostShipmentToBigCommerce(shipmentToCreate);
                            Log.Information($"shipment id {shipmentCreated.ShipmentId} created.");
                        }
                        catch (Exception ex)
                        {
                            string errorMessage = $"Error Posting Shipment To Big Commerce. Error: {ex}";
                            Log.Error(errorMessage);
                            string      title        = "Error in NestProShipments PostShipmentToBigCommerce";
                            string      text         = errorMessage;
                            string      color        = "yellow";
                            TeamsHelper teamsMessage = new TeamsHelper(title, text, color, Program.teamsUrl);
                            teamsMessage.LogToMicrosoftTeams(teamsMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = $"Error in ImportShipmentsToBigCommerce. Error: {ex}";
                Log.Error(errorMessage);
                string      title        = "Error in NestProShipments ImportShipmentsToBigCommerce";
                string      text         = errorMessage;
                string      color        = "red";
                TeamsHelper teamsMessage = new TeamsHelper(title, text, color, Program.teamsUrl);
                teamsMessage.LogToMicrosoftTeams(teamsMessage);
            }
        }