public void WillCreateANewCustomerInNetsuite()
        {
            var createCustomerRequest = new OrderToImport();

            // General information
            createCustomerRequest.Email       = $"{Faker.Name.First()}{Faker.Name.Last()}@gmail.com";
            createCustomerRequest.PhoneNumber = Faker.Phone.Number();
            createCustomerRequest.Department  = NetSuiteController.b2bDepartmentId;
            createCustomerRequest.UserTypeId  = NetSuiteController.generalContractor;

            // Billing address
            createCustomerRequest.BillingFirstName = Faker.Name.First();
            createCustomerRequest.BillingLastName  = Faker.Name.Last();
            createCustomerRequest.BillingLine1     = Faker.Address.StreetAddress();
            createCustomerRequest.BillingLine2     = "Apt B";
            createCustomerRequest.BillingCity      = Faker.Address.City();
            createCustomerRequest.BillingState     = Faker.Address.UsState();
            createCustomerRequest.BillingZip       = Faker.Address.ZipCode();
            createCustomerRequest.BillingCountry   = "US";

            // Shipping Address
            createCustomerRequest.ShippingFirstName = Faker.Name.First();
            createCustomerRequest.ShippingLastName  = Faker.Name.Last();
            createCustomerRequest.ShippingLine1     = Faker.Address.StreetAddress();
            createCustomerRequest.ShippingLine2     = "Room 104";
            createCustomerRequest.ShippingCity      = Faker.Address.City();
            createCustomerRequest.ShippingState     = Faker.Address.UsState();
            createCustomerRequest.ShippingZip       = Faker.Address.ZipCode();
            createCustomerRequest.ShippingCountry   = "US";

            string customerId = NetSuiteController.GetNetSuiteCustomerId(createCustomerRequest);

            Assert.NotNull(customerId);
        }
        public static void SetTaxableStatus(BigCommerceCustomer customer, OrderToImport request)
        {
            // If there is any value in the tax_exemption_category, they are tax exempt
            request.Taxable = customer.tax_exempt_category == "";

            // If customer is taxable, set tax vendor to Avatax
            request.TaxVendor = request.Taxable ? "1990053" : " ";
        }
        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);
            }
        }
