public ShippingNotificationResponse SendShippingNotifications(ShippingNotification request) { var payLoad = new ShippingNotificationOrderDto(request); var backup = new BackupLogEntry(payLoad, nameof(SendShippingNotifications)); var shippingNotification = new ShippingNotificationResponse(); LogRequest(payLoad, nameof(SendShippingNotifications)); try { var result = _atgOrderApi.SendShippingNotifications(payLoad); backup.AddResponse(result); _repository.InsertOne(backup); LogResponse(result); if (string.IsNullOrEmpty(result)) { shippingNotification.EmailSent = false; shippingNotification.ErrorMessage = "Server Error communcating with notification service."; } shippingNotification.EmailSent = Boolean.Parse(result); } catch (Exception ex) { shippingNotification.EmailSent = false; shippingNotification.ErrorMessage = ex.Message; } return(shippingNotification); }
public ActionResult ShippingNotifications(string InvoiceXML) { ShippingNotification shippingNotification = null; var s = new XmlSerializer(typeof(ShippingNotification)); LogRequest(InvoiceXML, "ShippingNotificationXMLFromWM"); using (var reader = new StringReader(InvoiceXML)) { shippingNotification = (ShippingNotification)s.Deserialize(reader); } if (shippingNotification == null || string.IsNullOrEmpty(InvoiceXML)) { Log("Invalid Request"); return(BadRequest("Invalid Request")); } var response = _orderService.SendShippingNotification(shippingNotification); if (response.EmailSent != false) { return(Ok(response)); } Log(response.ErrorMessage); return(StatusCode(500, response)); }
public ShippingNotificationOrderDto(ShippingNotification shippingNotification) { var body = shippingNotification.Body; var summary = body.OrderSummary; var orderDetails = summary.OrderDetail; var orerItems = new ShippingNotificationValidator(); foreach (var item in orderDetails) { var newItem = new ShippingNotificationLineItemDto(item.Carrier, item.Description, item.id, item.QuantityOrdered, item.QuantityShipped, Int32.Parse(item.SAPLineOrderNo), item.ShipDate, item.TrackingNO); orerItems.Add(newItem); } this.CcLast4 = summary.CCLast4; this.CcType = summary.CCType; this.CustomerPO = summary.CustomerPO; this.SapON = summary.SAPON; this.ShipToAttn = summary.ShipToAttn; this.WebON = summary.WebON; this.OrderItems = orerItems; }
private void ProcessResponse(XmlDocument responseString, string prefix) { object ediDocument = null; int bskIdentifier = 0; switch (prefix) { case "OrderResponse": ediDocument = ExtractResponseMessage <OrderResponse>(responseString); bskIdentifier = ((OrderResponse)ediDocument).OrderHeader.BSKIdentifier; break; case "ShippingNotification": ediDocument = ExtractResponseMessage <ShippingNotification>(responseString); bskIdentifier = ((ShippingNotification)ediDocument).ShipmentOrderHeader.BSKIdentifier; break; case "InvoiceNotification": ediDocument = ExtractResponseMessage <InvoiceNotification>(responseString); bskIdentifier = ((InvoiceNotification)ediDocument).InvoiceOrderHeader.BSKIdentifier; break; case "Statuses": ediDocument = XDocument.Parse(responseString.OuterXml); break; } Connector connector = null; using (var unit = GetUnitOfWork()) { if (bskIdentifier != 0) { connector = unit.Scope.Repository <Connector>().GetSingle(x => x.BSKIdentifier == bskIdentifier); } else { if (ediDocument != null) { var connectorid = int.Parse(((XDocument)ediDocument).Root.Attribute("ConnectorID").Value); connector = unit.Scope.Repository <Connector>().GetSingle(x => x.ConnectorID == connectorid); } } if (connector == null) { string bsk = bskIdentifier.ToString(); var setting = unit.Scope.Repository <ConnectorSetting>().GetSingle(x => x.SettingKey == "ShopOrderBSK" && x.Value == bsk); if (setting != null) { connector = setting.Connector; } if (connector == null) { log.WarnFormat("Process response failed for {0} message", prefix); return; } } } OrderHelper helper = new OrderHelper(connector.Connection); sales_flat_order order = null; switch (prefix) { case "OrderResponse": OrderResponse ediResponse = ediDocument as OrderResponse; order = helper.GetSalesOrder(ediResponse.OrderHeader.WebSiteOrderNumber); if (order != null) { order.state = "processing"; order.status = "concentrator"; log.Info("For order " + order.increment_id + " updating the status to concentrator "); helper.UpdateOrderStatus(ediResponse.OrderHeader.WebSiteOrderNumber, MagentoOrderState.Processing, MagentoOrderStatus.concentrator); int cancelledlines = 0; int backorderLines = 0; int lines = 0; foreach (var line in ediResponse.OrderDetails) { //var responseLine = (from r in mctx.sales_flat_order_item // where r.item_id == line.LineNumber // select r).FirstOrDefault(); helper.UpdateOrderLine(order, line); lines++; var lineEntity = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID); //if (responseLine != null) //{ // lines++; if (line.Quantity.QuantityCancelled > 0) { cancelledlines++; } if (line.Quantity.QuantityBackordered > 0) { backorderLines++; } } #region REPLACED WITH FUNCTION : DiSCUSS WITH FREEK //if (cancelledlines == lines) //{ // // helper.UpdateOrderStatus(order.increment_id, MagentoOrderState.canceled, MagentoOrderStatus.canceled); // log.Info("For order " + order.increment_id + " , trying to call the cancel shipment url "); // if (((ConnectorSystemType)connector.ConnectorSystemType).Has(ConnectorSystemType.CallShipmentLink)) // { // int ediOrderLines = ediResponse.OrderDetails.Count(); // var isIgnorable = (ediOrderLines == 1 && (ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_IDEAL".ToLower() || ediResponse.OrderDetails.First().ProductIdentifier.ProductNumber.ToLower() == "ShippingCostProductID_CREDITCARD".ToLower())); // if (!isIgnorable) // { // string url = connector.ConnectorSettings.GetValueByKey("CancelShipmentUrl", string.Empty); // if (!string.IsNullOrEmpty(url)) // { // var skus = new Dictionary<string, int>(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < ediOrderLines; i++) // { // var line = ediResponse.OrderDetails[i]; // sb.Append(HttpUtility.HtmlEncode(line.ProductIdentifier.ManufacturerItemID) + "," + line.Quantity.QuantityShipped); // if (i != ediOrderLines - 1) sb.Append(";"); // } // ///basstock/shipment/shippartialorder/order_id/100000342/items/SKU1,5;SKU2,7/trackin_code/123,2345 // url = string.Format(url, ediResponse.OrderHeader.WebSiteOrderNumber, HttpUtility.UrlEncode(sb.ToString())); // log.Info("For order " + order.increment_id + " , called cancel shipment url " + url); // WebRequest req = WebRequest.Create(url); // using (WebResponse resp = req.GetResponse()) // { // log.AuditInfo("Url for partial shipment called for " + connector.Name + " returned:" + (((HttpWebResponse)resp).StatusDescription)); // } // } // } // } //} #endregion if (cancelledlines > 0) { int totalLines = 0; totalLines = helper.GetOrderLinesCount(order, true); CancelItems(order, connector, ediResponse, cancelledlines, totalLines, helper); } //if (backorderLines == lines) //{ // //helper.UpdateOrderStatus(order.increment_id, MagentoOrderState.Processing, MagentoOrderStatus.backorder); //} } log.DebugFormat("Processed OrderResponse for order {0} (Connector : {1})", ediResponse.OrderHeader.WebSiteOrderNumber, connector.Name); break; case "ShippingNotification": ShippingNotification ediShipment = ediDocument as ShippingNotification; log.Info("Shipment order for " + ediShipment.ShipmentOrderHeader.WebSiteOrderNumber); bool shopOrder = false; order = helper.GetSalesOrder(ediShipment.ShipmentOrderHeader.WebSiteOrderNumber); if (order != null) { if (ediShipment.ShipmentOrderHeader.CustomerOrder.Contains("Winkel#") || ediShipment.ShipmentOrderHeader.CustomerOrder.Contains("#winkel")) { shopOrder = true; } int cancelledlines = 0; int lines = 0; foreach (var line in ediShipment.ShipmentOrderDetails) { long lineNumber = 0; if (long.TryParse(line.LineNumber, out lineNumber)) { var responseLine = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID); if (responseLine != null) { lines++; if (line.Quantity.QuantityCancelled > 0) { cancelledlines++; } helper.UpdateOrderLine(order, line); } } } log.Info("Number of cancelled lines " + cancelledlines); log.Info("For order " + order.increment_id + " trying to call shipment url"); if (((ConnectorSystemType)connector.ConnectorSystemType).Has(ConnectorSystemType.CallShipmentLink)) { int ediOrderLines = ediShipment.ShipmentOrderDetails.Count(); JsonOrder orderJson = new JsonOrder(); orderJson.id = order.increment_id; orderJson.tracking_codes = ediShipment.ShipmentOrderDetails.Select(x => x.ShipmentInformation.TrackAndTraceNumber).Distinct().ToArray(); orderJson.lines = new JsonOrderLine[ediOrderLines]; var isIgnorable = (ediOrderLines == 1 && (ediShipment.ShipmentOrderDetails.First().ProductIdentifier.ManufacturerItemID.ToLower() == "ShippingCostProductID_IDEAL".ToLower() || ediShipment.ShipmentOrderDetails.First().ProductIdentifier.ManufacturerItemID.ToLower() == "ShippingCostProductID_CREDITCARD".ToLower())); if (!isIgnorable) { string url = connector.ConnectorSettings.GetValueByKey("SCBUrl", string.Empty); if (!string.IsNullOrEmpty(url)) { var skus = new Dictionary <string, int>(); for (int i = 0; i < ediOrderLines; i++) { var line = ediShipment.ShipmentOrderDetails[i]; orderJson.lines[i] = new JsonOrderLine() { lineid = line.ProductIdentifier.ManufacturerItemID, qty = line.Quantity.QuantityShipped, status = "S" }; } SendGenericUpdate(orderJson, connector, helper); } } } } log.DebugFormat("Processed ShippingNotification for order {0} (Connector : {1})", ediShipment.ShipmentOrderHeader.WebSiteOrderNumber, connector.Name); break; case "InvoiceNotification": InvoiceNotification ediInvoice = ediDocument as InvoiceNotification; order = helper.GetSalesOrder(ediInvoice.InvoiceOrderHeader.WebSiteOrderNumber); if (order != null) { foreach (var line in ediInvoice.InvoiceOrderDetails) { long lineNumber = 0; if (long.TryParse(line.LineNumber, out lineNumber)) { var responseLine = helper.GetOrderLine(order, line.ProductIdentifier.ManufacturerItemID); if (responseLine != null) { helper.UpdateOrderLine(order, line); } } } } log.DebugFormat("Processed InvoiceNotification for order {0} (Connector : {1})", ediInvoice.InvoiceOrderHeader.WebSiteOrderNumber, connector.Name); break; case "Statuses": string websiteOrderNumber = ((XDocument)ediDocument).Root.Attribute("WebsiteOrderNumber").Value; Dictionary <string, string> urls = new Dictionary <string, string>(); var statuses = ((XDocument)ediDocument).Root.Elements("Status").GroupBy(x => x.Element("StatusDescription").Value).ToArray(); foreach (var statusGroup in statuses) { var count = statusGroup.Count(); var statusId = statusGroup.Key; var statusUrl = connector.ConnectorSettings.GetValueByKey(statusGroup.Key, string.Empty); JsonOrder ord = new JsonOrder(); ord.id = websiteOrderNumber; ord.tracking_codes = new string[0]; ord.lines = new JsonOrderLine[count]; int c = 0; foreach (var stat in statusGroup) { ord.lines[c] = new JsonOrderLine() { lineid = stat.Element("VendorItemNumber").Value, qty = int.Parse(stat.Element("Quantity").Value), status = statusId[0].ToString().ToUpper() }; c++; } SendGenericUpdate(ord, connector, helper, statusUrl); } break; } }
public ShippingNotificationResponse SendShippingNotification(ShippingNotification payload) { return(_erpGateway.SendShippingNotifications(payload)); }