/// <summary> /// Gets tax /// </summary> /// <param name="cart">Shopping cart</param> /// <param name="paymentMethodId">Payment method identifier</param> /// <param name="customer">Customer</param> /// <param name="error">Error</param> /// <returns>Tax total</returns> public static decimal GetTaxTotal(ShoppingCart cart, int paymentMethodId, Customer customer, ref string error) { decimal taxTotal = decimal.Zero; //items decimal itemsTaxTotal = decimal.Zero; foreach (var shoppingCartItem in cart) { string error1 = string.Empty; string error2 = string.Empty; decimal subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), false, customer, ref error1); decimal subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), true, customer, ref error2); if (!String.IsNullOrEmpty(error1)) { error = error1; } if (!String.IsNullOrEmpty(error2)) { error = error2; } decimal shoppingCartItemTax = subTotalWithoutDiscountInclTax - subTotalWithoutDiscountExclTax; itemsTaxTotal += shoppingCartItemTax; } //checkout attributes decimal checkoutAttributesTax = decimal.Zero; if (customer != null) { var caValues = CheckoutAttributeHelper.ParseCheckoutAttributeValues(customer.CheckoutAttributes); foreach (var caValue in caValues) { string error1 = string.Empty; string error2 = string.Empty; decimal caExclTax = TaxManager.GetCheckoutAttributePrice(caValue, false, customer, ref error1); decimal caInclTax = TaxManager.GetCheckoutAttributePrice(caValue, true, customer, ref error2); if (!String.IsNullOrEmpty(error1)) { error = error1; } if (!String.IsNullOrEmpty(error2)) { error = error2; } decimal caTax = caInclTax - caExclTax; checkoutAttributesTax += caTax; } } //shipping decimal shippingTax = decimal.Zero; if (TaxManager.ShippingIsTaxable) { string error1 = string.Empty; string error2 = string.Empty; decimal?shippingExclTax = ShippingManager.GetShoppingCartShippingTotal(cart, customer, false, ref error1); decimal?shippingInclTax = ShippingManager.GetShoppingCartShippingTotal(cart, customer, true, ref error2); if (!String.IsNullOrEmpty(error1)) { error = error1; } if (!String.IsNullOrEmpty(error2)) { error = error2; } if (shippingExclTax.HasValue && shippingInclTax.HasValue) { shippingTax = shippingInclTax.Value - shippingExclTax.Value; } } //payment method additional fee decimal paymentMethodAdditionalFeeTax = decimal.Zero; if (TaxManager.PaymentMethodAdditionalFeeIsTaxable) { string error1 = string.Empty; string error2 = string.Empty; decimal paymentMethodAdditionalFee = PaymentManager.GetAdditionalHandlingFee(paymentMethodId); decimal?paymentMethodAdditionalFeeExclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, false, customer, ref error1); decimal?paymentMethodAdditionalFeeInclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, true, customer, ref error2); if (!String.IsNullOrEmpty(error1)) { error = error1; } if (!String.IsNullOrEmpty(error2)) { error = error2; } if (paymentMethodAdditionalFeeExclTax.HasValue && paymentMethodAdditionalFeeInclTax.HasValue) { paymentMethodAdditionalFeeTax = paymentMethodAdditionalFeeInclTax.Value - paymentMethodAdditionalFeeExclTax.Value; } } taxTotal = itemsTaxTotal + checkoutAttributesTax + shippingTax + paymentMethodAdditionalFeeTax; taxTotal = Math.Round(taxTotal, 2); return(taxTotal); }
/// <summary> /// Gets tax /// </summary> /// <param name="Cart">Shopping cart</param> /// <param name="PaymentMethodID">Payment method identifier</param> /// <param name="customer">Customer</param> /// <param name="Error">Error</param> /// <returns>Tax total</returns> public static decimal GetTaxTotal(ShoppingCart Cart, int PaymentMethodID, Customer customer, ref string Error) { decimal taxTotal = decimal.Zero; //items decimal itemsTaxTotal = decimal.Zero; foreach (ShoppingCartItem shoppingCartItem in Cart) { decimal subTotalWithoutDiscountExclTax = decimal.Zero; decimal subTotalWithoutDiscountInclTax = decimal.Zero; string Error1 = string.Empty; string Error2 = string.Empty; subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), false, customer, ref Error1); subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), true, customer, ref Error2); if (!String.IsNullOrEmpty(Error1)) { Error = Error1; } if (!String.IsNullOrEmpty(Error2)) { Error = Error2; } decimal shoppingCartItemTax = subTotalWithoutDiscountInclTax - subTotalWithoutDiscountExclTax; itemsTaxTotal += shoppingCartItemTax; } //shipping decimal shippingTax = decimal.Zero; if (TaxManager.ShippingIsTaxable) { string Error3 = string.Empty; string Error4 = string.Empty; decimal?shippingExclTax = ShippingManager.GetShoppingCartShippingTotal(Cart, customer, false, ref Error3); decimal?shippingInclTax = ShippingManager.GetShoppingCartShippingTotal(Cart, customer, true, ref Error4); if (!String.IsNullOrEmpty(Error3)) { Error = Error3; } if (!String.IsNullOrEmpty(Error4)) { Error = Error4; } if (shippingExclTax.HasValue && shippingInclTax.HasValue) { shippingTax = shippingInclTax.Value - shippingExclTax.Value; } } //payment method additional fee decimal paymentMethodAdditionalFeeTax = decimal.Zero; if (TaxManager.PaymentMethodAdditionalFeeIsTaxable) { string Error5 = string.Empty; string Error6 = string.Empty; decimal paymentMethodAdditionalFee = PaymentManager.GetAdditionalHandlingFee(PaymentMethodID); decimal?paymentMethodAdditionalFeeExclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, false, customer, ref Error5); decimal?paymentMethodAdditionalFeeInclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, true, customer, ref Error6); if (!String.IsNullOrEmpty(Error5)) { Error = Error5; } if (!String.IsNullOrEmpty(Error6)) { Error = Error6; } if (paymentMethodAdditionalFeeExclTax.HasValue && paymentMethodAdditionalFeeInclTax.HasValue) { paymentMethodAdditionalFeeTax = paymentMethodAdditionalFeeInclTax.Value - paymentMethodAdditionalFeeExclTax.Value; } } taxTotal = itemsTaxTotal + shippingTax + paymentMethodAdditionalFeeTax; taxTotal = Math.Round(taxTotal, 2); return(taxTotal); }