private ShipmentStatusEvent ToStatusEvent(ActivityType activity) { var ev = new ShipmentStatusEvent(); switch (activity.Status.Type) { case "I": if (activity.Status.Code == "DP") { ev.Description = "Departed".Localize(); } else if (activity.Status.Code == "EP") { ev.Description = "Export scanned".Localize(); } else if (activity.Status.Code == "OR") { ev.Description = "Origin scanned".Localize(); } else { ev.Description = "Arrived".Localize(); } break; case "X": ev.Description = "Not delivered".Localize(); break; case "M": ev.Description = "Booked".Localize(); break; case "D": ev.Description = "Delivered".Localize(); break; } var dateString = string.Concat(activity.Date, " ", activity.Time); ev.DateUtc = DateTime.ParseExact(dateString, "yyyyMMdd HHmmss", CultureInfo.InvariantCulture); ev.CountryCode = activity.ActivityLocation.Address.CountryCode; ev.Location = activity.ActivityLocation.Address.City; return(ev); }
private ShipmentStatusEvent ToStatusEvent(ActivityType activity) { var ev = new ShipmentStatusEvent(); switch (activity.Status.Type) { case "I": if (activity.Status.Code == "DP") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Departed"); } else if (activity.Status.Code == "EP") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.ExportScanned"); } else if (activity.Status.Code == "OR") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.OriginScanned"); } else { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Arrived"); } break; case "X": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.NotDelivered"); break; case "M": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Booked"); break; case "D": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Delivered"); break; } string dateString = string.Concat(activity.Date, " ", activity.Time); ev.Date = DateTime.ParseExact(dateString, "yyyyMMdd HHmmss", CultureInfo.InvariantCulture); ev.CountryCode = activity.ActivityLocation.Address.CountryCode; ev.Location = activity.ActivityLocation.Address.City; return(ev); }
private IList <ShipmentStatusEvent> GetShipmentStatusEvents(Infrastructure.Aftership.Tracking tracker) { var shipmentStatusList = new List <ShipmentStatusEvent>(); tracker = _connection.GetTrackingByNumber(tracker); if (tracker.Checkpoints == null || !tracker.Checkpoints.Any()) { return(shipmentStatusList); } foreach (var checkpoint in tracker.Checkpoints) { Country country = null; if (checkpoint.CountryIso3 != Iso3Country.Null) { country = _countryService.GetCountryByThreeLetterIsoCode(checkpoint.CountryIso3.GetIso3Code()); } var shipmentStatus = new ShipmentStatusEvent { CountryCode = country != null ? country.TwoLetterIsoCode : string.Empty, Date = Convert.ToDateTime(checkpoint.CheckpointTime), EventName = string.Format("{0} ({1})", checkpoint.Message, GetStatus(checkpoint)), Location = string.IsNullOrEmpty(checkpoint.City) ? checkpoint.Location : checkpoint.City }; //// other properties (not used yet) //checkpoint.checkpointTime; //checkpoint.countryName; //checkpoint.state; //checkpoint.zip; shipmentStatusList.Add(shipmentStatus); } return(shipmentStatusList); }
/// <summary> /// Prepare shipment status event by the passed track activity /// </summary> /// <param name="activity">Track activity</param> /// <returns>Shipment status event </returns> private ShipmentStatusEvent PrepareShipmentStatusEvent(UPSTrack.ActivityType activity) { var shipmentStatusEvent = new ShipmentStatusEvent(); try { //prepare date shipmentStatusEvent.Date = DateTime .ParseExact($"{activity.Date} {activity.Time}", "yyyyMMdd HHmmss", CultureInfo.InvariantCulture); //prepare address var addressDetails = new List <string>(); if (!string.IsNullOrEmpty(activity.ActivityLocation?.Address?.CountryCode)) { addressDetails.Add(activity.ActivityLocation.Address.CountryCode); } if (!string.IsNullOrEmpty(activity.ActivityLocation?.Address?.StateProvinceCode)) { addressDetails.Add(activity.ActivityLocation.Address.StateProvinceCode); } if (!string.IsNullOrEmpty(activity.ActivityLocation?.Address?.City)) { addressDetails.Add(activity.ActivityLocation.Address.City); } if (activity.ActivityLocation?.Address?.AddressLine?.Any() ?? false) { addressDetails.AddRange(activity.ActivityLocation.Address.AddressLine); } if (!string.IsNullOrEmpty(activity.ActivityLocation?.Address?.PostalCode)) { addressDetails.Add(activity.ActivityLocation.Address.PostalCode); } shipmentStatusEvent.CountryCode = activity.ActivityLocation?.Address?.CountryCode; shipmentStatusEvent.Location = string.Join(", ", addressDetails); if (activity.Status == null) { return(shipmentStatusEvent); } //prepare description var eventName = string.Empty; switch (activity.Status.Type) { case "I": switch (activity.Status.Code) { case "DP": eventName = "Plugins.Shipping.Tracker.Departed"; break; case "EP": eventName = "Plugins.Shipping.Tracker.ExportScanned"; break; case "OR": eventName = "Plugins.Shipping.Tracker.OriginScanned"; break; default: eventName = "Plugins.Shipping.Tracker.Arrived"; break; } break; case "X": eventName = "Plugins.Shipping.Tracker.NotDelivered"; break; case "M": eventName = "Plugins.Shipping.Tracker.Booked"; break; case "D": eventName = "Plugins.Shipping.Tracker.Delivered"; break; case "P": eventName = "Plugins.Shipping.Tracker.Pickup"; break; } shipmentStatusEvent.EventName = _localizationService.GetResource(eventName); } catch { } return(shipmentStatusEvent); }
/// <summary> /// Gets all events for a tracking number. /// </summary> /// <param name="trackingNumber">The tracking number to track</param> /// <returns>List of Shipment Events.</returns> public virtual IList <ShipmentStatusEvent> GetShipmentEvents(string trackingNumber) { if (string.IsNullOrEmpty(trackingNumber)) { return(new List <ShipmentStatusEvent>()); } var result = new List <ShipmentStatusEvent>(); try { //use try-catch to ensure exception won't be thrown is web service is not available //build the TrackRequest var request = new TrackRequest { // WebAuthenticationDetail = new WebAuthenticationDetail { UserCredential = new WebAuthenticationCredential { Key = _fedexSettings.Key, // Replace "XXX" with the Key Password = _fedexSettings.Password // Replace "XXX" with the Password } }, // ClientDetail = new ClientDetail { AccountNumber = _fedexSettings.AccountNumber, // Replace "XXX" with client's account number MeterNumber = _fedexSettings.MeterNumber // Replace "XXX" with client's meter number }, // TransactionDetail = new TransactionDetail { CustomerTransactionId = "***nopCommerce v16 Request using VC#***" }, //creates the Version element with all child elements populated from the wsdl Version = new VersionId(), //tracking information PackageIdentifier = new TrackPackageIdentifier { Value = trackingNumber, Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG }, IncludeDetailedScans = true, IncludeDetailedScansSpecified = true }; //initialize the service var service = new TrackService(_fedexSettings.Url); //this is the call to the web service passing in a TrackRequest and returning a TrackReply var reply = service.track(request); //parse response if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { foreach (var trackDetail in reply.TrackDetails) { if (trackDetail.Events != null) { //Set the parent level attributes //var statusDescription = trackDetail.StatusDescription; //var tatusCode = trackDetail.StatusCode; //if (statusCode == "DL") //{ // var delivered = true; //} //if (trackDetail.SignatureProofOfDeliveryAvailable == true) //{ // trackResults.SignedForBy = trackDetail.DeliverySignatureName; //} //if (trackDetail.ShipmentWeight != null) //{ // var shipmentWeight = $"{trackDetail.ShipmentWeight.Value} {trackDetail.ShipmentWeight.Units}"; //} //else //{ // var shipmentWeight = $"{trackDetail.PackageWeight.Value} {trackDetail.PackageWeight.Units}"; //} //var shipDate = trackDetail.ShipTimestamp; //var serviceType = trackDetail.ServiceInfo; //var packageCount = int.Parse(trackDetail.PackageCount); //var destination = $"{trackDetail.DestinationAddress.City}, {trackDetail.DestinationAddress.StateOrProvinceCode} {trackDetail.DestinationAddress.CountryCode}"; //var deliveryDate = trackDetail.ActualDeliveryTimestamp; //Set the TrackingActivity foreach (var trackevent in trackDetail.Events) { var sse = new ShipmentStatusEvent(); if (trackevent.TimestampSpecified) { sse.Date = trackevent.Timestamp; } sse.EventName = $"{trackevent.EventDescription} ({trackevent.EventType})"; sse.Location = trackevent.Address.City; sse.CountryCode = trackevent.Address.CountryCode; //other properties (not used yet) //trackevent.EventType; //trackevent.Address.PostalCode; //trackevent.Address.StateOrProvinceCode; //trackevent.StatusExceptionCode; //trackevent.StatusExceptionDescription; result.Add(sse); } } } } //result.AddRange(trackResponse.Shipment.SelectMany(c => c.Package[0].Activity.Select(x => ToStatusEvent(x))).ToList()); } catch (Exception ex) { _logger.Error($"Error while getting Fedex shipment tracking info - {trackingNumber}", ex); } return(result); }
/// <summary> /// Gets all events for a tracking number. /// </summary> /// <param name="trackingNumber">The tracking number to track</param> /// <returns>List of Shipment Events.</returns> public virtual IList <ShipmentStatusEvent> GetShipmentEvents(string trackingNumber) { var result = new List <ShipmentStatusEvent>(); try { //use try-catch to ensure exception won't be thrown is web service is not available //build the TrackRequest var request = new TrackRequest(); // request.WebAuthenticationDetail = new WebAuthenticationDetail(); request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); request.WebAuthenticationDetail.UserCredential.Key = _fedexSettings.Key; // Replace "XXX" with the Key request.WebAuthenticationDetail.UserCredential.Password = _fedexSettings.Password; // Replace "XXX" with the Password // request.ClientDetail = new ClientDetail(); request.ClientDetail.AccountNumber = _fedexSettings.AccountNumber; // Replace "XXX" with client's account number request.ClientDetail.MeterNumber = _fedexSettings.MeterNumber; // Replace "XXX" with client's meter number // request.TransactionDetail = new TransactionDetail(); request.TransactionDetail.CustomerTransactionId = "***NasCommerce v5 Request using VC#***"; //creates the Version element with all child elements populated from the wsdl request.Version = new VersionId(); //tracking information request.PackageIdentifier = new TrackPackageIdentifier(); request.PackageIdentifier.Value = trackingNumber; request.PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG; request.IncludeDetailedScans = true; request.IncludeDetailedScansSpecified = true; //initialize the service var service = new TrackService(_fedexSettings.Url); //this is the call to the web service passing in a TrackRequest and returning a TrackReply TrackReply reply = service.track(request); //parse response if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { foreach (TrackDetail trackDetail in reply.TrackDetails) { if (trackDetail.Events != null) { //Set the parent level attributes //var statusDescription = trackDetail.StatusDescription; //var tatusCode = trackDetail.StatusCode; //if (statusCode == "DL") //{ // var delivered = true; //} //if (trackDetail.SignatureProofOfDeliveryAvailable == true) //{ // trackResults.SignedForBy = trackDetail.DeliverySignatureName; //} //if (trackDetail.ShipmentWeight != null) //{ // var shipmentWeight = string.Format("{0} {1}", trackDetail.ShipmentWeight.Value, trackDetail.ShipmentWeight.Units); //} //else //{ // var shipmentWeight = string.Format("{0} {1}", trackDetail.PackageWeight.Value, trackDetail.PackageWeight.Units); //} //var shipDate = trackDetail.ShipTimestamp; //var serviceType = trackDetail.ServiceInfo; //var packageCount = int.Parse(trackDetail.PackageCount); //var destination = string.Format("{0}, {1} {2}", trackDetail.DestinationAddress.City, trackDetail.DestinationAddress.StateOrProvinceCode, trackDetail.DestinationAddress.CountryCode); //var deliveryDate = trackDetail.ActualDeliveryTimestamp; //Set the TrackingActivity foreach (TrackEvent trackevent in trackDetail.Events) { var sse = new ShipmentStatusEvent(); if (trackevent.TimestampSpecified) { sse.Date = trackevent.Timestamp; } sse.EventName = String.Format("{0} ({1})", trackevent.EventDescription, trackevent.EventType); sse.Location = trackevent.Address.City; sse.CountryCode = trackevent.Address.CountryCode; //other properties (not used yet) //trackevent.EventType; //trackevent.Address.PostalCode; //trackevent.Address.StateOrProvinceCode; //trackevent.StatusExceptionCode; //trackevent.StatusExceptionDescription; result.Add(sse); } } } } //result.AddRange(trackResponse.Shipment.SelectMany(c => c.Package[0].Activity.Select(x => ToStatusEvent(x))).ToList()); } catch (SoapException ex) { var sb = new StringBuilder(); sb.AppendFormat("SoapException Message= {0}.", ex.Message); sb.AppendFormat("SoapException Category:Code:Message= {0}.", ex.Detail.LastChild.InnerText); //sb.AppendFormat("SoapException XML String for all= {0}.", ex.Detail.LastChild.OuterXml); _logger.Error(string.Format("Error while getting Fedex shipment tracking info - {0}", trackingNumber), new Exception(sb.ToString())); } catch (Exception exc) { _logger.Error(string.Format("Error while getting Fedex shipment tracking info - {0}", trackingNumber), exc); } return(result); }
private ShipmentStatusEvent ToStatusEvent(ActivityType activity) { var ev = new ShipmentStatusEvent(); switch (activity.Status.Type) { case "I": if (activity.Status.Code == "DP") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Departed"); } else if (activity.Status.Code == "EP") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.ExportScanned"); } else if (activity.Status.Code == "OR") { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.OriginScanned"); } else { ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Arrived"); } break; case "X": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.NotDelivered"); break; case "M": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Booked"); break; case "D": ev.EventName = _localizationService.GetResource("Plugins.Shipping.UPS.Tracker.Delivered"); break; } string dateString = string.Concat(activity.Date, " ", activity.Time); ev.Date = DateTime.ParseExact(dateString, "yyyyMMdd HHmmss", CultureInfo.InvariantCulture); ev.CountryCode = activity.ActivityLocation.Address.CountryCode; ev.Location = activity.ActivityLocation.Address.City; return ev; }
private ShipmentStatusEvent ToStatusEvent(ActivityType activity) { var ev = new ShipmentStatusEvent(); switch (activity.Status.Type) { case "I": if (activity.Status.Code == "DP") { ev.Description = "Departed".Localize(); } else if (activity.Status.Code == "EP") { ev.Description = "Export scanned".Localize(); } else if (activity.Status.Code == "OR") { ev.Description = "Origin scanned".Localize(); } else { ev.Description = "Arrived".Localize(); } break; case "X": ev.Description = "Not delivered".Localize(); break; case "M": ev.Description = "Booked".Localize(); break; case "D": ev.Description = "Delivered".Localize(); break; } var dateString = string.Concat(activity.Date, " ", activity.Time); ev.DateUtc = DateTime.ParseExact(dateString, "yyyyMMdd HHmmss", CultureInfo.InvariantCulture); ev.CountryCode = activity.ActivityLocation.Address.CountryCode; ev.Location = activity.ActivityLocation.Address.City; return ev; }
/// <summary> /// Gets all events for a tracking number. /// </summary> /// <param name="trackingNumber">The tracking number to track</param> /// <returns>List of Shipment Events.</returns> public virtual IList<ShipmentStatusEvent> GetShipmentEvents(string trackingNumber) { var result = new List<ShipmentStatusEvent>(); try { //use try-catch to ensure exception won't be thrown is web service is not available //build the TrackRequest var request = new TrackRequest(); // request.WebAuthenticationDetail = new WebAuthenticationDetail(); request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); request.WebAuthenticationDetail.UserCredential.Key = _fedexSettings.Key; // Replace "XXX" with the Key request.WebAuthenticationDetail.UserCredential.Password = _fedexSettings.Password; // Replace "XXX" with the Password // request.ClientDetail = new ClientDetail(); request.ClientDetail.AccountNumber = _fedexSettings.AccountNumber; // Replace "XXX" with client's account number request.ClientDetail.MeterNumber = _fedexSettings.MeterNumber; // Replace "XXX" with client's meter number // request.TransactionDetail = new TransactionDetail(); request.TransactionDetail.CustomerTransactionId = "***NasCommerce v5 Request using VC#***"; //creates the Version element with all child elements populated from the wsdl request.Version = new VersionId(); //tracking information request.PackageIdentifier = new TrackPackageIdentifier(); request.PackageIdentifier.Value = trackingNumber; request.PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG; request.IncludeDetailedScans = true; request.IncludeDetailedScansSpecified = true; //initialize the service var service = new TrackService(_fedexSettings.Url); //this is the call to the web service passing in a TrackRequest and returning a TrackReply TrackReply reply = service.track(request); //parse response if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { foreach (TrackDetail trackDetail in reply.TrackDetails) { if (trackDetail.Events != null) { //Set the parent level attributes //var statusDescription = trackDetail.StatusDescription; //var tatusCode = trackDetail.StatusCode; //if (statusCode == "DL") //{ // var delivered = true; //} //if (trackDetail.SignatureProofOfDeliveryAvailable == true) //{ // trackResults.SignedForBy = trackDetail.DeliverySignatureName; //} //if (trackDetail.ShipmentWeight != null) //{ // var shipmentWeight = string.Format("{0} {1}", trackDetail.ShipmentWeight.Value, trackDetail.ShipmentWeight.Units); //} //else //{ // var shipmentWeight = string.Format("{0} {1}", trackDetail.PackageWeight.Value, trackDetail.PackageWeight.Units); //} //var shipDate = trackDetail.ShipTimestamp; //var serviceType = trackDetail.ServiceInfo; //var packageCount = int.Parse(trackDetail.PackageCount); //var destination = string.Format("{0}, {1} {2}", trackDetail.DestinationAddress.City, trackDetail.DestinationAddress.StateOrProvinceCode, trackDetail.DestinationAddress.CountryCode); //var deliveryDate = trackDetail.ActualDeliveryTimestamp; //Set the TrackingActivity foreach (TrackEvent trackevent in trackDetail.Events) { var sse = new ShipmentStatusEvent(); if (trackevent.TimestampSpecified) { sse.Date = trackevent.Timestamp; } sse.EventName = String.Format("{0} ({1})", trackevent.EventDescription, trackevent.EventType); sse.Location = trackevent.Address.City; sse.CountryCode = trackevent.Address.CountryCode; //other properties (not used yet) //trackevent.EventType; //trackevent.Address.PostalCode; //trackevent.Address.StateOrProvinceCode; //trackevent.StatusExceptionCode; //trackevent.StatusExceptionDescription; result.Add(sse); } } } } //result.AddRange(trackResponse.Shipment.SelectMany(c => c.Package[0].Activity.Select(x => ToStatusEvent(x))).ToList()); } catch (SoapException ex) { var sb = new StringBuilder(); sb.AppendFormat("SoapException Message= {0}.", ex.Message); sb.AppendFormat("SoapException Category:Code:Message= {0}.", ex.Detail.LastChild.InnerText); //sb.AppendFormat("SoapException XML String for all= {0}.", ex.Detail.LastChild.OuterXml); _logger.Error(string.Format("Error while getting Fedex shipment tracking info - {0}", trackingNumber), new Exception(sb.ToString())); } catch (Exception exc) { _logger.Error(string.Format("Error while getting Fedex shipment tracking info - {0}", trackingNumber), exc); } return result; }