Exemple #4
0
        public void WillImportOrderToNetSuite()
        {
            OrderToImport importOrderRequest = CreateFakeOrderToImport();

            string salesOrderId = NetSuiteController.ImportOrderToNetSuite(importOrderRequest);

            OrderToImport netsuiteResponse = GetSalesOrderValues(salesOrderId);

            // Billing address
            Assert.Equal($"{importOrderRequest.BillingFirstName} {importOrderRequest.BillingLastName}", netsuiteResponse.BillingAddressee);
            Assert.Equal(importOrderRequest.BillingLine1, netsuiteResponse.BillingLine1);
            Assert.Equal(importOrderRequest.BillingLine2, netsuiteResponse.BillingLine2);
            Assert.Equal(importOrderRequest.BillingCity, netsuiteResponse.BillingCity);
            Assert.Equal(importOrderRequest.BillingState, netsuiteResponse.BillingState);
            Assert.Equal(importOrderRequest.BillingZip, netsuiteResponse.BillingZip);

            // Shipping address
            Assert.Equal($"{importOrderRequest.ShippingFirstName} {importOrderRequest.ShippingLastName}", netsuiteResponse.ShippingAddressee);
            Assert.Equal(importOrderRequest.ShippingLine1, netsuiteResponse.ShippingLine1);
            Assert.Equal(importOrderRequest.ShippingLine2, netsuiteResponse.ShippingLine2);
            Assert.Equal(importOrderRequest.ShippingCity, netsuiteResponse.ShippingCity);
            Assert.Equal(importOrderRequest.ShippingState, netsuiteResponse.ShippingState);
            Assert.Equal(importOrderRequest.ShippingZip, netsuiteResponse.ShippingZip);

            Assert.Equal(importOrderRequest.CheckoutTypeId, netsuiteResponse.CheckoutTypeId);
            Assert.Equal(importOrderRequest.CustomerId, netsuiteResponse.CustomerId);
            Assert.Equal(importOrderRequest.Department, netsuiteResponse.Department);
            Assert.Equal(importOrderRequest.IPAddress, netsuiteResponse.IPAddress);
            Assert.Equal(importOrderRequest.Microsite, netsuiteResponse.Microsite);
            Assert.Equal(importOrderRequest.Note, netsuiteResponse.Note);
            Assert.Equal(importOrderRequest.SiteOrderNumber, netsuiteResponse.SiteOrderNumber);
            Assert.Equal(importOrderRequest.PaymentMethodId, netsuiteResponse.PaymentMethodId);

            // Items
            foreach (var item in netsuiteResponse.Items)
            {
                if (item.ItemId != "484204" && item.ItemId != "348230")
                {
                    throw new Exception($"Unexpected item id {item.ItemId}");
                }
                else if (item.ItemId == "484204")
                {
                    Assert.Equal(importOrderRequest.Items[0].Quantity, item.Quantity);
                    Assert.Equal(importOrderRequest.Items[0].Rate, item.Rate);
                    Assert.Equal(importOrderRequest.Items[0].Amount, item.Amount);
                    Assert.Equal(importOrderRequest.Items[0].PersonalItem, item.PersonalItem);
                }
                else
                {
                    Assert.Equal(importOrderRequest.Items[1].Quantity, item.Quantity);
                    Assert.Equal(importOrderRequest.Items[1].Rate, item.Rate);
                    Assert.Equal(importOrderRequest.Items[1].Amount, item.Amount);
                    Assert.Equal(importOrderRequest.Items[1].PersonalItem, item.PersonalItem);
                }
            }
        }
 public static void SetOrderDetails(Order order, OrderToImport request)
 {
     request.SiteOrderNumber = $"NP{Convert.ToInt32(order.id)}";
     request.AltOrderNumber  = order.payment_provider_id; // Processing Gateway ID
     request.Note            = order.customer_message;
     request.Microsite       = micrositeId;
     request.CheckoutTypeId  = registered;
     request.PaymentMethodId = creditCard;
     request.SameDayShipping = sameDayFullyCommittedOnly;
     request.SH = Convert.ToDouble(order.base_shipping_cost);
 }
        public void WillGetCustomerNetSuiteId()
        {
            OrderToImport customerRequest = new OrderToImport();

            customerRequest.Email = "*****@*****.**";
            int expectedCustomerId = 17494445;

            string netsuiteCustomerId = NetSuiteController.GetNetSuiteCustomerId(customerRequest);

            Assert.Equal(expectedCustomerId, Convert.ToInt32(netsuiteCustomerId));
        }
