/// <summary> /// Gets available shipping options /// </summary> /// <param name="getShippingOptionRequest">A request for getting shipping options</param> /// <returns>Represents a response of getting shipping rate options</returns> public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest) { if (getShippingOptionRequest == null) { throw new ArgumentNullException("getShippingOptionRequest"); } var response = new GetShippingOptionResponse(); // <endpoint address="http://www.gls.dk/webservices_v3/wsShopFinder.asmx" binding="basicHttpBinding" bindingConfiguration="wsShopFinderSoap" contract="GlsWebService.wsShopFinderSoap" name="wsShopFinderSoap"/> var endpoint = new EndpointAddress(_glsSettings.GatewayUrl); var binding = new BasicHttpBinding(); var glsService = new wsShopFinderSoapClient(binding, endpoint); var street = getShippingOptionRequest.ShippingAddress.Address1; var postalCode = getShippingOptionRequest.ShippingAddress.ZipPostalCode; var countryCode = "DK"; var numberOfResults = _glsSettings.NumberOfSearchResults; var nearestShops = glsService.SearchNearestParcelShops(street, postalCode, countryCode, numberOfResults); if (nearestShops.parcelshops == null || nearestShops.parcelshops.Length < 1) { return(response); } foreach (var pakkeshopData in nearestShops.parcelshops) { var shippingOption = new ShippingOption(); shippingOption.Name = pakkeshopData.CompanyName; shippingOption.Description = GenerateStoreLocationLocation(pakkeshopData); shippingOption.Rate = _glsSettings.Rate; response.ShippingOptions.Add(shippingOption); } return(response); }
public PakkeshopData GetParcelShopData(string parcelNumber) { PakkeshopData parcelShop = null; try { wsShopFinderSoapClient client = new wsShopFinderSoapClient(EndpointConfiguration.wsShopFinderSoap12, _glsSettings.EndpointAddress); parcelShop = client.GetOneParcelShopAsync(parcelNumber).Result; } catch (Exception ex) { _logger.Error(ex.Message, ex); } if (parcelShop == null) { parcelShop = new PakkeshopData(); parcelShop.Number = "0"; parcelShop.Streetname = "Fejl ved hentning af pakkeshop data"; } return(parcelShop); }
public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest) { var response = new GetShippingOptionResponse(); if (_glsSettings.Tracing) { _traceMessages.AppendLine("\r\nReady to validate shipping input"); } AOGLSCountry glsCountry = null; bool validInput = ValidateShippingInfo(getShippingOptionRequest, ref response, ref glsCountry); if (validInput == false && response.Errors != null && response.Errors.Count > 0) { var test = _workContext; return(response); } try { if (_glsSettings.Tracing) { _traceMessages.AppendLine("Ready to prapare GLS call"); } List <PakkeshopData> parcelShops = null; if (glsCountry.SupportParcelShop) { wsShopFinderSoapClient client = new wsShopFinderSoapClient(EndpointConfiguration.wsShopFinderSoap12, _glsSettings.EndpointAddress); string zip = getShippingOptionRequest.ShippingAddress.ZipPostalCode; string street = getShippingOptionRequest.ShippingAddress.Address1; if (_glsSettings.Tracing) { _traceMessages.AppendLine("Ready to call GLS at: '" + _glsSettings.EndpointAddress + "'"); } try { // First try to find a number of shops near the address parcelShops = client.GetParcelShopDropPointAsync(street, zip, glsCountry.TwoLetterGLSCode, _glsSettings.AmountNearestShops).Result.parcelshops.ToList(); } catch (Exception ex) { if (_glsSettings.Tracing) { _traceMessages.AppendLine("Error finding parcelshops: " + ex.ToString()); } } if (parcelShops == null || parcelShops.Count == 0) { try { // If any errors or no shop found, try to find shops from only zip code parcelShops = client.GetParcelShopsInZipcodeAsync(zip, glsCountry.TwoLetterGLSCode).Result.GetParcelShopsInZipcodeResult.ToList(); } catch (Exception ex) { if (_glsSettings.Tracing) { _traceMessages.AppendLine("Error finding parcelshops: " + ex.ToString()); } } } if (_glsSettings.Tracing && parcelShops != null && parcelShops.Count > 0) { _traceMessages.AppendLine(parcelShops.Count + " parcelshops found:"); } if (parcelShops != null && parcelShops.Count > 0) { foreach (var parcelShop in parcelShops) { ShippingOption shippingOption = new ShippingOption() { Name = BuildGLSName(parcelShop), Description = "", ShippingRateComputationMethodSystemName = "GLS", Rate = GetRate(glsCountry.ShippingPrice_0_1) }; response.ShippingOptions.Add(shippingOption); if (_glsSettings.Tracing) { _traceMessages.AppendLine(" - " + shippingOption.Name); } } } } if (parcelShops == null || parcelShops.Count == 0) { Address address = getShippingOptionRequest.ShippingAddress; ShippingOption shippingOption = new ShippingOption() { Name = address.FirstName + " " + address.LastName, Description = BuildDescription(address), ShippingRateComputationMethodSystemName = "GLS", Rate = GetRate(glsCountry.ShippingPrice_0_1) }; response.ShippingOptions.Add(shippingOption); } if (response.ShippingOptions.Any()) { response.Errors.Clear(); } } catch (Exception exc) { while (exc.InnerException != null) { exc = exc.InnerException; } response.AddError($"GLS Service is currently unavailable, try again later. {exc.ToString()}"); if (_glsSettings.Tracing) { _traceMessages.AppendLine($"GLS Service is currently unavailable, try again later. {exc.ToString()}"); } } finally { if (_glsSettings.Tracing && _traceMessages.Length > 0) { var shortMessage = $"GLS Shipping Options for customer {getShippingOptionRequest.Customer.Email}. {getShippingOptionRequest.Items.Count} item(s) in cart (See more in full message)"; _logger.Information(shortMessage, new Exception(_traceMessages.ToString()), getShippingOptionRequest.Customer); } } return(response); }