Example #1
0
        /// <summary>
        /// Calculate tax
        /// </summary>
        /// <param name="Input">Input</param>
        /// <returns>CalculateTaxOut</returns>
        public async Task <CalculateTaxOut> CalculateTaxAsync(CalculateTaxIn Input)
        {
            // verify the required parameter 'Input' is set
            if (Input == null)
            {
                throw new ApiException(400, "Missing required parameter 'Input' when calling CalculateTax");
            }


            var path = "/api/v1/tax/calculate";

            path = path.Replace("{format}", "json");


            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, String>();
            String postBody     = null;



            postBody = this.apiClient.Serialize(Input); // http body (model) parameter


            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)await this.apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) == 400)
            {
                // This is to get around an API change where insufficient evidence now returns a
                // 400 error code but all the data we need is still there.
                var transaction = (Transaction)this.apiClient.Deserialize(response.Content, typeof(Transaction));
                return(new CalculateTaxOut {
                    Transaction = transaction
                });
            }

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling CalculateTax: " + response.Content, response.Content);
            }
            return((CalculateTaxOut)this.apiClient.Deserialize(response.Content, typeof(CalculateTaxOut)));
        }
Example #2
0
        public async Task <TaxamoCalculationResult> ExecuteAsync(
            PositiveInt amount,
            string billingCountryCode,
            string creditCardPrefix,
            string ipAddress,
            string originalTaxamoTransactionKey,
            UserType userType)
        {
            amount.AssertNotNull("amount");

            var apiKey = this.taxamoApiKeyRepository.GetApiKey(userType);

            var input = new CalculateTaxIn
            {
                Transaction = new InputTransaction
                {
                    CurrencyCode     = PaymentConstants.Usd,
                    TransactionLines = new List <InputTransactionLine>
                    {
                        new InputTransactionLine
                        {
                            CustomId = CreateTaxamoTransaction.CustomId,
                            Amount   = new AmountInMinorDenomination(amount.Value).ToMajorDenomination()
                        }
                    },
                    BuyerCreditCardPrefix = creditCardPrefix,
                    BuyerIp                = ipAddress,
                    BillingCountryCode     = billingCountryCode,
                    OriginalTransactionKey = originalTaxamoTransactionKey
                }
            };

            var result = await this.taxamoService.CalculateTaxAsync(input, apiKey);

            var countryDetected = this.IsCountryDetected(result);

            return(new TaxamoCalculationResult(
                       result.Transaction.Amount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.Amount.Value),
                       result.Transaction.TotalAmount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.TotalAmount.Value),
                       result.Transaction.TaxAmount == null ? null : AmountInMinorDenomination.FromMajorDenomination(result.Transaction.TaxAmount.Value),
                       result.Transaction.TransactionLines[0].TaxRate,
                       result.Transaction.TransactionLines[0].TaxName,
                       result.Transaction.TaxEntityName,
                       countryDetected ? result.Transaction.CountryName : null,
                       countryDetected ? null : this.GetPossibleCountries(result)));
        }
Example #3
0
        /// <summary>
        /// Calculate tax
        /// </summary>
        /// <param name="Input">Input</param>
        /// <returns>CalculateTaxOut</returns>
        public CalculateTaxOut CalculateTax(CalculateTaxIn Input)
        {
            // verify the required parameter 'Input' is set
            if (Input == null)
            {
                throw new ApiException(400, "Missing required parameter 'Input' when calling CalculateTax");
            }


            var path = "/api/v1/tax/calculate";

            path = path.Replace("{format}", "json");


            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, String>();
            String postBody     = null;



            postBody = this.apiClient.Serialize(Input); // http body (model) parameter


            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)this.apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling CalculateTax: " + response.Content, response.Content);
            }
            return((CalculateTaxOut)this.apiClient.Deserialize(response.Content, typeof(CalculateTaxOut)));
        }
Example #4
0
        public Task <CalculateTaxOut> CalculateTaxAsync(CalculateTaxIn input, string apiKey)
        {
            var tax = new ApivtaxApi(new ApiClient(apiKey));

            return(tax.CalculateTaxAsync(input));
        }
        private async Task PerformCountryNotDetectedTest(UserType userType)
        {
            this.apiKeyRepository.Setup(v => v.GetApiKey(userType)).Returns(ApiKey);

            var expectedInput = new CalculateTaxIn
            {
                Transaction = new InputTransaction
                {
                    CurrencyCode     = PaymentConstants.Usd,
                    TransactionLines = new List <InputTransactionLine>
                    {
                        new InputTransactionLine
                        {
                            CustomId = CreateTaxamoTransaction.CustomId,
                            Amount   = new AmountInMinorDenomination(Amount.Value).ToMajorDenomination()
                        }
                    },
                    BuyerCreditCardPrefix = CreditCardPrefix,
                    BuyerIp                = IpAddress,
                    BillingCountryCode     = CountryCode,
                    OriginalTransactionKey = OriginalTaxamoTransactionKey
                }
            };

            CalculateTaxIn actualInput = null;

            this.taxamoService.Setup(v => v.CalculateTaxAsync(It.IsAny <CalculateTaxIn>(), ApiKey))
            .Callback <CalculateTaxIn, string>((b, c) => actualInput = b)
            .ReturnsAsync(new CalculateTaxOut
            {
                Transaction = new Transaction
                {
                    Key              = NewTaxamoTransactionKey,
                    Amount           = 0.1m,
                    TotalAmount      = 0.12m,
                    TaxAmount        = 0.02m,
                    TaxEntityName    = "England",
                    CountryName      = "UK",
                    TransactionLines = new List <TransactionLines>
                    {
                        new TransactionLines {
                            TaxRate = 20m, TaxName = "VAT"
                        }
                    },
                    Evidence = new Evidence
                    {
                        ByCc = new EvidenceSchema
                        {
                            Used = true
                        },
                        ByIp = new EvidenceSchema
                        {
                            Used = false
                        },
                        ByBilling = null,
                    },
                    Countries = new Countries
                    {
                        ByCc = new CountrySchema
                        {
                            Name = "United Kingdom",
                            Code = "GB"
                        },
                        ByIp = new CountrySchema
                        {
                            Name = "France",
                            Code = "FR"
                        },
                        ByBilling = new CountrySchema
                        {
                            Name = "United States",
                            Code = "US"
                        },
                    }
                }
            });

            var result = await this.target.ExecuteAsync(Amount, CountryCode, CreditCardPrefix, IpAddress, OriginalTaxamoTransactionKey, userType);

            Assert.AreEqual(
                new TaxamoCalculationResult(
                    new AmountInMinorDenomination(10),
                    new AmountInMinorDenomination(12),
                    new AmountInMinorDenomination(2),
                    20m,
                    "VAT",
                    "England",
                    null,
                    new List <TaxamoCalculationResult.PossibleCountry>
            {
                new TaxamoCalculationResult.PossibleCountry("United Kingdom", "GB"),
                new TaxamoCalculationResult.PossibleCountry("France", "FR"),
                new TaxamoCalculationResult.PossibleCountry("United States", "US"),
            }),
                result);

            Assert.AreEqual(
                JsonConvert.SerializeObject(expectedInput, Formatting.None),
                JsonConvert.SerializeObject(actualInput, Formatting.None));
        }