Exemple #7
0
        private static OrderToImport GetSalesOrderValues(string salesOrderId)
        {
            RestClient  client  = new RestClient(orderImporterSpecControllerUrl);
            RestRequest request = BigCommerceHelper.CreateNewGetRequest();

            NetSuiteHelper.SetNetSuiteTestParameters(request, salesOrderId);

            IRestResponse response       = client.Execute(request);
            OrderToImport parsedResponse = JsonConvert.DeserializeObject <OrderToImport>(response.Content);

            return(parsedResponse);
        }
        public void WillSetTaxableStatus()
        {
            BigCommerceCustomer customer = new BigCommerceCustomer();

            customer.tax_exempt_category = "G";

            OrderToImport netsuiteRequest       = new OrderToImport();
            bool          expectedTaxableStatus = false;

            NetSuiteController.SetTaxableStatus(customer, netsuiteRequest);

            Assert.Equal(expectedTaxableStatus, netsuiteRequest.Taxable);
        }
 public static void SetShippingInformation(ShippingAddress shippingAddress, OrderToImport request)
 {
     request.ShippingFirstName  = shippingAddress.first_name;
     request.ShippingLastName   = shippingAddress.last_name;
     request.ShippingCompany    = shippingAddress.company;
     request.ShippingLine1      = shippingAddress.street_1;
     request.ShippingLine2      = shippingAddress.street_2;
     request.ShippingCity       = shippingAddress.city;
     request.ShippingState      = NetSuiteHelper.GetStateByName(shippingAddress.state);
     request.ShippingZip        = shippingAddress.zip;
     request.ShippingCountry    = shippingAddress.country_iso2;
     request.ShippingPhone      = shippingAddress.phone;
     request.ShippingMethodName = BigCommerceHelper.GetShippingMethodName(shippingAddress.shipping_method);
 }
        public static void SetNetSuiteItemIdAndPersonalItemFlag(OrderToImport netsuiteRequest)
        {
            var productsOnOrder = netsuiteRequest.Items;

            foreach (Product product in productsOnOrder)
            {
                foreach (ProductOptions option in product.ProductOptions)
                {
                    String[] seperators   = { " ", "-" };
                    String[] displayValue = option.display_value.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
                    Log.Information("display value {@displayValue}", displayValue);
                    Log.Information($"display name {option.display_name}");

                    if (option.display_name.ToLower().Contains("pack"))
                    {
                        int packQuantity = 0;
                        // Look for a pack quantity in the first character of display value. If one is found, append it to the end of the sku
                        if (int.TryParse(displayValue[0], out packQuantity))
                        {
                            if (packQuantity > 1)
                            {
                                product.Sku = $"{product.Sku}_{packQuantity}";
                            }
                        }
                    }
                    // Set the personal item flag
                    if (option.display_value.ToLower().Contains("personal"))
                    {
                        Log.Information($"PersonalItem is true");
                        product.PersonalItem = true;
                    }
                }

                Log.Information($"Parsed sku {product.Sku}");
                product.ItemId = GetNetSuiteItemIdBySku(product.Sku);

                // Set the Shipping Method Name on the item line
                if (netsuiteRequest.ShippingMethodName.Contains("Priority"))
                {
                    product.ShippingMethodName = "Priority";
                }
                else
                {
                    product.ShippingMethodName = "Standard";
                }
            }
        }
        public void WillSetCustomerName()
        {
            string firstName             = "Morty";
            string lastName              = "Smith";
            BigCommerceCustomer customer = new BigCommerceCustomer();

            customer.first_name = firstName;
            customer.last_name  = lastName;

            OrderToImport netsuiteRequest = new OrderToImport();

            NetSuiteController.SetCustomerName(customer, netsuiteRequest);

            Assert.Equal(firstName, netsuiteRequest.CustomerFirstName);
            Assert.Equal(lastName, netsuiteRequest.CustomerLastName);
            Assert.Equal(firstName + " " + lastName, netsuiteRequest.CustomerName);
        }
        public static string ImportOrderToNetSuite(OrderToImport importOrderRequest)
        {
            var client      = new RestClient(orderImporterRestletUrl);
            var jsonRequest = JsonConvert.SerializeObject(importOrderRequest);
            var request     = NetSuiteHelper.CreateNewRestletRequest(jsonRequest, orderImporterRestletUrl, "OrderImporter");

            var orderImporterRestletResponse = client.Execute(request);
            var parsedNetSuiteResponse       = JsonConvert.DeserializeObject <ImportOrderResponse>(orderImporterRestletResponse.Content);

            Log.Information("Netsuite Order Importer response {@parsedNetSuiteResponse}", parsedNetSuiteResponse);

            if (parsedNetSuiteResponse.error != null)
            {
                throw new Exception($"Error: {parsedNetSuiteResponse.error}");
            }

            return(parsedNetSuiteResponse.salesOrderRecordId);
        }
        public static void SetBillingInformation(Order order, OrderToImport request)
        {
            int googleParentAccountId = 18054032;

            request.ParentAccountId  = googleParentAccountId;
            request.Email            = order.billing_address.email;
            request.PhoneNumber      = order.billing_address.phone;
            request.Department       = b2bDepartmentId;
            request.IPAddress        = order.ip_address;
            request.UserTypeId       = generalContractor;
            request.BillingFirstName = order.billing_address.first_name;
            request.BillingLastName  = order.billing_address.last_name;
            request.BillingLine1     = order.billing_address.street_1;
            request.BillingLine2     = order.billing_address.street_2;
            request.BillingCity      = order.billing_address.city;
            request.BillingState     = NetSuiteHelper.GetStateByName(order.billing_address.state);
            request.BillingZip       = order.billing_address.zip;
            request.BillingCountry   = order.billing_address.country_iso2;
            request.Company          = order.billing_address.company;
        }
        public static OrderToImport CreateNetSuiteRequest(Order parsedOrder, ShippingAddress customerShippingAddress)
        {
            OrderToImport       netsuiteRequest = new OrderToImport();
            BigCommerceCustomer customerData    = BigCommerceController.GetCustomerData();

            SetTaxableStatus(customerData, netsuiteRequest);

            SetCustomerName(customerData, netsuiteRequest);

            SetBillingInformation(parsedOrder, netsuiteRequest);

            SetShippingInformation(customerShippingAddress, netsuiteRequest);

            SetOrderDetails(parsedOrder, netsuiteRequest);

            netsuiteRequest.NestProId = BigCommerceController.GetNestProId();

            Log.Information("netsuiteRequest {@netsuiteRequest}", netsuiteRequest);

            return(netsuiteRequest);
        }
