private void FillItemCosts(DeliveryItem deliveryItem) { var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient(); var getInventoryReturn = onlineApiClient.GetInventory_SingleItem( onlineApiClient.CreateCredentials(), "1", null, deliveryItem.ItemId, "Wholesale", 0).FirstOrDefault(); if (getInventoryReturn != null) { deliveryItem.Cost = Convert.ToDecimal(getInventoryReturn.Price); deliveryItem.PayCost = deliveryItem.Cost; } }
public void ProcessNotification(PaymentNotificationData data) { try { int orderId = 0; if (int.TryParse(data.mnt_transaction_id, out orderId)) { var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient(); var orderApiCred = orderApiClient.CreateCredentials(); var response = orderApiClient.GetOrderInfo_V2(orderApiCred, orderId); if (response.Success > 0) { int custNum = 0; if (int.TryParse(response.CustomerNumber, out custNum)) { if (custNum >= 2000) { var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, orderId); if (orderDetailsResponse.Success == 0) { throw new InvalidOperationException(orderDetailsResponse.Message); } if (orderDetailsResponse.OrderDetailsResponse .Any(x => x.ProductID.Equals(Properties.Settings.Default.Freedom_VipKitItemId))) { // change customer type var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient(); var onlineApiCred = onlineApiClient.CreateCredentials(); var types = onlineApiClient.GetCustomerTypes(onlineApiCred); var preferredType = types.FirstOrDefault(x => x.Abbreviation.Equals(CustomerType_Preferred)); if (preferredType != null) { onlineApiClient.SetCustomerType(onlineApiCred, response.CustomerNumber, preferredType.ID); } } } } OrderStatus currentStatus = OrderStatus.Unknown; if (Enum.TryParse(response.Status, out currentStatus)) { if (currentStatus == OrderStatus.Entered) { orderApiClient.SetStatusPosted(orderApiCred, orderId, 0); using (BiWellEntities context = new BiWellEntities()) { order_payment payment = new order_payment { order_id = orderId, amount = decimal.Parse(data.mnt_amount, CultureInfo.InvariantCulture), created_at = DateTime.UtcNow }; context.order_payment.Add(payment); context.SaveChanges(); } } } } } } catch (Exception ex) { _looger.Log(ex.Message); } }
private void FillFromFreedomDetails(DeliveryParameters deliveryParameters) { var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient(); var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiClient.CreateCredentials(), deliveryParameters.OrderId); if (orderDetailsResponse.Success == 0) { throw new InvalidOperationException(orderDetailsResponse.Message); } List <DeliveryItem> deliveryItems = new List <DeliveryItem>(); foreach (var responseItem in orderDetailsResponse.OrderDetailsResponse) { DeliveryItem deliveryItem = new DeliveryItem { ItemId = responseItem.ProductID, Name = responseItem.Description, Quantity = responseItem.Quantity, Cost = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture), PayCost = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture) }; FillItemCosts(deliveryItem); deliveryItems.Add(deliveryItem); } var responseOrderInfo = orderApiClient.GetOrderInfo_V2(orderApiClient.CreateCredentials(), deliveryParameters.OrderId); if (responseOrderInfo.Success == 0) { throw new InvalidOperationException(responseOrderInfo.Message); } OrderClientInfo orderClientInfo = OrderClientInfo.ExtractFromOrder(responseOrderInfo); // extracting order client info var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient(); ClientContactInfo contactInfo = new ClientContactInfo(); if (orderClientInfo.IsRep) { var responseRepInfo = onlineApiClient.GetRepInfo_V3(onlineApiClient.CreateCredentials(), orderClientInfo.ClientNumber); if (responseRepInfo.Success == 0) { throw new InvalidOperationException(responseOrderInfo.Message); } contactInfo.FirstName = responseRepInfo.Firstname; contactInfo.LastName = responseRepInfo.Lastname; contactInfo.Email = responseRepInfo.Email; contactInfo.Phone = responseRepInfo.Phone1; } else { var responseCustInfo = onlineApiClient.GetCustomerInfo_v3(onlineApiClient.CreateCredentials(), orderClientInfo.ClientNumber); if (responseCustInfo.Success == 0) { throw new InvalidOperationException(responseOrderInfo.Message); } contactInfo.FirstName = responseCustInfo.FirstName; contactInfo.LastName = responseCustInfo.LastName; contactInfo.Email = responseCustInfo.Email; contactInfo.Phone = responseCustInfo.Phone1; } Address deliveryAddress = new Address { PostIndex = responseOrderInfo.ShipPostalCode, Country = responseOrderInfo.ShipCountry, State = responseOrderInfo.ShipState, Place = responseOrderInfo.ShipCity, Street_1 = responseOrderInfo.ShipStreet1, Street_2 = responseOrderInfo.ShipStreet2 }; DeliveryRecipient recipient = new DeliveryRecipient { FullName = responseOrderInfo.ShipName1, Phone = responseOrderInfo.ShipPhone, Email = responseOrderInfo.ShipEmail }; deliveryParameters.Items = deliveryItems.ToArray(); deliveryParameters.DeliveryAddress = deliveryAddress; deliveryParameters.Recipient = recipient; deliveryParameters.ContactInfo = contactInfo; var responseTotals = orderApiClient.GetTotals(orderApiClient.CreateCredentials(), deliveryParameters.OrderId); if (responseTotals.Success == 0) { throw new InvalidOperationException(responseTotals.Message); } deliveryParameters.ShippingTotal = decimal.Parse(responseTotals.ShippingTotal, CultureInfo.InvariantCulture); }