Exemplo n.º 1
0
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();
            var cart            = commerceContext?.GetObjects <Cart>().FirstOrDefault();
            var totals          = commerceContext?.GetObjects <CartTotals>().FirstOrDefault();

            if (cart == null || !cart.Lines.Any() || (totals == null || !totals.Lines.Any()))
            {
                return;
            }

            var list = MatchingLines(context).ToList();

            if (!list.Any())
            {
                return;
            }

            list.ForEach(line =>
            {
                if (!totals.Lines.ContainsKey(line.Id))
                {
                    return;
                }

                var propertiesModel = commerceContext.GetObject <PropertiesModel>();
                var discount        = commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount;
                var d = Convert.ToDecimal(PercentOff.Yield(context) * 0.01) * totals.Lines[line.Id].SubTotal.Amount;
                if (commerceContext.GetPolicy <GlobalPricingPolicy>().ShouldRoundPriceCalc)
                {
                    d = decimal.Round(d, commerceContext.GetPolicy <GlobalPricingPolicy>().RoundDigits,
                                      commerceContext.GetPolicy <GlobalPricingPolicy>().MidPointRoundUp
                            ? MidpointRounding.AwayFromZero
                            : MidpointRounding.ToEven);
                }

                var amount            = d * decimal.MinusOne;
                var adjustments       = line.Adjustments;
                var awardedAdjustment = new CartLineLevelAwardedAdjustment
                {
                    Name           = propertiesModel?.GetPropertyValue("PromotionText") as string ?? discount,
                    DisplayName    = propertiesModel?.GetPropertyValue("PromotionCartText") as string ?? discount,
                    Adjustment     = new Money(commerceContext.CurrentCurrency(), amount),
                    AdjustmentType = discount,
                    IsTaxable      = false,
                    AwardingBlock  = nameof(CartItemsPreviouslyPurchasedPercentOffAction)
                };

                adjustments.Add(awardedAdjustment);
                totals.Lines[line.Id].SubTotal.Amount = totals.Lines[line.Id].SubTotal.Amount + amount;
                line.GetComponent <MessagesComponent>().AddMessage(commerceContext.GetPolicy <KnownMessageCodePolicy>().Promotions, $"PromotionApplied: {propertiesModel?.GetPropertyValue("PromotionId") ?? nameof(CartItemsPreviouslyPurchasedPercentOffAction)}");
            });
        }
        private void SetFulfillmentFeeAward(CommercePipelineExecutionContext context, CartLineComponent cartLineComponent, FulfillmentFee fulfillmentFee)
        {
            var awardedAdjustment = new CartLineLevelAwardedAdjustment()
            {
                Name                = FulfillmentConstants.AwardedAdjustmentAttributes.FulfillmentFeeAttributeName,
                DisplayName         = FulfillmentConstants.AwardedAdjustmentAttributes.FulfillmentFeeAttributeName,
                Adjustment          = fulfillmentFee.Fee,
                AdjustmentType      = context.GetPolicy <KnownCartAdjustmentTypesPolicy>().Fulfillment,
                IsTaxable           = false,
                AwardingBlock       = this.Name,
                IncludeInGrandTotal = false
            };

            context.Logger.LogDebug(string.Format("{0} - Added fulfillment fee to line:{1} {2}", this.Name, fulfillmentFee.Fee.CurrencyCode, fulfillmentFee.Fee.Amount));

            cartLineComponent.Adjustments.Add(awardedAdjustment);
        }