Exemple #15
0
        private static OrderToImport CreateFakeOrderToImport()
        {
            var importOrderRequest = new OrderToImport();

            // Billing address
            importOrderRequest.BillingFirstName = Name.First();
            importOrderRequest.BillingLastName  = Name.Last();
            importOrderRequest.BillingLine1     = Address.StreetAddress();
            importOrderRequest.BillingLine2     = "Apt B";
            importOrderRequest.BillingCity      = Address.City();
            importOrderRequest.BillingState     = "GA";
            importOrderRequest.BillingZip       = "30316";
            importOrderRequest.BillingCountry   = "US";

            // Shipping Address
            importOrderRequest.ShippingFirstName  = Name.First();
            importOrderRequest.ShippingLastName   = Name.Last();
            importOrderRequest.ShippingLine1      = Address.StreetAddress();
            importOrderRequest.ShippingLine2      = "Room 104";
            importOrderRequest.ShippingCity       = Address.City();
            importOrderRequest.ShippingState      = "CA";
            importOrderRequest.ShippingZip        = "90292";
            importOrderRequest.ShippingCountry    = "US";
            importOrderRequest.ShippingMethodName = "UPS Ground";

            importOrderRequest.AltOrderNumber  = $"{RandomNumber.Next()}";
            importOrderRequest.CheckoutTypeId  = 4;
            importOrderRequest.CustomerId      = 17494445;
            importOrderRequest.PhoneNumber     = Phone.Number();
            importOrderRequest.Department      = NetSuiteController.b2bDepartmentId;
            importOrderRequest.Email           = $"{Name.First()}{Name.Last()}@gmail.com";
            importOrderRequest.IPAddress       = "1.1.125.45845";
            importOrderRequest.PaymentMethodId = 1;
            importOrderRequest.Microsite       = 31;
            importOrderRequest.Note            = "There is no spoon";
            importOrderRequest.SiteOrderNumber = $"NP{RandomNumber.Next()}";
            importOrderRequest.Items           = CreateFakeItems();

            return(importOrderRequest);
        }
