private ShippingRate CreateShippingRate( Guid methodId, ShippingMethodDto shippingMethod, EstimateResult <ShipmentEstimate> result) { var estimate = result.Estimates.First(); var priceExclTax = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceExclTax) == "True"; var usesAdditionalServices = !string.IsNullOrEmpty(shippingMethod.GetShippingMethodParameterValue(ParameterNames.AdditionalServices)); var priceWithAdditionalServices = !priceExclTax ? (decimal)estimate.PackagePrice.PackagePriceWithAdditionalServices.AmountWithVAT : (decimal)estimate.PackagePrice.PackagePriceWithAdditionalServices.AmountWithoutVAT; var priceWithoutAdditionalServices = !priceExclTax ? (decimal)estimate.PackagePrice.PackagePriceWithoutAdditionalServices.AmountWithVAT : (decimal)estimate.PackagePrice.PackagePriceWithoutAdditionalServices.AmountWithoutVAT; var amount = AdjustPrice(shippingMethod, usesAdditionalServices ? priceWithAdditionalServices : priceWithoutAdditionalServices); var moneyAmount = new Money( amount, new Currency(estimate.PackagePrice.CurrencyIdentificationCode)); return(new BringShippingRate( methodId, estimate.GuiInformation.DisplayName, estimate.GuiInformation.MainDisplayCategory, estimate.GuiInformation.SubDisplayCategory, estimate.GuiInformation.DescriptionText, estimate.GuiInformation.HelpText, estimate.GuiInformation.Tip, estimate.ExpectedDelivery.ExpectedDeliveryDate, moneyAmount)); }
public IEstimateSettings CreateFrom(ShippingMethodDto shippingMethod) { var productId = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.BringProductId, null); var customerNumber = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.BringCustomerNumber, null); var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(BringShippingGateway.ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod.GetShippingOptionParameterValue(BringShippingGateway.ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); var ediParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.Edi, "true"); bool.TryParse(ediParameter, out var edi); var postingAtPostOfficeParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PostingAtPostOffice, "false"); bool.TryParse(postingAtPostOfficeParameter, out var postingAtPostOffice); var additionalServicesCodes = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.AdditionalServices); var services = additionalServicesCodes.Split(',') .Select(code => AdditionalService.All.FirstOrDefault(x => x.Code == code)) .Where(service => service != null); var priceExclTaxParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceExclTax); bool.TryParse(priceExclTaxParameter, out var priceExclTax); var priceRoundingParameterParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceRounding, "false"); bool.TryParse(priceRoundingParameterParameter, out bool priceRounding); var priceAdjustmentPercentParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceAdjustmentPercent, "0"); int.TryParse(priceAdjustmentPercentParameter, out var priceAdjustmentPercent); var priceAdjustmentOperatorParameter = shippingMethod.GetShippingMethodParameterValue(BringShippingGateway.ParameterNames.PriceAdjustmentOperator, "true"); bool.TryParse(priceAdjustmentOperatorParameter, out var priceAdjustmentAdd); return(new BringEstimateSettings { BringProductId = productId, BringCustomerNumber = customerNumber, PostalCodeFrom = postalCodeFrom, CountryCodeFrom = countryCodeFrom, Edi = edi, PostingAtPostOffice = postingAtPostOffice, PriceExclTax = priceExclTax, PriceAdjustmentIsAddition = priceAdjustmentAdd, PriceAdjustmentPercent = priceAdjustmentPercent, PriceRounding = priceRounding, AdditionalServices = services }); }
private ShipmentLeg CreateShipmentLeg(IShipment shipment, ShippingMethodDto shippingMethod) { var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod .GetShippingOptionParameterValue(ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); if (string.IsNullOrEmpty(shipment.WarehouseCode) == false) { var warehouse = _warehouseRepository.Get(shipment.WarehouseCode); var warehousePostalCode = warehouse.ContactInformation?.PostalCode; var warehouseCountryCode = warehouse.ContactInformation?.CountryCode; if (string.IsNullOrEmpty(warehousePostalCode) == false && warehouse.IsPickupLocation) { postalCodeFrom = warehousePostalCode; countryCodeFrom = warehouseCountryCode.ToIso2CountryCode(); } } var countryCodeTo = shipment.ShippingAddress.CountryCode.ToIso2CountryCode(); return(new ShipmentLeg(postalCodeFrom, shipment.ShippingAddress.PostalCode, countryCodeFrom, countryCodeTo)); }
private static ShipmentLeg CreateShipmentLeg(OrderAddress orderAddress, ShippingMethodDto shippingMethod) { var postalCodeFrom = shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostalCodeFrom, null) ?? shippingMethod.GetShippingOptionParameterValue(ParameterNames.PostalCodeFrom); var countryCodeFrom = shippingMethod .GetShippingOptionParameterValue(ParameterNames.CountryFrom, "NOR") .ToIso2CountryCode(); var countryCodeTo = orderAddress.CountryCode.ToIso2CountryCode(); return(new ShipmentLeg(postalCodeFrom, orderAddress.PostalCode, countryCodeFrom, countryCodeTo)); }
private decimal AdjustPrice(ShippingMethodDto shippingMethod, decimal price) { var shippingMethodRow = shippingMethod.ShippingMethod[0]; var amount = shippingMethodRow.BasePrice + price; bool priceRounding; if (bool.TryParse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceRounding, "false"), out priceRounding) && priceRounding) { return(Math.Round(amount, MidpointRounding.AwayFromZero)); } return(amount); }
private static IEnumerable <IQueryParameter> CreateAdditionalParameters(ShippingMethodDto shippingMethod) { var hasEdi = bool.Parse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.Edi, "true")); yield return(new Edi(hasEdi)); var shippedFromPostOffice = bool.Parse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostingAtPostOffice, "false")); yield return(new ShippedFromPostOffice(shippedFromPostOffice)); var productCode = shippingMethod.GetShippingMethodParameterValue(ParameterNames.BringProductId, null) ?? Product.Servicepakke.Code; yield return(new Products(Product.GetByCode(productCode))); var additionalServicesCodes = shippingMethod.GetShippingMethodParameterValue(ParameterNames.AdditionalServices); var services = additionalServicesCodes.Split(',') .Select(code => AdditionalService.All.FirstOrDefault(x => x.Code == code)) .Where(service => service != null); yield return(new AdditionalServices(services.ToArray())); }
private IEnumerable <IShippingQueryParameter> CreateAdditionalParameters(ShippingMethodDto shippingMethod) { var hasEdi = bool.Parse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.Edi, "true")); yield return(new Edi(hasEdi)); var shippedFromPostOffice = bool.Parse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PostingAtPostOffice, "false")); yield return(new ShippedFromPostOffice(shippedFromPostOffice)); int priceAdjustmentPercent; int.TryParse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceAdjustmentPercent, "0"), out priceAdjustmentPercent); if (priceAdjustmentPercent > 0) { bool priceAdjustmentAdd; bool.TryParse(shippingMethod.GetShippingMethodParameterValue(ParameterNames.PriceAdjustmentOperator, "true"), out priceAdjustmentAdd); yield return(priceAdjustmentAdd ? PriceAdjustment.IncreasePercent(priceAdjustmentPercent) : PriceAdjustment.DecreasePercent(priceAdjustmentPercent)); } var productCode = shippingMethod.GetShippingMethodParameterValue(ParameterNames.BringProductId, null) ?? Product.Servicepakke.Code; yield return(new Products(Product.GetByCode(productCode))); var customerNumber = shippingMethod.GetShippingMethodParameterValue(ParameterNames.BringCustomerNumber, null); if (!string.IsNullOrWhiteSpace(customerNumber)) { yield return(new CustomerNumber(customerNumber)); } var additionalServicesCodes = shippingMethod.GetShippingMethodParameterValue(ParameterNames.AdditionalServices); var services = additionalServicesCodes.Split(',') .Select(code => AdditionalService.All.FirstOrDefault(x => x.Code == code)) .Where(service => service != null); yield return(new AdditionalServices(services.ToArray())); }