/// <summary>Creates a new CustomerOrder through the API</summary> /// <exception cref="Exception">Thrown when the call is not successful.</exception> /// <param name="newOrder">NewCustomerOrder instance to create order from.</param> /// <returns>The uid of the newly created CustomerOrder.</returns> public int Create(NewCustomerOrder newOrder) { string json = JsonConvert.SerializeObject(newOrder); CallResults results = AJAX.CallAPI(CUSTOMERORDER_API_URL, Constants.enumRESTVerb.POST, json); if (!results.Success || !int.TryParse(results.Json, out int orderId)) { throw new Exception($"Error {MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}"); } return(orderId); }
/// <summary>Builds a new customer order.</summary> /// <param name="uniqueReference">The unique reference of the order.</param> /// <param name="customerToUse">The customer to use.</param> /// <param name="storeCode">The store code.</param> /// <param name="comment">The comment for the order.</param> /// <returns>A CustomerOrder.</returns> public static NewCustomerOrder Build(string uniqueReference, Customer customerToUse, string storeCode, string comment) { NewCustomerOrder newOrder = new NewCustomerOrder() { Id = uniqueReference, ChannelType = "None", StoreClientCode = storeCode, Comment = comment, PremiumShipping = false }; newOrder.Addresses.Add(CustomerOrderAddressBuilder.GenerateBillingAddressFromCustomer(customerToUse)); newOrder.Addresses.Add(CustomerOrderAddressBuilder.GenerateShippingAddressFromCustomer(customerToUse)); return(newOrder); }
/// <summary>Creates new customer order and show response.</summary> /// <param name="customerOrderService">The customer order service.</param> /// <param name="customer">The customer.</param> private static void CreateNewCustomerOrderAndShowResponse(CustomerOrderService customerOrderService, Customer customer) { Console.WriteLine("Getting all items."); ItemService itemService = new ItemService(); List <Item> items = itemService.GetAll(); Console.WriteLine("Getting all stores."); StoresService storesService = new StoresService(); List <Store> stores = storesService.GetAll(); NewCustomerOrder newOrder = NewCustomerOrderBuilder.Build($"{Constants.APP_NAME}{CurrentTimeAsString}", customer, stores.FirstOrDefault().StoreClientCode, "API CSharp Order Comment"); newOrder.Items.Add(new CustomerOrderItem() { Code = items.Last().ItemLookupCode, Quantity = 2, UnitPrice = 9.99, }); try { Console.WriteLine("Creating an order."); int orderId = customerOrderService.Create(newOrder); Console.WriteLine($"New Order Id : {orderId}"); } catch (Exception exception) { Console.WriteLine($"New Order Failed - {exception.Message}"); } }