public void flatrateshipping_ignore_zerocost()
        {
            // don't transform methods if they are zero cost
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 0,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1);
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1 });
            var result    = ApplyFlatRateShipping(worksheet, estimates, "027", null);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(method1.Cost, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
        }
        public async Task free_shipping_for_no_rates()
        {
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 370,
                SupplierID   = "010"
            };
            var method1 = new HSShipMethod
            {
                ID = "NO_SHIPPING_RATES",
                xp = new ShipMethodXP()
            };
            var worksheet = BuildOrderWorksheet(new HSLineItem[] { line1 });
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1 });
            var result    = await estimates.ApplyShippingLogic(worksheet, _oc, FREE_SHIPPING_DAYS);

            var methods = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(0, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
            Assert.IsTrue(methods[0].xp.FreeShippingApplied);
        }
        public void handle_methods_with_same_rates()
        {
            // handle two estimates with same rates
            // we do not want to filter out a slower estimate with the same rate
            var method1 = new HSShipMethod
            {
                EstimatedTransitDays = 1,
                Cost = 15
            };
            var method2 = new HSShipMethod
            {
                EstimatedTransitDays = 2,
                Cost = 15
            };
            var method3 = new HSShipMethod
            {
                EstimatedTransitDays = 3,
                Cost = 5
            };
            var estimates = BuildEstimates(new[] { method1, method2, method3 });
            var result    = CheckoutIntegrationCommand.FilterSlowerRatesWithHighCost(estimates);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(3, methods.Count);
            Assert.AreEqual(15, methods[0].Cost);
            Assert.AreEqual(1, methods[0].EstimatedTransitDays);
            Assert.AreEqual(5, methods[2].Cost);
            Assert.AreEqual(3, methods[2].EstimatedTransitDays);
        }
        public void dont_filter_valid_rates()
        {
            // preserve order, rates are already correct
            var method1 = new HSShipMethod
            {
                EstimatedTransitDays = 1,
                Cost = 25
            };
            var method2 = new HSShipMethod
            {
                EstimatedTransitDays = 2,
                Cost = 15
            };
            var method3 = new HSShipMethod
            {
                EstimatedTransitDays = 3,
                Cost = 5
            };
            var estimates = BuildEstimates(new[] { method1, method2, method3 });
            var result    = CheckoutIntegrationCommand.FilterSlowerRatesWithHighCost(estimates);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(3, methods.Count);
            Assert.AreEqual(25, methods[0].Cost);
            Assert.AreEqual(15, methods[1].Cost);
            Assert.AreEqual(5, methods[2].Cost);
        }
        public void handle_free_shipping()
        {
            // handle free shipping
            var method1 = new HSShipMethod
            {
                EstimatedTransitDays = 1,
                Cost = 15
            };
            var method2 = new HSShipMethod
            {
                EstimatedTransitDays = 2,
                Cost = 0
            };
            var method3 = new HSShipMethod
            {
                EstimatedTransitDays = 3,
                Cost = 5
            };
            var estimates = BuildEstimates(new[] { method1, method2, method3 });
            var result    = CheckoutIntegrationCommand.FilterSlowerRatesWithHighCost(estimates);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(2, methods.Count);
            Assert.AreEqual(15, methods[0].Cost);
            Assert.AreEqual(0, methods[1].Cost);
        }
        public void handle_mixed_order_by_transit_days()
        {
            // remove two offending ship methods, transit days ordered backwards
            var method1 = new HSShipMethod
            {
                EstimatedTransitDays = 3,
                Cost = 15
            };
            var method2 = new HSShipMethod
            {
                EstimatedTransitDays = 2,
                Cost = 10
            };
            var method3 = new HSShipMethod
            {
                EstimatedTransitDays = 1,
                Cost = 5
            };
            var estimates = BuildEstimates(new[] { method1, method2, method3 });
            var result    = CheckoutIntegrationCommand.FilterSlowerRatesWithHighCost(estimates);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count);
            Assert.AreEqual(5, methods[0].Cost);
        }
        public async Task shipping_ignore_zerocostAsync()
        {
            // don't transform methods if they are zero cost
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 0,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(new HSLineItem[] { line1 });
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1 });
            var result    = await estimates.ApplyShippingLogic(worksheet, _oc, FREE_SHIPPING_DAYS);

            var methods = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(method1.Cost, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
        }
        public void remove_two_invalid_methods()
        {
            // remove two offending ship methods
            var method1 = new HSShipMethod
            {
                EstimatedTransitDays = 1,
                Cost = 5
            };
            var method2 = new HSShipMethod
            {
                EstimatedTransitDays = 2,
                Cost = 10
            };
            var method3 = new HSShipMethod
            {
                EstimatedTransitDays = 3,
                Cost = 15
            };
            var estimates = BuildEstimates(new[] { method1, method2, method3 });
            var result    = CheckoutIntegrationCommand.FilterSlowerRatesWithHighCost(estimates);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count);
            Assert.AreEqual(5, methods[0].Cost);
        }
        public void flatrateshipping_handle_second_tier()
        {
            // set shipping cost to $0 if line item cost is greater than $499.99
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 602,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1);
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1 });
            var result    = ApplyFlatRateShipping(worksheet, estimates, "027", null);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(FLAT_RATE_SECOND_TIER, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
        }
