/// <summary> /// Gets the tax regime. /// </summary> /// <param name="context">The request context.</param> /// <param name="shippingAddress">Shipping address.</param> /// <returns> /// The sales tax regime information. /// </returns> internal static string GetTaxRegime(RequestContext context, Address shippingAddress) { if (context == null) { throw new ArgumentNullException("context"); } if (context.Runtime == null) { throw new ArgumentNullException("context", "context.Runtime"); } if (shippingAddress == null) { throw new ArgumentNullException("shippingAddress"); } if (string.IsNullOrWhiteSpace(shippingAddress.ThreeLetterISORegionName) && string.IsNullOrWhiteSpace(shippingAddress.TwoLetterISORegionName)) { throw new ArgumentNullException("shippingAddress", "shippingAddress ISORegionName"); } string taxRegime = string.Empty; // If address has a tax group, then return this tax group. if (!string.IsNullOrWhiteSpace(shippingAddress.TaxGroup)) { taxRegime = shippingAddress.TaxGroup; return(taxRegime); } Dictionary <string, string> predicates = new Dictionary <string, string>(); var addressComponentsFilterHandlers = BuildDbtFilterList(); for (int i = 0; i < addressComponentsFilterHandlers.Count; i++) { predicates.Clear(); for (int j = i; j < addressComponentsFilterHandlers.Count; j++) { if (addressComponentsFilterHandlers[j].CanHandle(shippingAddress)) { addressComponentsFilterHandlers[j].Handle(shippingAddress, predicates); } } GetSalesTaxGroupDataRequest dataRequest = new GetSalesTaxGroupDataRequest(predicates); taxRegime = context.Execute <SingleEntityDataServiceResponse <string> >(dataRequest).Entity; if (!string.IsNullOrWhiteSpace(taxRegime)) { break; } } if (string.IsNullOrWhiteSpace(taxRegime)) { InvalidTaxGroupNotification notification = new InvalidTaxGroupNotification(shippingAddress); context.Notify(notification); } return(taxRegime); }
/// <summary> /// Gets the tax group for India inter-state transaction. /// </summary> /// <param name="context">The request context.</param> /// <param name="inventLocationId">Inventory location id.</param> /// <param name="shippingAddress">Shipping address.</param> /// <param name="isInterState">The flag indicates whether it's inter state.</param> /// <returns> /// The sales tax group information. /// </returns> internal static string GetInterStateTaxRegimeIndia(RequestContext context, string inventLocationId, Address shippingAddress, out bool isInterState) { if (context == null) { throw new ArgumentNullException("context"); } if (context.Runtime == null) { throw new ArgumentException("context.Runtime cannot be null."); } if (shippingAddress == null) { throw new ArgumentNullException("shippingAddress"); } if (string.IsNullOrWhiteSpace(shippingAddress.ThreeLetterISORegionName) && string.IsNullOrWhiteSpace(shippingAddress.TwoLetterISORegionName)) { throw new ArgumentNullException("shippingAddress", "shippingAddress ISORegionName"); } string taxRegime = string.Empty; isInterState = false; bool isApplyInterStateTax = false; if (!string.IsNullOrWhiteSpace(inventLocationId)) { GetApplyInterstateTaxIndiaDataRequest getApplyInterstateTaxIndiaDataRequest = new GetApplyInterstateTaxIndiaDataRequest(QueryResultSettings.SingleRecord); ApplyInterStateTaxIndia interStateTaxSetting = context.Runtime.Execute <SingleEntityDataServiceResponse <ApplyInterStateTaxIndia> >(getApplyInterstateTaxIndiaDataRequest, context).Entity; if (interStateTaxSetting != null) { isApplyInterStateTax = interStateTaxSetting.IsApplyInterStateTaxIndia; } if (isApplyInterStateTax) { GetWarehouseAddressIndiaDataRequest getWarehouseAddressIndiaDataRequest = new GetWarehouseAddressIndiaDataRequest(inventLocationId, QueryResultSettings.SingleRecord); Address shippingFromAddress = context.Runtime.Execute <SingleEntityDataServiceResponse <Address> >(getWarehouseAddressIndiaDataRequest, context).Entity; if (shippingFromAddress != null && (shippingFromAddress.ThreeLetterISORegionName == shippingAddress.ThreeLetterISORegionName) && !string.IsNullOrWhiteSpace(shippingFromAddress.State) && !string.IsNullOrWhiteSpace(shippingAddress.State) && (shippingFromAddress.State != shippingAddress.State)) { isInterState = true; } if (isInterState) { GetTaxRegimeIndiaDataRequest getTaxRegimeIndiaDataRequest = new GetTaxRegimeIndiaDataRequest(QueryResultSettings.SingleRecord); taxRegime = context.Runtime.Execute <SingleEntityDataServiceResponse <string> >(getTaxRegimeIndiaDataRequest, context).Entity; if (string.IsNullOrWhiteSpace(taxRegime)) { InvalidTaxGroupNotification notification = new InvalidTaxGroupNotification(shippingFromAddress); context.Notify(notification); } } } } return(taxRegime); }