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); } }
public void WillGetCustomerShippingAddress() { string shippingAddressUrl = $"{BigCommerceHelper.baseUrl}/{bigCommerceOrderId}/shippingaddresses"; ShippingAddress customerShippingAddress = BigCommerceController.GetCustomerShippingAddress(shippingAddressUrl); Assert.Equal(31, customerShippingAddress.id); Assert.Equal(bigCommerceOrderId, customerShippingAddress.order_id); Assert.Equal("Barry", customerShippingAddress.first_name); Assert.Equal("Block", customerShippingAddress.last_name); Assert.Equal("998 Hollywood Blvd", customerShippingAddress.street_1); Assert.Equal("Apt D", customerShippingAddress.street_2); Assert.Equal("Beverly Hills", customerShippingAddress.city); Assert.Equal("California", customerShippingAddress.state); Assert.Equal("90210", customerShippingAddress.zip); }