Exemplo n.º 3
0
        public static CartLineLevelAwardedAdjustment CreateLineLevelAwardedAdjustment(decimal amountOff, string awardingBlock,
                                                                                      string lineItemId, CommerceContext commerceContext)
        {
            var    propertiesModel = commerceContext.GetObject <PropertiesModel>();
            string discount        = commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount;

            var adjustment = new CartLineLevelAwardedAdjustment
            {
                Name           = propertiesModel?.GetPropertyValue("PromotionText") as string ?? discount,
                DisplayName    = propertiesModel?.GetPropertyValue("PromotionCartText") as string ?? discount,
                Adjustment     = new Money(commerceContext.CurrentCurrency(), amountOff),
                AdjustmentType = discount,
                IsTaxable      = false,
                AwardingBlock  = awardingBlock,
                LineItemId     = lineItemId
            };

            return(adjustment);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull(string.Format("{0}: {1}", Name, Constants.Tax.CartNullText));
            Condition.Requires(arg.Lines).IsNotNull(string.Format("{0}: {1}", Name, Constants.Tax.CartLineNullText));

            // get all lines that have fulfillment methods applied
            var list = arg.Lines.Where(line =>
            {
                if (line != null)
                {
                    return(line.HasComponent <FulfillmentComponent>());
                }
                return(false);
            }).Select(l => l).ToList();

            if (!list.Any())
            {
                return(await Task.FromResult(arg));
            }


            var language            = context.CommerceContext.CurrentLanguage();
            var currencyCode        = context.CommerceContext.CurrentCurrency();
            var globalTaxPolicy     = context.GetPolicy <GlobalTaxPolicy>();
            var defaultTaxRate      = globalTaxPolicy.DefaultCartTaxRate;
            var taxRate             = defaultTaxRate;
            var globalPricingPolicy = context.GetPolicy <GlobalPricingPolicy>();
            var avalaraTaxPolicy    = context.GetPolicy <AvalaraPolicy>();


            foreach (var cartLineComponent in list)
            {
                // If it is an electronically transmitted item such as e-book or subscription, charge no tax
                if (cartLineComponent.ChildComponents.OfType <FulfillmentComponent>().FirstOrDefault() is
                    ElectronicFulfillmentComponent)
                {
                    context.Logger.LogDebug(string.Format("{0} - Skipping Tax Calculation for Electronic Delivery", Name));
                }
                else
                {
                    // if there is a delivery address, then charge tax
                    if (cartLineComponent.ChildComponents.OfType <FulfillmentComponent>().FirstOrDefault() is
                        PhysicalFulfillmentComponent)
                    {
                        var cartComponent = cartLineComponent.GetComponent <PhysicalFulfillmentComponent>();
                        ShippingParty = cartComponent?.ShippingParty;

                        if (ShippingParty != null)
                        {
                            var lines = new[]
                            {
                                new
                                {
                                    amount =
                                        double.Parse(
                                            cartLineComponent.Totals.GrandTotal.Amount.ToString(CultureInfo.InvariantCulture)),
                                    description = "Item " + cartLineComponent.ItemId,
                                    itemCode    = cartLineComponent.ItemId,
                                    quantity    = Convert.ToInt32(Math.Ceiling(cartLineComponent.Quantity))
                                }
                            }.ToList();



                            var shipfrom = new
                            {
                                line1      = avalaraTaxPolicy.ShipFromAddressLine1 + " " + avalaraTaxPolicy.ShipFromAddressLine2,
                                city       = avalaraTaxPolicy.ShipFromCity,
                                region     = avalaraTaxPolicy.ShipFromStateOrProvinceCode,
                                country    = avalaraTaxPolicy.ShipFromCountryCode,
                                postalCode = avalaraTaxPolicy.ShipFromPostalCode
                            };

                            var pointOfOrderOrigin = new
                            {
                                line1      = avalaraTaxPolicy.ShipFromAddressLine1 + " " + avalaraTaxPolicy.ShipFromAddressLine2,
                                city       = avalaraTaxPolicy.ShipFromCity,
                                region     = avalaraTaxPolicy.ShipFromStateOrProvinceCode,
                                country    = avalaraTaxPolicy.ShipFromCountryCode,
                                postalCode = avalaraTaxPolicy.ShipFromPostalCode
                            };

                            var shipTo = new
                            {
                                line1      = ShippingParty.Address1,
                                city       = ShippingParty.City,
                                region     = !string.IsNullOrEmpty(ShippingParty.StateCode) ? ShippingParty.StateCode : ShippingParty.State,
                                country    = ShippingParty.CountryCode,
                                postalCode = ShippingParty.ZipPostalCode
                            };


                            var pointOfOrderAcceptance = new
                            {
                                line1      = ShippingParty.Address1,
                                city       = ShippingParty.City,
                                region     = !string.IsNullOrEmpty(ShippingParty.StateCode) ? ShippingParty.StateCode : ShippingParty.State,
                                country    = ShippingParty.CountryCode,
                                postalCode = ShippingParty.ZipPostalCode
                            };

                            var addresses = new
                            {
                                shipFrom               = shipfrom,
                                pointOfOrderOrigin     = pointOfOrderOrigin,
                                shipTo                 = shipTo,
                                pointOfOrderAcceptance = pointOfOrderAcceptance
                            };


                            var avalaraRequest = new
                            {
                                lines           = lines,
                                type            = "SalesInvoice",
                                date            = DateTime.UtcNow.ToLongDateString(),
                                companyCode     = avalaraTaxPolicy.CompanyCode,
                                customerCode    = arg.Id.ToLower().Replace("default", String.Empty).Replace(arg.ShopName.ToLower(), String.Empty),
                                purchaseOrderNo = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                                addresses       = addresses,
                                commit          = false,
                                currencyCode    = currencyCode,
                                description     = arg.Id + "Cart for user" + arg.Id + " Date: " + DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
                            };

                            var url = avalaraTaxPolicy.InProductionMode
                                ? avalaraTaxPolicy.ProductionUrl
                                : avalaraTaxPolicy.TestUrl;



                            var credentials = "Basic " + System.Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", avalaraTaxPolicy.UserName, avalaraTaxPolicy.Password)));
                            var appName     = "MyTestApp";
                            var appVersion  = "1.0";
                            var api_version = "17.6.0-89";

                            var clientHeader = String.Format("{0}; {1}; {2}; {3}; {4}", appName, appVersion, "CSharpRestClient", api_version, "SANDBOX");
                            var client       = new HttpClient();
                            // Setup the request
                            using (var request = new HttpRequestMessage())
                            {
                                request.Method     = new HttpMethod("POST");
                                request.RequestUri = new Uri(url);

                                // Add credentials and client header
                                request.Headers.Add("Authorization", credentials);

                                request.Headers.Add("X-Avalara-Client", clientHeader);


                                // Add payload
                                var json = JsonConvert.SerializeObject(avalaraRequest, SerializerSettings);
                                request.Content = new StringContent(json, Encoding.UTF8, "application/json");


                                // Send
                                var response = client.SendAsync(request).Result;


                                if (response != null && response.IsSuccessStatusCode)
                                {
                                    dynamic contentData = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
                                    var     totalTax    = contentData.totalTax.ToString();

                                    decimal.TryParse(totalTax.ToString(), out taxRate);

                                    response.Dispose();
                                }


                                client.Dispose();
                            }
                        }
                    }

                    var subTotal = cartLineComponent.Adjustments.Where(a => a.IsTaxable)
                                   .Aggregate(decimal.Zero, (current, adjustment) => current + adjustment.Adjustment.Amount);
                    var subTotalRound = new Money(currencyCode,
                                                  (cartLineComponent.Totals.SubTotal.Amount + subTotal) * taxRate);
                    if (globalPricingPolicy.ShouldRoundPriceCalc)
                    {
                        subTotalRound.Amount = decimal.Round(subTotalRound.Amount, globalPricingPolicy.RoundDigits,
                                                             globalPricingPolicy.MidPointRoundUp ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven);
                    }
                    var adjustments       = cartLineComponent.Adjustments;
                    var awardedAdjustment = new CartLineLevelAwardedAdjustment
                    {
                        Name        = Constants.Tax.TaxFee,
                        DisplayName = Constants.Tax.TaxFee,
                        Adjustment  = subTotalRound
                    };

                    var tax = context.GetPolicy <KnownCartAdjustmentTypesPolicy>().Tax;
                    awardedAdjustment.AdjustmentType = tax;

                    awardedAdjustment.AwardingBlock = Name;
                    var taxableFlag = 0;
                    awardedAdjustment.IsTaxable = taxableFlag != 0;
                    var includeinGrandTotalFlag = 0;
                    awardedAdjustment.IncludeInGrandTotal = includeinGrandTotalFlag != 0;
                    adjustments.Add(awardedAdjustment);
                }
            }
            return(await Task.FromResult(arg));
        }
