Exemplo n.º 1
0
 // Constructors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 public MainPageVM() : base()
 {
     taxRequest    = new TaxRequestModel();
     taxService    = new TaxService();
     ResetCommand  = new RelayCommand(Reset);
     SubmitCommand = new RelayCommand(Submit);
 }
Exemplo n.º 2
0
        // Constructors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // Properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // Events & Handlers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // POST https://api.taxjar.com/v2/taxes
        public async Task <(bool success, string message, TaxModel tax)> CalculateTax(TaxRequestModel _request)
        {
            (bool success, string message, TaxModel tax)ret;
            var json = JsonConvert.SerializeObject(_request);

            var message = new HttpRequestMessage(HttpMethod.Post, calculateTaxURI);

            message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);
            message.Content = new StringContent(json, Encoding.UTF8, "application/json");

            var res = await client.SendAsync(message);

            var resString = await res.Content.ReadAsStringAsync();

            if (res.IsSuccessStatusCode)
            {
                try
                {
                    var tax = JsonConvert.DeserializeObject <TaxModelParse>(resString);
                    ret = (true, string.Empty, tax.Tax);
                }
                catch (Exception e)
                {
                    ret = (false, Translations.UnexpectedError, null);
                }
            }
            else
            {
                try
                {
                    var error = JsonConvert.DeserializeObject <HttpErrorParse>(resString);
                    ret = (false, error.Detail, null);
                }
                catch (Exception e)
                {
                    ret = (false, Translations.UnexpectedError, null);
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
 // Properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 public Task <(bool success, string message, TaxModel tax)> CalculateTax(TaxRequestModel _request)
 => TaxCalculator.CalculateTax(_request);