Exemplo n.º 1
0
        /// <summary>
        /// Creates a TaxJar tax method
        /// </summary>
        /// <param name="countryCode">
        /// The country code.
        /// </param>
        /// <param name="taxPercentageRate">
        /// The tax percentage rate.
        /// </param>
        /// <returns>
        /// The <see cref="ITaxationGatewayMethod"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// Throws an exception if tax rate creation fails
        /// </exception>
        public override ITaxationGatewayMethod CreateTaxMethod(string countryCode, decimal taxPercentageRate)
        {
            var attempt = ListResourcesOffered().FirstOrDefault(x => x.ServiceCode.Equals(countryCode)) != null
                ? GatewayProviderService.CreateTaxMethodWithKey(GatewayProviderSettings.Key, countryCode, taxPercentageRate)
                : Attempt <ITaxMethod> .Fail(new ConstraintException("A TaxJar tax method has already been defined for " + countryCode));


            if (attempt.Success)
            {
                return(new TaxJarTaxationGatewayMethod(attempt.Result, ExtendedData));
            }

            LogHelper.Error <TaxationGatewayProviderBase>("CreateTaxMethod failed.", attempt.Exception);

            throw attempt.Exception;
        }