Exemple #16
0
        public void WillCreateNetSuiteRequest()
        {
            BigCommerceController.customerId = 2;
            Order           order           = CreateFakeBigCommerceOrder();
            ShippingAddress shippingAddress = CreateFakeShippingAddress();

            OrderToImport netsuiteRequest = NetSuiteController.CreateNetSuiteRequest(order, shippingAddress);

            Assert.Equal(order.billing_address.email, netsuiteRequest.Email);
            Assert.Equal(order.billing_address.phone, netsuiteRequest.PhoneNumber);
            Assert.Equal(NetSuiteController.b2bDepartmentId, netsuiteRequest.Department);
            Assert.Equal(order.ip_address, netsuiteRequest.IPAddress);
            Assert.Equal("BB1-866", netsuiteRequest.NestProId);

            Assert.Equal($"NP{order.id}", netsuiteRequest.SiteOrderNumber);
            Assert.Equal(order.payment_provider_id, netsuiteRequest.AltOrderNumber);
            Assert.Equal(NetSuiteController.micrositeId, netsuiteRequest.Microsite);
            Assert.Equal(NetSuiteController.registered, netsuiteRequest.CheckoutTypeId);
            Assert.Equal(Convert.ToDouble(order.base_shipping_cost), netsuiteRequest.SH);

            Assert.Equal(order.billing_address.first_name, netsuiteRequest.BillingFirstName);
            Assert.Equal(order.billing_address.last_name, netsuiteRequest.BillingLastName);
            Assert.Equal(order.billing_address.street_1, netsuiteRequest.BillingLine1);
            Assert.Equal(order.billing_address.street_2, netsuiteRequest.BillingLine2);
            Assert.Equal(order.billing_address.city, netsuiteRequest.BillingCity);
            Assert.Equal(NetSuiteHelper.GetStateByName(order.billing_address.state), netsuiteRequest.BillingState);
            Assert.Equal(order.billing_address.zip, netsuiteRequest.BillingZip);
            Assert.Equal(order.billing_address.country_iso2, netsuiteRequest.BillingCountry);
            Assert.Equal(NetSuiteController.generalContractor, netsuiteRequest.UserTypeId);

            Assert.Equal(shippingAddress.first_name, netsuiteRequest.ShippingFirstName);
            Assert.Equal(shippingAddress.last_name, netsuiteRequest.ShippingLastName);
            Assert.Equal(shippingAddress.street_1, netsuiteRequest.ShippingLine1);
            Assert.Equal(shippingAddress.street_2, netsuiteRequest.ShippingLine2);
            Assert.Equal(shippingAddress.city, netsuiteRequest.ShippingCity);
            Assert.Equal(NetSuiteHelper.GetStateByName(shippingAddress.state), netsuiteRequest.ShippingState);
            Assert.Equal(shippingAddress.zip, netsuiteRequest.ShippingZip);
            Assert.Equal(shippingAddress.country_iso2, netsuiteRequest.ShippingCountry);
            Assert.Equal(BigCommerceHelper.GetShippingMethodName(shippingAddress.shipping_method), netsuiteRequest.ShippingMethodName);
        }
        public static string GetNetSuiteCustomerId(OrderToImport createCustomerRequest)
        {
            var client      = new RestClient(createCustomerSuiteletUrl);
            var jsonRequest = JsonConvert.SerializeObject(createCustomerRequest);

            var request = new RestRequest(Method.GET);

            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("jsonRequest", jsonRequest, ParameterType.GetOrPost);

            var response = client.Execute(request);

            if (response.Content.Contains("Error"))
            {
                var errorMessage = $"CreateCustomerSuitelet return an Error: {response.Content}";
                Log.Error(errorMessage);
                throw new Exception(errorMessage);
            }

            var customerId = response.Content;

            Log.Information($"customerId {customerId}");
            return(customerId);
        }
 public static void SetCustomerName(BigCommerceCustomer customer, OrderToImport request)
 {
     request.CustomerFirstName = customer.first_name;
     request.CustomerLastName  = customer.last_name;
 }