Exemplo n.º 5
0
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();

            if (commerceContext == null)
            {
                return;
            }

            var cart   = commerceContext.GetObject <Cart>();
            var totals = commerceContext.GetObject <CartTotals>();

            if ((cart != null) && cart.Lines.Any() && ((totals != null) && totals.Lines.Any()) == false)
            {
                return;
            }

            var source = new List <CartLineComponent>();

            foreach (var cartLine in cart.Lines.Where(x => x.HasComponent <CartProductComponent>()))
            {
                var firstOrDefault = cartLine.GetComponent <CartProductComponent>().Tags.FirstOrDefault(t => t.Name == this.Tag.Yield(context));
                if (!string.IsNullOrEmpty(firstOrDefault?.Name))
                {
                    source.Add(cartLine);
                }
            }

            if (!source.Any())
            {
                return;
            }

            var model = commerceContext.GetObject <PropertiesModel>();

            if (model == null)
            {
                return;
            }

            foreach (var line in source)
            {
                if (!totals.Lines.ContainsKey(line.Id))
                {
                    continue;
                }

                var discount = commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount;
                var d        = this.Price.Yield(context);
                if (commerceContext.GetPolicy <GlobalPricingPolicy>().ShouldRoundPriceCalc)
                {
                    d = decimal.Round(d, commerceContext.GetPolicy <GlobalPricingPolicy>().RoundDigits, commerceContext.GetPolicy <GlobalPricingPolicy>().MidPointRoundUp ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven);
                }

                decimal amount;

                var currentAmount = totals.Lines[line.Id].SubTotal.Amount;
                if (currentAmount <= d)
                {
                    amount = d - currentAmount;
                    totals.Lines[line.Id].SubTotal.Amount += amount;
                }
                else
                {
                    amount = currentAmount - d;
                    amount = amount * decimal.MinusOne;
                    totals.Lines[line.Id].SubTotal.Amount += amount;
                }

                var item = new CartLineLevelAwardedAdjustment
                {
                    Name           = (string)model.GetPropertyValue("PromotionText"),
                    DisplayName    = (string)model.GetPropertyValue("PromotionCartText"),
                    Adjustment     = new Money(commerceContext.CurrentCurrency(), amount),
                    AdjustmentType = discount,
                    IsTaxable      = false,
                    AwardingBlock  = "CartAllItemsWithTagSpecifyAmountAction"
                };
                line.Adjustments.Add(item);

                line.GetComponent <MessagesComponent>().AddMessage(commerceContext.GetPolicy <KnownMessageCodePolicy>().Promotions, $"PromotionApplied: {model.GetPropertyValue("PromotionId")}");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            // If the cart is not null and has product lines
            if (arg != null && arg.Lines.Any())
            {
                // lop through to reset Shipping for all line that already has fulfilment set.
                foreach (var cartLineComponent in arg.Lines)
                {
                    // Get all adjustment applied to the cartline
                    var adjustments = cartLineComponent.Adjustments;

                    // It there are adjustments
                    if (adjustments != null && adjustments.Count > 0)
                    {
                        // Check if shipping adjustment has been applied by the default fulfillment plugin.
                        var fulfillment = adjustments.FirstOrDefault(x => x.Name.ToLower().Contains("fulfillmentfee"));

                        // If it has been applied, then we can simply replace it with our desired value based on our external APIs or internal apps.
                        if (fulfillment != null)
                        {
                            // Go get you shipping from Fedex or USPS or UPS web service or from Sitecore
                            // This can come from calculating shipping from external source based on items in the cart above or address of the buyer
                            var customShipping = 0.99M;

                            // If already set, or same as the amount set return cart
                            if (customShipping == fulfillment.Adjustment.Amount)
                            {
                                continue;
                            }

                            // Prepare to overide the shipping value
                            var awardedAdjustment = new CartLineLevelAwardedAdjustment
                            {
                                Name        = fulfillment.Name,
                                DisplayName = fulfillment.DisplayName
                            };

                            // convert the new shipping price from decimal to money
                            var money = new Money(context.CommerceContext.CurrentCurrency(), customShipping);

                            // set the money as the new adjustment
                            awardedAdjustment.Adjustment = money;


                            awardedAdjustment.AdjustmentType =
                                context.GetPolicy <KnownCartAdjustmentTypesPolicy>().Fulfillment;

                            // populate other values with that of the default plugin value or change them to suit you.
                            awardedAdjustment.IsTaxable = fulfillment.IsTaxable;

                            // Set the name of the awarding block to that of the current code block
                            awardedAdjustment.AwardingBlock = Name;

                            // Remove the default shipping price
                            adjustments.Remove(fulfillment);

                            // Add the new shipping price
                            adjustments.Add(awardedAdjustment);
                        }
                    }
                }
            }

            // Return cart
            return(await Task.FromResult(arg));
        }
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>(null);
            var cart            = commerceContext?.GetObject <Cart>();
            var totals          = commerceContext?.GetObject <CartTotals>();

            var qualifiedItemsArgument = commerceContext?.GetObject <QualifiedItemsArgument>();

            if (cart == null || qualifiedItemsArgument == null || !qualifiedItemsArgument.QualifiedCartLines.Any() ||
                !cart.Lines.Any() || totals == null || !totals.Lines.Any())
            {
                return;
            }
            var list = cart.Lines.Where(x =>
            {
                var productId = x.GetComponent <CartProductComponent>().Id;


                return(qualifiedItemsArgument.QualifiedCartLines.Any(y =>
                                                                     y.GetComponent <CartProductComponent>().Id == productId));
            }).ToList();


            if (!list.Any())
            {
                return;
            }

            var percentage = PercentOff.Yield(context);

            var name            = commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount;
            var propertiesModel = commerceContext.GetObject <PropertiesModel>();

            list.ForEach(line =>
            {
                var d = percentage * totals.Lines[line.Id].SubTotal.Amount;
                if (commerceContext.GetPolicy <GlobalPricingPolicy>().ShouldRoundPriceCalc)
                {
                    d = decimal.Round(d, commerceContext.GetPolicy <GlobalPricingPolicy>().RoundDigits,
                                      commerceContext.GetPolicy <GlobalPricingPolicy>().MidPointRoundUp
                            ? MidpointRounding.AwayFromZero
                            : MidpointRounding.ToEven);
                }
                var amount      = d * decimal.MinusOne;
                var adjustments = line.Adjustments;

                var adjustment = new CartLineLevelAwardedAdjustment
                {
                    Name           = propertiesModel?.GetPropertyValue("PromotionText") as string ?? name,
                    DisplayName    = propertiesModel?.GetPropertyValue("PromotionCartText") as string ?? name,
                    Adjustment     = new Money(commerceContext.CurrentCurrency(), amount),
                    AdjustmentType = name,
                    IsTaxable      = false,
                    AwardingBlock  = nameof(CartAnyItemSubtotalPercentOffAction)
                };

                adjustments.Add(adjustment);

                var currentPromotionId = context.Fact <CommerceContext>(null)?.GetObject <PropertiesModel>()
                                         .GetPropertyValue("PromotionId")?.ToString();

                qualifiedItemsArgument.RuleMetArguments
                .First(x => x.PromotionId == currentPromotionId && x.ItemId == line.ItemId &&
                       x.PercentageOff == null)
                .PercentageOff = percentage;

                totals.Lines[line.Id].SubTotal.Amount = totals.Lines[line.Id].SubTotal.Amount + amount;
                line.GetComponent <MessagesComponent>().AddMessage(
                    commerceContext.GetPolicy <KnownMessageCodePolicy>().Promotions,
                    string.Format("PromotionApplied: {0}",
                                  propertiesModel?.GetPropertyValue("PromotionId") ??
                                  nameof(CartAnyItemSubtotalPercentOffAction)));
            });
        }