Exemplo n.º 10
0
 public static ZohoLineItem Map(ZohoLineItem item, HSShipMethod method)
 {
     item.item_id              = item.item_id;
     item.item_type            = "sales_and_purchases";
     item.name                 = $"Shipping: {method.Name}";
     item.rate                 = Math.Round(decimal.ToDouble(method.Cost), 2);
     item.description          = $"{method.Name} - {method.EstimatedTransitDays} days transit";
     item.sku                  = item.sku;
     item.quantity             = 1;
     item.unit                 = "each";
     item.purchase_description = $"{method.Name} - {method.EstimatedTransitDays} days transit";
     item.avatax_tax_code      = "FR";
     return(item);
 }
        public void flatrateshipping_multiple_methods_with_nonqualifyingflatrate()
        {
            // If DOESNT qualify for flat rate shipping then dont modify the rates
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var shipItem2 = new ShipEstimateItem
            {
                LineItemID = "Line2"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 250,
                SupplierID   = "027"
            };
            var line2 = new HSLineItem
            {
                ID           = "Line2",
                LineSubtotal = 130,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "SOMETHING_ELSE",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var method2 = new HSShipMethod
            {
                Name = "PRIORITY_OVERNIGHT",
                EstimatedTransitDays = 1,
                Cost = 120,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1, line2);
            var estimates = BuildEstimates(new[] { method1, method2 }, new[] { shipItem1, shipItem2 });
            var result    = ApplyFlatRateShipping(worksheet, estimates, "027", null);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(2, methods.Count());
            Assert.AreEqual(method1.Cost, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
            Assert.AreEqual(method2.Cost, methods[1].Cost);
            Assert.AreEqual(method2.Name, methods[1].Name);
        }
        public static HSShipMethod ApplyFlatRateShippingOnShipmethod(HSShipMethod method, decimal supplierSubTotal)
        {
            if (supplierSubTotal > .01M && supplierSubTotal <= 499.99M)
            {
                method.Cost = 29.99M;
            }
            else if (supplierSubTotal > 499.9M)
            {
                method.Cost = 0;
                method.xp.FreeShippingApplied = true;
            }

            return(method);
        }
        public void flatrateshipping_multiple_methods_with_qualifyingflatrate()
        {
            // If qualifies for flat rate shipping then the only rate that should be returned is the modified ground option
            // this test ensures the non-ground option is stripped out
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var shipItem2 = new ShipEstimateItem
            {
                LineItemID = "Line2"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 250,
                SupplierID   = "027"
            };
            var line2 = new HSLineItem
            {
                ID           = "Line2",
                LineSubtotal = 130,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var method2 = new HSShipMethod
            {
                Name = "PRIORITY_OVERNIGHT",
                EstimatedTransitDays = 1,
                Cost = 120,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1, line2);
            var estimates = BuildEstimates(new[] { method1, method2 }, new[] { shipItem1, shipItem2 });
            var result    = ApplyFlatRateShipping(worksheet, estimates, "027", null);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(FLAT_RATE_FIRST_TIER, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
        }
Exemplo n.º 14
0
        public static ZohoLineItem Map(HSShipMethod method)
        {
            var item = new ZohoLineItem()
            {
                item_type            = "sales_and_purchases",
                sku                  = method.ShippingSku(),
                rate                 = Math.Round(decimal.ToDouble(method.Cost), 2),
                description          = $"{method.Name} - {method.EstimatedTransitDays} days transit",
                name                 = $"Shipping: {method.Name}",
                quantity             = 1,
                unit                 = "each",
                purchase_description = $"{method.Name} - {method.EstimatedTransitDays} days transit",
                avatax_tax_code      = "FR"
            };

            return(item);
        }
Exemplo n.º 15
0
        public async Task <JObject> GetOrderAsync(string ID, VerifiedUserContext user)
        {
            //TODO: BaseUrl cannot be found here
            var ocAuth = await _ocSeller.AuthenticateAsync();

            HSShipEstimate estimate;
            HSShipMethod   ship_method       = null;
            var            supplierWorksheet = await _ocSeller.IntegrationEvents.GetWorksheetAsync <HSOrderWorksheet>(OrderDirection.Outgoing, ID, ocAuth.AccessToken);

            var buyerWorksheet = await _ocSeller.IntegrationEvents.GetWorksheetAsync <HSOrderWorksheet>(OrderDirection.Incoming, ID.Split('-')[0], ocAuth.AccessToken);

            var buyerLineItems = buyerWorksheet.GetBuyerLineItemsBySupplierID(supplierWorksheet.Order.ToCompanyID);

            if (buyerWorksheet?.ShipEstimateResponse != null && buyerWorksheet?.ShipEstimateResponse?.ShipEstimates.Count > 0)
            {
                estimate    = buyerWorksheet.GetMatchingShipEstimate(supplierWorksheet?.LineItems?.FirstOrDefault()?.ShipFromAddressID);
                ship_method = estimate?.ShipMethods?.FirstOrDefault(m => m.ID == estimate.SelectedShipMethodID);
            }

            var returnObject = new JObject {
            };

            if (supplierWorksheet.Order != null)
            {
                returnObject.Add(new JProperty("SupplierOrder", new JObject {
                    { "Order", JToken.FromObject(supplierWorksheet?.Order) },
                    new JProperty("LineItems", JToken.FromObject(supplierWorksheet?.LineItems))
                }));
            }

            if (buyerWorksheet.Order != null)
            {
                returnObject.Add(new JProperty("BuyerOrder", new JObject {
                    { "Order", JToken.FromObject(buyerWorksheet?.Order) },
                    new JProperty("LineItems", JToken.FromObject(buyerLineItems))
                }));
            }

            if (ship_method != null)
            {
                returnObject.Add(new JProperty("ShipMethod", JToken.FromObject(ship_method)));
            }
            return(JObject.FromObject(returnObject));
        }
        public void flatrateshipping_handle_first_tier_multiple_lines()
        {
            // set shipping cost to $29.99 if line item cost is between 0.01$ and $499.99
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Line1"
            };
            var shipItem2 = new ShipEstimateItem
            {
                LineItemID = "Line2"
            };
            var line1 = new HSLineItem
            {
                ID           = "Line1",
                LineSubtotal = 200,
                SupplierID   = "027"
            };
            var line2 = new HSLineItem
            {
                ID           = "Line2",
                LineSubtotal = 250,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1, line2);
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1, shipItem2 });
            var result    = ApplyFlatRateShipping(worksheet, estimates, "027", null);
            var methods   = result[0].ShipMethods;

            Assert.AreEqual(1, methods.Count());
            Assert.AreEqual(FLAT_RATE_FIRST_TIER, methods[0].Cost);
            Assert.AreEqual(method1.Name, methods[0].Name);
        }
Exemplo n.º 17
0
 public static string ShippingSku(this HSShipMethod method)
 {
     return($"{method?.Name} {ShippingSuffix}");
 }
        public void flatrateshipping_handle_multiple_estimates()
        {
            // set shipping cost to $0 if line item cost is greater than $499.99
            var shipItem1 = new ShipEstimateItem
            {
                LineItemID = "Supplier1Line1"
            };
            var shipitem2 = new ShipEstimateItem
            {
                LineItemID = "Supplier2Line1"
            };
            var line1 = new HSLineItem
            {
                ID           = "Supplier1Line1",
                LineSubtotal = 110,
                SupplierID   = "010"
            };
            var line2 = new HSLineItem
            {
                ID           = "Supplier1Line2",
                LineSubtotal = 125,
                SupplierID   = "010"
            };
            var line3 = new HSLineItem
            {
                ID           = "Supplier2Line1",
                LineSubtotal = 130,
                SupplierID   = "027"
            };
            var line4 = new HSLineItem
            {
                ID           = "Supplier2Line2",
                LineSubtotal = 180,
                SupplierID   = "027"
            };
            var method1 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 1,
                Cost = 80,
                xp   = new ShipMethodXP {
                }
            };
            var method2 = new HSShipMethod
            {
                Name = "FEDEX_GROUND",
                EstimatedTransitDays = 3,
                Cost = 60,
                xp   = new ShipMethodXP {
                }
            };
            var worksheet = BuildOrderWorksheet(line1, line2, line3, line4);
            var estimates = BuildEstimates(new[] { method1 }, new[] { shipItem1 });

            estimates.AddRange(BuildEstimates(new[] { method2 }, new[] { shipitem2 }));
            var result = ApplyFlatRateShipping(worksheet, estimates, "027", null);

            Assert.AreEqual(2, result.Count());
            // compare first shipment item from first estimate (no changes because its not medline supplier)
            Assert.AreEqual(1, result[0].ShipMethods.Count());
            Assert.AreEqual(method1.Name, result[0].ShipMethods[0].Name);
            Assert.AreEqual(method1.Cost, result[0].ShipMethods[0].Cost);

            // compare first shipment item from second estimate (cost falls in first tier between $0.01 and $499.9)
            Assert.AreEqual(1, result[0].ShipMethods.Count());
            Assert.AreEqual(method2.Name, result[1].ShipMethods[0].Name);
            Assert.AreEqual(29.99M, result[1].ShipMethods[0].Cost);
        }