public static List <string> GetImportedItemFulfillments() { var getImportedItemFulfillmentsRetryPolicy = Policy.Handle <SqlException>() .WaitAndRetry(4, _ => TimeSpan.FromSeconds(30), (ex, ts, count, context) => { string errorMessage = "Error in GetImportedItemFulfillments"; Log.Warning(ex, $"{errorMessage} . Retrying..."); if (count == 4) { Log.Error(ex, errorMessage); } }); return(getImportedItemFulfillmentsRetryPolicy.Execute(() => { RestClient client = new RestClient($"{BigCommerceHelper.baseUrl}/{bigCommerceOrderId}/shipments"); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse shipmentsApiResponse = client.Execute(request); JArray parsedShipmentsApiResponse = BigCommerceHelper.ParseApiResponse(shipmentsApiResponse.Content); List <string> shipmentsOnOrder = new List <string>(); foreach (var shipment in parsedShipmentsApiResponse) { Shipment parsedShipment = JsonConvert.DeserializeObject <Shipment>(shipment.ToString()); string netsuiteItemFulfillmentId = parsedShipment.NetSuiteItemFulfillmentId; shipmentsOnOrder.Add(netsuiteItemFulfillmentId); } Log.Information("shipmentsOnOrder {@shipmentsOnOrder}", shipmentsOnOrder); return shipmentsOnOrder; })); }
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); }
public static Shipment PostShipmentToBigCommerce(Shipment shipmentToCreate) { RestClient client = new RestClient($"{BigCommerceHelper.baseUrl}/{bigCommerceOrderId}/shipments"); string jsonRequest = JsonConvert.SerializeObject(shipmentToCreate); RestRequest request = BigCommerceHelper.CreateNewPostRequest(jsonRequest); IRestResponse shipmentApiResponse = client.Execute(request); // If there is an error, the API will send the response as a JArray instead of JObject try { Shipment shipmentCreated = JsonConvert.DeserializeObject <Shipment>(shipmentApiResponse.Content); Log.Information($"Shipment created in Big Commerce. Shipment id: {shipmentCreated.ShipmentId}, Big Commerce order id: {bigCommerceOrderId}"); return(shipmentCreated); } catch (Exception ex) { JArray bigCommerceErrorResponse = BigCommerceHelper.ParseApiResponse(shipmentApiResponse.Content); string errorMessage = $"Invalid shipment request. Error: {bigCommerceErrorResponse}"; Log.Error($"Error in PostShipmentToBigCommerce. {errorMessage}"); throw new Exception(errorMessage); } }
public static List <Product> GetProductsOnOrder(string productsUrl) { var getProductsOnOrderRetryPolicy = Policy.Handle <SqlException>() .WaitAndRetry(4, _ => TimeSpan.FromSeconds(30), (ex, ts, count, context) => { string errorMessage = "Error in GetProductsOnOrder"; Log.Warning(ex, $"{errorMessage} . Retrying..."); if (count == 4) { Log.Error(ex, errorMessage); } }); return(getProductsOnOrderRetryPolicy.Execute(() => { RestClient client = new RestClient(productsUrl); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse productsApiResponse = client.Execute(request); JArray parsedProductsApiResponse = BigCommerceHelper.ParseApiResponse(productsApiResponse.Content); List <Product> productsOnOrder = new List <Product>(); foreach (var product in parsedProductsApiResponse) { Product parsedProduct = JsonConvert.DeserializeObject <Product>(product.ToString()); productsOnOrder.Add(parsedProduct); } Log.Information("productsOnOrder {@productsOnOrder}", productsOnOrder); return productsOnOrder; })); }
public static ShippingAddress GetCustomerShippingAddress(string shippingAddressUrl) { var getCustomerShippingAddressRetryPolicy = Policy.Handle <SqlException>() .WaitAndRetry(4, _ => TimeSpan.FromSeconds(30), (ex, ts, count, context) => { string errorMessage = "Error in GetCustomerShippingAddress"; Log.Warning(ex, $"{errorMessage} . Retrying..."); if (count == 4) { Log.Error(ex, errorMessage); } }); return(getCustomerShippingAddressRetryPolicy.Execute(() => { RestClient client = new RestClient(shippingAddressUrl); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse shippingAddressApiResponse = client.Execute(request); JArray parsedShippingAddressApiResponse = BigCommerceHelper.ParseApiResponse(shippingAddressApiResponse.Content); // There will only be one shipping address, so we get the address at the first index ShippingAddress parsedShippingAddress = JsonConvert.DeserializeObject <ShippingAddress>(parsedShippingAddressApiResponse[0].ToString()); Log.Information("Shipping address id: {@shippingAddressId}", parsedShippingAddress.id); return parsedShippingAddress; })); }
private static void DeleteShipment(string shipmentId) { var client = new RestClient($"{BigCommerceHelper.baseUrl}{bigCommerceOrderId}/shipments/{shipmentId}"); var request = BigCommerceHelper.CreateNewDeleteRequest(); client.Execute(request); }
public void WillSetBigCommerceHeaders() { RestRequest request = new RestRequest(Method.GET); BigCommerceHelper.SetBigCommerceHeaders(request); Assert.Equal(4, request.Parameters.Count); }
private static void RemoveItemFulfillmentId(int orderId, int shipmentId) { RestClient client = new RestClient($"{BigCommerceHelper.baseUrl}{orderId}/shipments"); string jsonRequest = "{\"comments\": \"\"}"; RestRequest request = BigCommerceHelper.CreateNewPutRequest(shipmentId, jsonRequest); client.Execute(request); }
public void WillSetShippingMethodToUpsGround() { string shippingMethod = "Free Shipping"; string expectedShippingMethodName = "ups ground"; string shippingMethodName = BigCommerceHelper.GetShippingMethodName(shippingMethod); Assert.Equal(expectedShippingMethodName, shippingMethodName); }
public void WillSetShippingMethodToSecondDayAirEarly() { string shippingMethod = "Priority"; string expectedShippingMethodName = "ups next day air early a.m."; string shippingMethodName = BigCommerceHelper.GetShippingMethodName(shippingMethod); Assert.Equal(expectedShippingMethodName, shippingMethodName); }
private static void ResetOrderStatusAndNetSuiteOrderId(int bigCommerceOrderId, string netsuiteOrderId) { string jsonRequest = "{\"status_id\": 11, \"staff_notes\": \"\"}"; ; RestClient client = new RestClient(BigCommerceHelper.baseUrl); RestRequest request = BigCommerceHelper.CreateNewPutRequest(bigCommerceOrderId, jsonRequest); IRestResponse ordersApiResponse = client.Execute(request); }
private static JArray GetOrdersAwaitingShipment() { RestClient client = new RestClient($"{BigCommerceHelper.baseUrl}?status_id=9"); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse jsonResponse = client.Execute(request); JArray parsedResponse = BigCommerceHelper.ParseApiResponse(jsonResponse.Content); return(parsedResponse); }
public static BigCommerceCustomer GetCustomerData() { string customerUrl = $"https://api.bigcommerce.com/stores/v68kp5ifsa/v2/customers/{customerId}"; RestClient client = new RestClient(customerUrl); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse customerApiResponse = client.Execute(request); BigCommerceCustomer parsedCustomer = JsonConvert.DeserializeObject <BigCommerceCustomer>(customerApiResponse.Content); return(parsedCustomer); }
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); }
private static string GetOrderStatus() { var client = new RestClient($"{BigCommerceHelper.baseUrl}{bigCommerceOrderId}"); var request = BigCommerceHelper.CreateNewGetRequest(); var jsonResponse = client.Execute(request); Order parsedOrder = JsonConvert.DeserializeObject <Order>(jsonResponse.Content); string orderStatus = parsedOrder.status; return(orderStatus); }
public static ShippingAddress GetCustomerShippingAddress(string shippingAddressUrl) { RestClient client = new RestClient(shippingAddressUrl); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse shippingAddressApiResponse = client.Execute(request); JArray parsedShippingAddressApiResponse = BigCommerceHelper.ParseApiResponse(shippingAddressApiResponse.Content); ShippingAddress parsedShippingAddress = JsonConvert.DeserializeObject <ShippingAddress>(parsedShippingAddressApiResponse[0].ToString()); Log.Information("parsedShippingAddress {@parsedShippingAddress}", parsedShippingAddress); return(parsedShippingAddress); }
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 JArray GetOrdersByStatus(int statusId) { RestClient client = new RestClient($"{getOrdersByStatusBaseUrl}{statusId}"); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); string jsonResponse = client.Execute(request).Content; // Handles if there are no orders for a given status if (jsonResponse == "") { return(new JArray()); } return(BigCommerceHelper.ParseApiResponse(jsonResponse)); }
public static void SetOrderStatus(int bigCommerceOrderId, string netsuiteOrderId) { OrderValues orderValues = new OrderValues(awaitingShipmentStatusId, netsuiteOrderId); string jsonRequest = JsonConvert.SerializeObject(orderValues); RestClient client = new RestClient(BigCommerceHelper.baseUrl); RestRequest request = BigCommerceHelper.CreateNewPutRequest(bigCommerceOrderId, jsonRequest); IRestResponse ordersApiResponse = client.Execute(request); if (ordersApiResponse.StatusCode.ToString() != "OK") { throw new Exception($"Error in setting order status to Awaiting Shipment. Big Commerce order id {bigCommerceOrderId}"); } }
public static JArray GetOrdersAwaitingFulfillment() { RestClient client = new RestClient($"{BigCommerceHelper.baseUrl}?status_id={awaitingFulfillmentStatusId}"); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); string jsonResponse = client.Execute(request).Content; JArray parsedResponse; // Handles if there are no orders for a given status if (jsonResponse == "") { parsedResponse = new JArray(); } else { parsedResponse = BigCommerceHelper.ParseApiResponse(jsonResponse); } return(parsedResponse); }
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 List <Product> GetProductsOnOrder(string productsUrl) { RestClient client = new RestClient(productsUrl); RestRequest request = BigCommerceHelper.CreateNewGetRequest(); IRestResponse productsApiResponse = client.Execute(request); JArray parsedProductsApiResponse = BigCommerceHelper.ParseApiResponse(productsApiResponse.Content); List <Product> productsOnOrder = new List <Product>(); foreach (var product in parsedProductsApiResponse) { Product parsedProduct = JsonConvert.DeserializeObject <Product>(product.ToString()); // Map rate and amount values to the NetSuite expected names parsedProduct.Rate = Convert.ToDouble(parsedProduct.BasePrice); parsedProduct.Amount = Convert.ToDouble(parsedProduct.BaseTotal); productsOnOrder.Add(parsedProduct); } Log.Information("productsOnOrder {@productsOnOrder}", productsOnOrder); return(productsOnOrder); }