예제 #1
0
        public IActionResult TestTaxRequest(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
                return AccessDeniedView();

            if (!ModelState.IsValid)
                return Configure();

            //get result
            var transaction = _avalaraTaxManager.CreateTestTaxTransaction(new Address
            {
                City = model.TestAddress?.City,
                CountryId = model.TestAddress?.CountryId,
                Address1 = model.TestAddress?.Address1,
                ZipPostalCode = model.TestAddress?.ZipPostalCode,
                StateProvinceId = model.TestAddress?.StateProvinceId
            });

            var testTaxResult = string.Empty;
            if (transaction?.totalTax != null)
            {
                //display tax rates by jurisdictions
                testTaxResult = $"Total tax rate: {transaction.totalTax:0.00}% {Environment.NewLine}";
                if (transaction.summary?.Any() ?? false)
                {
                    testTaxResult = transaction.summary.Aggregate(testTaxResult, (resultString, rate) =>
                        $"{resultString}Jurisdiction: {rate?.jurisName}, Tax rate: {(rate?.rate ?? 0) * 100:0.00}% {Environment.NewLine}");
                }
                _notificationService.SuccessNotification(_localizationService.GetResource("Plugins.Tax.Avalara.TestTax.Success"));
            }
            else
                _notificationService.ErrorNotification(_localizationService.GetResource("Plugins.Tax.Avalara.TestTax.Error"));

            return Configure(testTaxResult);
        }