public List <IShippingRate> RateShipment(IShipment shipment) { var totalItems = 0; foreach (var item in shipment.Items) { totalItems += item.QuantityOfItemsInBox; } decimal amount = 0; if (Settings != null) { if (Settings.GetLevels() != null) { var level = RateTableLevel.FindRateForLevel(totalItems, Settings.GetLevels()); if (level != null && level.Rate >= 0) { amount = level.Rate; } } } var r = new ShippingRate { ServiceId = Id, EstimatedCost = amount }; var rates = new List <IShippingRate> { r }; return(rates); }
public List <IShippingRate> RateShipment(IShipment shipment) { decimal totalValue = 0; foreach (IShippable item in shipment.Items) { totalValue += item.BoxValue; } decimal amount = 0; if (Settings != null) { if (Settings.GetLevels() != null) { amount = RateTableLevel.FindRateFromLevels(totalValue, Settings.GetLevels()); } } ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = amount; List <IShippingRate> rates = new List <IShippingRate>(); rates.Add(r); return(rates); }
/// <summary> /// Gets a test zone rate. /// </summary> /// <param name="project">Zone to include</param> /// <param name="zone">Zone</param> /// <returns>ZoneRate</returns> public static ZoneRate GetTestZoneRate(Project.Project project, Zone zone) { List <ShippingRate> shippingRates = new List <ShippingRate>(); foreach (string currency in project.Currencies) { Money money = new Money(); money.CentAmount = Helper.GetRandomNumber(99, 9999); money.CurrencyCode = currency; ShippingRate shippingRate = new ShippingRate(); shippingRate.Price = money; shippingRates.Add(shippingRate); } Reference zoneReference = new Reference(); zoneReference.Id = zone.Id; zoneReference.ReferenceType = Common.ReferenceType.Zone; ZoneRate zoneRate = new ZoneRate(); zoneRate.Zone = zoneReference; zoneRate.ShippingRates = shippingRates; return(zoneRate); }
private ShippingMethodAndRate GetShippingRateInfo(ShippingMethodDto.ShippingMethodRow row, Shipment shipment) { ShippingMethodAndRate returnRate = null; string nameAndRate = string.Empty; // Check if package contains shippable items, if it does not use the default shipping method instead of the one specified Type type = Type.GetType(row.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(row.ShippingOptionRow.ClassName, null); } string outputMessage = string.Empty; IShippingGateway provider = (IShippingGateway)Activator.CreateInstance(type); if (shipment != null) { ShippingRate rate = provider.GetRate(row.ShippingMethodId, shipment, ref outputMessage); nameAndRate = string.Format("{0} : {1}", row.Name, rate.Money.Amount.ToString("C")); returnRate = new ShippingMethodAndRate(row.Name, nameAndRate, rate.Money.Amount, row.ShippingMethodId); } return(returnRate); }
public ActionResult AddRate([Bind(Prefix = "Form")]ShippingAddRateForm form, int country) { if (ModelState.IsValid) { var rate = new ShippingRate { Name = form.Name, Country = _session.Load<Country>(country), ShippingPrice = form.ShippingPrice }; switch (form.Type) { case "weight": rate.MinOrderWeight = form.MinWeight; rate.MaxOrderWeight = form.MaxWeight; break; case "price": rate.MinOrderPrice = form.MinPrice; rate.MaxOrderPrice = form.MaxPrice; break; default: throw new NotSupportedException(); } _session.Save(rate); TempData["SuccessMessage"] = "Shipping rate has been added"; return RedirectToAction("Index"); } var model = new ShippingAddRateViewModel(); SetupAddRateViewModel(model, country); return View(model); }
public static ShippingRate RatePackage(FedExGlobalServiceSettings globals, ILogger logger, FedExServiceSettings settings, IShipment package) { var result = new ShippingRate(); // Get ServiceType var currentServiceType = (ServiceType)settings.ServiceCode; // Get PackageType var currentPackagingType = (PackageType)settings.Packaging; // Set max weight by service var carCode = GetCarrierCode(currentServiceType); // set the negotiated rates to true, or the setting in the local settings var useNegotiatedRates = !settings.ContainsKey("UseNegotiatedRates") || bool.Parse(settings["UseNegotiatedRates"]); result.EstimatedCost = RateSinglePackage(globals, logger, package, currentServiceType, currentPackagingType, carCode, useNegotiatedRates); return(result); }
public static ShippingRate RatePackage(FedExGlobalServiceSettings globals, MerchantTribe.Web.Logging.ILogger logger, FedExServiceSettings settings, IShipment package) { ShippingRate result = new ShippingRate(); // Get ServiceType ServiceType currentServiceType = ServiceType.FEDEXGROUND; currentServiceType = (ServiceType)settings.ServiceCode; // Get PackageType PackageType currentPackagingType = PackageType.YOURPACKAGING; currentPackagingType = (PackageType)settings.Packaging; // Set max weight by service CarrierCodeType carCode = GetCarrierCode(currentServiceType); result.EstimatedCost = RateSinglePackage(globals, logger, package, currentServiceType, currentPackagingType, carCode); return(result); }
public List<IShippingRate> RateShipment(IShipment shipment) { int totalItems = 0; foreach (IShippable item in shipment.Items) { totalItems += item.QuantityOfItemsInBox; } decimal amountPerItem = 0; if (Settings != null) { if (Settings.GetLevels() != null) { amountPerItem = RateTableLevel.FindRateFromLevels(totalItems, Settings.GetLevels()); } } ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = amountPerItem * totalItems; List<IShippingRate> rates = new List<IShippingRate>(); rates.Add(r); return rates; }
public List <IShippingRate> RateShipment(IShipment shipment) { int totalItems = 0; foreach (IShippable item in shipment.Items) { totalItems += item.QuantityOfItemsInBox; } decimal amountPerItem = 0; if (Settings != null) { if (Settings.GetLevels() != null) { amountPerItem = RateTableLevel.FindRateFromLevels(totalItems, Settings.GetLevels()); } } ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = amountPerItem * totalItems; List <IShippingRate> rates = new List <IShippingRate>(); rates.Add(r); return(rates); }
public async Task AddShipmentAsync_ShipmentFound_MustContainSameShipment() { // Arrange var cartAggregate = GetValidCartAggregate(); var shipment = new Shipment { ShipmentMethodCode = "shippingMethodCode", ShipmentMethodOption = "OptionName", Price = 777, }; var shippingRate = new ShippingRate { OptionName = "OptionName", ShippingMethod = new StubShippingMethod("shippingMethodCode"), Rate = 777, }; var shippingRates = new List <ShippingRate> { shippingRate }; cartAggregate.Cart.Shipments = new List <Shipment> { shipment }; // Act await cartAggregate.AddShipmentAsync(shipment, shippingRates); // Assert cartAggregate.Cart.Shipments.Should().Contain(shipment); }
public CheckoutOrderInfo() { cart = new Cart(); appliedCoupons = new List <CheckoutCouponInfo>(); BillingAddress = new AddressInfo(); BillingAddress.PropertyChanged += BillingAddress_PropertyChanged; BillingAddress.EnablePropertyChangeEvent = true; ShipToBillingAddress = null; ShippingAddress = new AddressInfo(); //ShippingAddress.PropertyChanged += ShippingAddress_PropertyChanged; //ShippingOption = new ShippingOption(); ShippingRate = new ShippingRate(); CreditCard = new CreditCardInfo(); PaymentProvider = PaymentProviderName.UNKNOWN; PayPalVariables = new Dictionary <string, string>(); SubTotal = 0; DiscountAmount = 0; //ShippingAmount = 0; TaxAmount = 0; Total = 0; OrderNotes = String.Empty; }
public async Task <Checkout> SetShippingRateAsync(ShippingRate shippingRate) { Checkout.ShippingRate = shippingRate; Checkout = await BuyClient.UpdateCheckoutAsync(Checkout); return(Checkout); }
public List <IShippingRate> RateShipment(IShipment shipment) { decimal totalWeight = 0; foreach (var item in shipment.Items) { totalWeight += item.BoxWeight; } decimal amount = 0; if (Settings != null) { if (Settings.GetLevels() != null) { var level = RateTableLevel.FindRateForLevel(totalWeight, Settings.GetLevels()); amount = level.Rate; } } var r = new ShippingRate { ServiceId = Id, EstimatedCost = amount }; var rates = new List <IShippingRate> { r }; return(rates); }
public List<IShippingRate> RateShipment(IShipment shipment) { decimal totalValue = 0; foreach (IShippable item in shipment.Items) { totalValue += item.BoxValue; } decimal amount = 0; if (Settings != null) { if (Settings.GetLevels() != null) { amount = RateTableLevel.FindRateFromLevels(totalValue, Settings.GetLevels()); } } ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = amount; List<IShippingRate> rates = new List<IShippingRate>(); rates.Add(r); return rates; }
public ShipmentViewModelFactoryTests() { var market = new MarketImpl(new MarketId(Currency.USD)); _cart = new FakeCart(market, Currency.USD) { Name = "Default" }; _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Code = "code" }); _cart.Forms.Single().CouponCodes.Add("couponcode"); _shippingManagerFacadeMock = new Mock <ShippingManagerFacade>(null, null); _shippingManagerFacadeMock.Setup(x => x.GetShippingMethodsByMarket(It.IsAny <string>(), It.IsAny <bool>())).Returns(() => new List <ShippingMethodInfoModel> { new ShippingMethodInfoModel { LanguageId = CultureInfo.InvariantCulture.TwoLetterISOLanguageName, Currency = Currency.USD } }); _shippingRate = new ShippingRate(Guid.NewGuid(), "name", new Money(10, Currency.USD)); _shippingManagerFacadeMock.Setup(x => x.GetRate(It.IsAny <IShipment>(), It.IsAny <ShippingMethodInfoModel>(), It.IsAny <IMarket>())) .Returns(_shippingRate); var languageServiceMock = new Mock <LanguageService>(null, null, null); languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(CultureInfo.InvariantCulture); var addressBookServiceMock = new Mock <IAddressBookService>(); _addressModel = new AddressModel(); addressBookServiceMock.Setup(x => x.ConvertToModel(It.IsAny <IOrderAddress>())).Returns(_addressModel); _cartItem = new CartItemViewModel(); var cartItemViewModelFactoryMock = new Mock <CartItemViewModelFactory>(null, null, null, null, null, null); cartItemViewModelFactoryMock.Setup(x => x.CreateCartItemViewModel(It.IsAny <ICart>(), It.IsAny <ILineItem>(), It.IsAny <VariationContent>())).Returns(_cartItem); var catalogContentServiceMock = new Mock <CatalogContentService>(null, null, null, null, null, null, null); catalogContentServiceMock.Setup(x => x.GetItems <EntryContentBase>(It.IsAny <IEnumerable <string> >())) .Returns(() => new List <VariationContent> { new VariationContent { Code = "code" } }); _marketServiceMock = new Mock <IMarketService>(); _marketServiceMock.Setup(x => x.GetMarket(It.IsAny <MarketId>())).Returns(market); _subject = new ShipmentViewModelFactory( catalogContentServiceMock.Object, _shippingManagerFacadeMock.Object, languageServiceMock.Object, addressBookServiceMock.Object, cartItemViewModelFactoryMock.Object, _marketServiceMock.Object); }
public void UpdateShipment(Shipment shipment, ShippingRate shippingCost) { shipment.ShippingMethodId = shippingCost.Id; shipment.ShippingMethodName = shippingCost.Name; shipment.SubTotal = shippingCost.Money.Amount; shipment.ShippingSubTotal = shippingCost.Money.Amount; shipment.AcceptChanges(); }
public void SetShippingRate(ShippingRate shippingRate, Action <Checkout, Response> success, Action <RetrofitError> failure) { Checkout.ShippingRate = shippingRate; BuyClient.UpdateCheckout(Checkout, (data, response) => { Checkout = data; success(data, response); }, failure); }
public void ShouldCreateValidCartValueTier() { var data = "{\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 400\r\n },\r\n \"tiers\": [{\r\n \"type\" : \"CartValue\",\r\n \"minimumCentAmount\": 5000,\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 300\r\n }\r\n },\r\n {\r\n \"type\" : \"CartValue\",\r\n \"minimumCentAmount\": 7500,\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 200\r\n }\r\n },\r\n {\r\n \"type\" : \"CartValue\",\r\n \"minimumCentAmount\": 1000,\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 0\r\n }\r\n }\r\n ]\r\n }"; ShippingRate shippingRate = JsonConvert.DeserializeObject <ShippingRate>(data); Assert.IsInstanceOf <CartValueTier>(shippingRate.Tiers[0]); Assert.IsInstanceOf <CartValueTier>(shippingRate.Tiers[1]); }
public ShippingRate GetShippingRate() { ShippingRate rate = new ShippingRate() { Price = Money.Parse("1.00 EUR"), FreeAbove = Money.Parse("100.00 EUR") }; return(rate); }
public void ShouldCreateValidCartClassificationTier() { var data = "{\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 1000\r\n },\r\n \"tiers\": [{\r\n \"type\" : \"CartClassification\",\r\n \"value\": \"Medium\",\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 2500\r\n }\r\n },\r\n {\r\n \"type\" : \"CartClassification\",\r\n \"value\": \"Heavy\",\r\n \"price\": {\r\n \"currencyCode\": \"EUR\",\r\n \"centAmount\": 5000\r\n }\r\n }\r\n ]\r\n }"; ShippingRate shippingRate = JsonConvert.DeserializeObject <ShippingRate>(data); Assert.IsInstanceOf <CartClassificationTier>(shippingRate.Tiers[0]); Assert.IsInstanceOf <CartClassificationTier>(shippingRate.Tiers[1]); }
public static ShippingRate GetShippingRate() { ShippingRate rate = new ShippingRate() { Price = Money.FromDecimal("EUR", 1), FreeAbove = Money.FromDecimal("EUR", 100) }; return(rate); }
public void ShouldCreateValidCartScoreTier() { var data = "{\r\n \"price\": {\r\n \"currencyCode\": \"USD\",\r\n \"centAmount\": 500\r\n },\r\n \"tiers\": [{\r\n \"type\" : \"CartScore\",\r\n \"score\": 5,\r\n \"price\": {\r\n \"currencyCode\": \"USD\",\r\n \"centAmount\": 750\r\n }\r\n },\r\n {\r\n \"type\" : \"CartScore\",\r\n \"score\": 10,\r\n \"price\": {\r\n \"currencyCode\": \"USD\",\r\n \"centAmount\": 1000\r\n }\r\n },\r\n {\r\n \"type\" : \"CartScore\",\r\n \"score\": 15,\r\n \"priceFunction\": {\r\n \"currencyCode\": \"USD\",\r\n \"function\": \"(50 * x) + 750\"\r\n }\r\n }\r\n ]\r\n }"; ShippingRate shippingRate = JsonConvert.DeserializeObject <ShippingRate>(data); Assert.IsInstanceOf <CartScoreTier>(shippingRate.Tiers[0]); Assert.IsInstanceOf <CartScoreTier>(shippingRate.Tiers[1]); }
// When the user selects a shipping rate, set that rate on the checkout and proceed to the discount activity. private void OnShippingRateSelected(ShippingRate shippingRate) { ShowLoadingDialog(Resource.String.syncing_data); SampleApplication.SetShippingRate(shippingRate, delegate { DismissLoadingDialog(); StartActivity(new Intent(this, typeof(DiscountActivity))); }, OnError); }
public List<IShippingRate> RateShipment(IShipment shipment) { ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = Settings.Amount; List<IShippingRate> rates = new List<IShippingRate>(); rates.Add(r); return rates; }
public List <IShippingRate> RateShipment(IShipment shipment) { ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = Settings.Amount; List <IShippingRate> rates = new List <IShippingRate>(); rates.Add(r); return(rates); }
public List <IShippingRate> RateShipment(IShipment shipment) { var r = new ShippingRate { ServiceId = Id, EstimatedCost = Settings.Amount }; var rates = new List <IShippingRate> { r }; return(rates); }
public CartShipmentValidatorTests() { _shippingRate = new ShippingRate { OptionName = ":)", ShippingMethod = new StubShippingMethod("shippingMethodCode"), Rate = 777, }; _context.AvailShippingRates = new List <ShippingRate>() { _shippingRate }; }
private List <IShippingRate> RatePackages(List <Shipment> packages) { var result = new List <IShippingRate>(); // Loop through packages, getting rates for each package var allPackagesRated = true; var individualRates = new List <ShippingRate>(); foreach (IShipment s in packages) { var singlePackageRate = new ShippingRate(); singlePackageRate = RateService.RatePackage(GlobalSettings, _Logger, Settings, s); if (singlePackageRate == null) { allPackagesRated = false; break; } if (singlePackageRate.EstimatedCost < 0) { allPackagesRated = false; break; } individualRates.Add(singlePackageRate); } // we are done with all packages for this shipping type if (allPackagesRated) { var total = individualRates.Sum(rate => rate.EstimatedCost); if (total <= 0m) { return(result); } if (individualRates.Count > 0) { result.Add( new ShippingRate { EstimatedCost = total, DisplayName = "FedEx:" + FindNameByServiceCode(Settings.ServiceCode), ServiceCodes = Settings.ServiceCode.ToString(), ServiceId = Id }); } } return(result); }
public ShipmentViewModelFactoryTests() { _cart = new FakeCart(new MarketImpl(new MarketId(Currency.USD)), Currency.USD) { Name = "Default" }; _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Code = "code"}); _cart.Forms.Single().CouponCodes.Add("couponcode"); var shippingManagerFacadeMock = new Mock<ShippingManagerFacade>(); shippingManagerFacadeMock.Setup(x => x.GetShippingMethodsByMarket(It.IsAny<string>(), It.IsAny<bool>())).Returns(() => new List<ShippingMethodInfoModel> { new ShippingMethodInfoModel { LanguageId = CultureInfo.InvariantCulture.TwoLetterISOLanguageName, Currency = Currency.USD } }); _shippingRate = new ShippingRate(Guid.NewGuid(), "name", new Money(10, Currency.USD)); shippingManagerFacadeMock.Setup(x => x.GetRate(It.IsAny<IShipment>(), It.IsAny<ShippingMethodInfoModel>(), It.IsAny<IMarket>())) .Returns(_shippingRate); var languageServiceMock = new Mock<LanguageService>(null, null, null, null); languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(CultureInfo.InvariantCulture); var referenceConverterMock = new Mock<ReferenceConverter>(null,null); var addressBookServiceMock = new Mock<IAddressBookService>(); _addressModel = new AddressModel(); addressBookServiceMock.Setup(x => x.ConvertToModel(It.IsAny<IOrderAddress>())).Returns(_addressModel); _cartItem = new CartItemViewModel (); var cartItemViewModelFactoryMock = new Mock<CartItemViewModelFactory>(null,null,null,null,null,null,null,null,null,null, null); cartItemViewModelFactoryMock.Setup(x => x.CreateCartItemViewModel(It.IsAny<ICart>(), It.IsAny<ILineItem>(), It.IsAny<VariationContent>())).Returns(_cartItem); var contentLoaderMock = new Mock<IContentLoader>(); contentLoaderMock.Setup(x => x.GetItems(It.IsAny<IEnumerable<ContentReference>>(), It.IsAny<CultureInfo>())) .Returns(() => new List<VariationContent> {new VariationContent {Code = "code"} }); var relationRepositoryMock = new Mock<IRelationRepository>(); relationRepositoryMock.Setup(x => x.GetRelationsByTarget<ProductVariation>(It.IsAny<ContentReference>())) .Returns(() => new[] {new ProductVariation {Source = new ContentReference(1)}}); _subject = new ShipmentViewModelFactory( contentLoaderMock.Object, shippingManagerFacadeMock.Object, languageServiceMock.Object, referenceConverterMock.Object, addressBookServiceMock.Object, cartItemViewModelFactoryMock.Object, () => CultureInfo.GetCultureInfo("en"), relationRepositoryMock.Object); }
/// <summary> /// Processes the shipments. /// </summary> private void ProcessShipments() { ShippingMethodDto methods = ShippingManager.GetShippingMethods(Thread.CurrentThread.CurrentUICulture.Name); OrderGroup order = OrderGroup; // request rates, make sure we request rates not bound to selected delivery method foreach (OrderForm form in order.OrderForms) { foreach (Shipment shipment in form.Shipments) { ShippingMethodDto.ShippingMethodRow row = methods.ShippingMethod.FindByShippingMethodId(shipment.ShippingMethodId); // If shipping method is not found, set it to 0 and continue if (row == null) { Logger.Info(String.Format("Total shipment is 0 so skip shipment calculations.")); shipment.ShipmentTotal = 0; continue; } // Check if package contains shippable items, if it does not use the default shipping method instead of the one specified Logger.Debug(String.Format("Getting the type \"{0}\".", row.ShippingOptionRow.ClassName)); Type type = Type.GetType(row.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(row.ShippingOptionRow.ClassName, null); } string message = String.Empty; Logger.Debug(String.Format("Creating instance of \"{0}\".", type.Name)); IShippingGateway provider = (IShippingGateway)Activator.CreateInstance(type); List <LineItem> items = Shipment.GetShipmentLineItems(shipment); Logger.Debug(String.Format("Calculating the rates.")); ShippingRate rate = provider.GetRate(row.ShippingMethodId, items.ToArray(), ref message); if (rate != null) { Logger.Debug(String.Format("Rates calculated.")); shipment.ShipmentTotal = rate.Price; } else { Logger.Debug(String.Format("No rates has been found.")); } } } }
// When the user selects a shipping rate, set that rate on the checkout and proceed to the discount activity. private async Task OnShippingRateSelectedAsync(ShippingRate shippingRate) { ShowLoadingDialog(Resource.String.syncing_data); try { await SampleApplication.SetShippingRateAsync(shippingRate); DismissLoadingDialog(); StartActivity(new Intent(this, typeof(DiscountActivity))); } catch (ShopifyException ex) { OnError(ex.Error); } }
private ZoneRateDraft GetNewZoneRateDraft(string country = null) { Zone zone = this.CreateNewZone(country); ShippingRate shippingRate = this.GetShippingRate(); ZoneRateDraft zoneRateDraft = new ZoneRateDraft() { Zone = new ResourceIdentifier <Zone> { Key = zone.Key }, ShippingRates = new List <ShippingRate>() { shippingRate } }; return(zoneRateDraft); }
public async Task <ActionResult> ValidateCert() { string certificateFile = Server.MapPath($"~/{ConfigurationManager.AppSettings["KCCCertificateFileName"]}"); var cert = new X509Certificate2(certificateFile, ConfigurationManager.AppSettings["KCCCertificatePassword"]); var handler = new HttpClientHandler(); handler.ClientCertificates.Add(cert); var httpClient = new HttpClient(handler); //httpClient.BaseAddress = new Uri(ConfigurationManager.AppSettings["TodoListBaseAddress"].ToString()); var apiCaller = new ProtectedApiCallHelper(httpClient); // ApiResponse result = await apiCaller.CallWebApiAndProcessResultASync("/api/todolist"); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; var request = new HttpRequestMessage() { RequestUri = new Uri($"{ConfigurationManager.AppSettings["ApiGatewayBaseAddress"]}/ShippingRates/ByName/LTLWeightCutoff"), Method = HttpMethod.Get, }; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Add("Ocp-Apim-Trace", "true"); request.Headers.Add("Ocp-Apim-Subscription-Key", ConfigurationManager.AppSettings["ApiGatewaySubsKey"]); APIResponse result = await apiCaller.CallWebApiAndProcessResultASync(request); ShippingRate rate = null; if (result.Result != null) { ViewBag.Result = result.Result.ToString(); rate = result.Result as ShippingRate; } if (!string.IsNullOrEmpty(result.ErrorMessage)) { ViewBag.ErrorMessage = $"Error Code: {result.ErrorCode}, ErrorMessage:{result.ErrorMessage}"; } return(View(rate)); }
public List<IShippingRate> RateShipment(IShipment shipment) { int totalItems = 0; foreach (IShippable item in shipment.Items) { totalItems += item.QuantityOfItemsInBox; } decimal perItemAmount = Settings.Amount; ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = perItemAmount * totalItems; List<IShippingRate> rates = new List<IShippingRate>(); rates.Add(r); return rates; }
public List <IShippingRate> RateShipment(IShipment shipment) { List <IShippingRate> rates = new List <IShippingRate>(); // Total Up Weight decimal totalWeight = 0; foreach (IShippable item in shipment.Items) { totalWeight += item.BoxWeight; } // Check for max weight if (totalWeight > Settings.MaxWeight || totalWeight < Settings.MinWeight) { return(rates); } // Calculate Overage decimal extraWeight = 0; if (totalWeight > Settings.BaseWeight) { extraWeight = totalWeight - Settings.BaseWeight; } int extraWeightWhole = (int)Math.Ceiling(extraWeight); // Base + Overage Charges decimal theRate = Settings.BaseAmount + (extraWeightWhole * Settings.AdditionalWeightCharge); ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = theRate; rates.Add(r); return(rates); }
public List <IShippingRate> RateShipment(IShipment shipment) { var rates = new List <IShippingRate>(); // Total Up Weight decimal totalWeight = 0; foreach (var item in shipment.Items) { totalWeight += item.BoxWeight; } // Check for max weight if (totalWeight > Settings.MaxWeight || totalWeight < Settings.MinWeight) { return(rates); } // Calculate Overage decimal extraWeight = 0; if (totalWeight > Settings.BaseWeight) { extraWeight = totalWeight - Settings.BaseWeight; } var extraWeightWhole = (int)Math.Ceiling(extraWeight); // Base + Overage Charges var theRate = Settings.BaseAmount + extraWeightWhole * Settings.AdditionalWeightCharge; var r = new ShippingRate { ServiceId = Id, EstimatedCost = theRate }; rates.Add(r); return(rates); }
public List<IShippingRate> RateShipment(IShipment shipment) { List<IShippingRate> rates = new List<IShippingRate>(); // Total Up Weight decimal totalWeight = 0; foreach (IShippable item in shipment.Items) { totalWeight += item.BoxWeight; } // Check for max weight if (totalWeight > Settings.MaxWeight || totalWeight < Settings.MinWeight) { return rates; } // Calculate Overage decimal extraWeight = 0; if (totalWeight > Settings.BaseWeight) { extraWeight = totalWeight - Settings.BaseWeight; } int extraWeightWhole = (int)Math.Ceiling(extraWeight); // Base + Overage Charges decimal theRate = Settings.BaseAmount + (extraWeightWhole * Settings.AdditionalWeightCharge); ShippingRate r = new ShippingRate(); r.ServiceId = this.Id; r.EstimatedCost = theRate; rates.Add(r); return rates; }
private List<SampleOrderResult> GetSampleOrders(GridViewRow row, out int count) { GridView grid = (GridView) row.FindControl("SampleShippingCosts"); OrderRule rule = new OrderRule(Rules.DataKeys[row.RowIndex].Value.ToString()); rule.Matches.AddRange( ((BVModules_Shipping_Order_Rules_OrderMatchEditor) row.FindControl("OrderMatchEditor")).GetMatches()); rule.Value = Decimal.Parse(((TextBox) row.FindControl("ValueField")).Text); rule.ValueCustomProperty = ((DropDownList) row.FindControl("ValueCustomPropertyField")).SelectedValue; rule.ValueItemPropertyAsString = ((DropDownList) row.FindControl("ValueItemPropertyField")).SelectedValue; rule.ValuePackagePropertyAsString = ((DropDownList) row.FindControl("ValuePackagePropertyField")).SelectedValue; rule.ValuePropertyAsString = ((DropDownList) row.FindControl("ValueOrderPropertyField")).SelectedValue; count = 0; // Scan all placed orders List<SampleOrderResult> results = new List<SampleOrderResult>(); foreach (Order order in Order.FindByCriteria(new OrderSearchCriteria())) { Order heavyOrder = Order.FindByBvin(order.Bvin); // "Unship" all of the items so that the samples look like they // were just placed. Skip any orders with deleted items. bool skipOrder = false; foreach (LineItem lineitem in heavyOrder.Items) { if (lineitem.AssociatedProduct == null || lineitem.AssociatedProduct.ShippingMode == ShippingMode.None) skipOrder = true; else lineitem.QuantityShipped = 0; } if (skipOrder) break; if (rule.IsMatch(heavyOrder)) { count += 1; if (count > grid.PageSize*5) break; SampleOrderResult result = new SampleOrderResult(); result.OrderNumber = order.OrderNumber; result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a>", Page.ResolveUrl( string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}", order.Bvin)), order.OrderNumber); List<string> matchValues = new List<string>(); List<string> limitValues = new List<string>(); if (rule.IsDefaultRule) { matchValues.Add("n/a"); limitValues.Add("n/a"); } else { for (int index = 0; index < rule.Matches.Count; index++) { OrderMatch match = rule.Matches[index]; string matchValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.OrderProperty, match.PackageProperty, match.ItemProperty, match.CustomProperty, "1").ToString(); if (string.IsNullOrEmpty(matchValue)) matchValue = "(empty)"; matchValues.Add(matchValue); string limitValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.LimitOrderProperty, match.LimitPackageProperty, match.LimitItemProperty, match.LimitCustomProperty, match.Limit).ToString(); if (string.IsNullOrEmpty(limitValue)) limitValue = "(empty)"; limitValues.Add(limitValue); } } result.MatchValues = string.Join(", ", matchValues.ToArray()); result.LimitValues = string.Join(", ", limitValues.ToArray()); object value = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, rule.ValueOrderProperty, rule.ValuePackageProperty, rule.ValueItemProperty, rule.ValueCustomProperty, "1"); result.Value = value == null ? "n/a" : value.ToString(); if (String.IsNullOrEmpty(result.Value)) result.Value = "(empty)"; ShippingRate rate = new ShippingRate(((OrderRulesEditor) NamingContainer).NameFieldText, string.Empty, string.Empty, 0, string.Empty); decimal? cost = rule.GetCost(heavyOrder); if (cost.HasValue) { rate.Rate = cost.Value; result.RateDisplay = rate.RateAndNameForDisplay; } else { result.RateDisplay = "Hidden"; } results.Add(result); } } results.Sort(); return results; }
public void SetShippingRate(ShippingRate shippingRate, Action<Checkout, Response> success, Action<RetrofitError> failure) { Checkout.ShippingRate = shippingRate; BuyClient.UpdateCheckout(Checkout, (data, response) => { Checkout = data; success(data, response); }, failure); }