Exemplo n.º 8
0
        /// <summary>
        /// Run
        /// </summary>
        /// <param name="arg">arg</param>
        /// <param name="context"><context/param>
        /// <returns></returns>
        public override Task <Cart> Run(Cart arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull(string.Format("{0}: The cart can not be null", this.Name));
            Condition.Requires(arg.Lines).IsNotNull(string.Format("{0}: The cart lines can not be null", this.Name));

            if (!arg.Lines.Any())
            {
                Task.FromResult(arg);
            }

            List <CartLineComponent> list = arg.Lines
                                            .Where((line =>
            {
                return(line != null
                         ? line.HasComponent <FulfillmentComponent>()
                         : false);
            }))
                                            .Select((l => l))
                                            .ToList();

            if (!list.Any())
            {
                context.Logger.LogDebug(string.Format("{0} - No lines to calculate tax on", this.Name));
                return(Task.FromResult(arg));
            }

            string              currencyCode = context.CommerceContext.CurrentCurrency();
            GenericTaxPolicy    taxPolicy    = context.GetPolicy <GenericTaxPolicy>();
            GlobalPricingPolicy pricePolicy  = context.GetPolicy <GlobalPricingPolicy>();

            context.Logger.LogDebug(string.Format("{0} - Policy:{1}", this.Name, taxPolicy.TaxCalculationEnabled));

            Decimal defaultItemTaxRate = taxPolicy.DefaultItemTaxRate;

            context.Logger.LogDebug(string.Format("{0} - Item Tax Rate:{1}", this.Name, defaultItemTaxRate));

            foreach (CartLineComponent cartLineComponent in list)
            {
                if (taxPolicy.TaxExemptTagsEnabled && cartLineComponent.HasComponent <CartProductComponent>())
                {
                    IList <Tag>        tags     = cartLineComponent.GetComponent <CartProductComponent>().Tags;
                    Func <Tag, string> func     = (t => t.Name);
                    Func <Tag, string> selector = null;
                    if (tags.Select(selector).Contains(taxPolicy.TaxExemptTag, StringComparer.InvariantCultureIgnoreCase))
                    {
                        context.Logger.LogDebug(string.Format("{0} - Skipping Tax Calculation for product {1} due to exempt tag", (object)this.Name, (object)cartLineComponent.ItemId), Array.Empty <object>());
                        continue;
                    }
                }

                Decimal num = cartLineComponent.Adjustments.Where((a => a.IsTaxable)).Aggregate(Decimal.Zero, ((current, adjustment) => current + adjustment.Adjustment.Amount));

                context.Logger.LogDebug(string.Format("{0} - SubTotal:{1}", this.Name, cartLineComponent.Totals.SubTotal.Amount));
                context.Logger.LogDebug(string.Format("{0} - Adjustment Total:{1}", this.Name, num));

                //** Custom Implementation
                // Retrieve the sellable item from commerce context
                var sellableItem = context.CommerceContext.GetEntity <SellableItem>();
                var composerTemplateViewsComponent = sellableItem.GetComponent <ComposerTemplateViewsComponent>().Views.FirstOrDefault(element => element.Value.Equals(GenericTaxesConstants.ComposerViewValue));
                var composerView = sellableItem.GetComposerView(composerTemplateViewsComponent.Key);

                // Extract the needed tax value from custom view property
                string taxValue = composerView.Properties.FirstOrDefault(element => element.Name.Equals(taxPolicy.TaxFieldName)).Value;

                // Cast the string with correct culture to decimal
                if (!decimal.TryParse(taxValue, NumberStyles.Any, this.CultureEn, out decimal taxValueAsDecimal) ||
                    !taxPolicy.Whitelist.Contains(taxValueAsDecimal))
                {
                    context.Logger.LogDebug(string.Format("{0} - Tax Rate: {1} is invalid or not whitelisted", this.Name, taxValue));
                    if (taxPolicy.UseDefaultTaxRateIfNoneIsSet)
                    {
                        taxValueAsDecimal = defaultItemTaxRate;
                    }
                    else
                    {
                        continue;
                    }
                }

                Money money = new Money(currencyCode, (cartLineComponent.Totals.SubTotal.Amount + num) * taxValueAsDecimal);
                if (pricePolicy.ShouldRoundPriceCalc)
                {
                    money.Amount = Decimal.Round(money.Amount, pricePolicy.RoundDigits, pricePolicy.MidPointRoundUp ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven);
                }

                IList <AwardedAdjustment> adjustments = cartLineComponent.Adjustments;
                string taxName = $"TaxFee-{(taxValueAsDecimal * 100)}%";
                CartLineLevelAwardedAdjustment awardedAdjustment = new CartLineLevelAwardedAdjustment
                {
                    Name                = taxName,
                    DisplayName         = taxName,
                    Adjustment          = money,
                    AdjustmentType      = context.GetPolicy <KnownCartAdjustmentTypesPolicy>().Tax,
                    AwardingBlock       = this.Name,
                    IsTaxable           = false,
                    IncludeInGrandTotal = false
                };
                adjustments.Add(awardedAdjustment);
            }

            return(Task.FromResult(arg));
        }