private async Task <TransactionModel> CreateTransactionAsync(DocumentType docType, OrderWorksheet orderWorksheet) { var standardLineItems = orderWorksheet.LineItems.Where(li => li.Product.xp.ProductType == "Standard")?.ToList(); if (standardLineItems.Any()) { try { var createTransactionModel = orderWorksheet.ToAvalaraTransationModel(_companyCode, docType); var transaction = await _avaTax.CreateTransactionAsync("", createTransactionModel); return(transaction); } catch (AvaTaxError e) { throw new CatalystBaseException("AvalaraTaxError", 400, e.error.error.message, e.error.error); } } else { return(new TransactionModel { code = "NotTaxable", totalTax = 0 }); } }
private async Task <TransactionModel> CreateTransactionAsync(DocumentType docType, OrderWorksheet orderWorksheet) { var standardLineItems = orderWorksheet.LineItems.Where(li => li.Product.xp.ProductType == "Standard")?.ToList(); if (standardLineItems.Any()) { try { if (ShouldMockAvalaraResponse()) { return(CreateMockTransactionModel()); } var promosOnOrder = await _oc.Orders.ListAllPromotionsAsync(OrderDirection.Incoming, orderWorksheet.Order.ID); var createTransactionModel = orderWorksheet.ToAvalaraTransactionModel(_companyCode, docType, promosOnOrder); var transaction = await _avaTax.CreateTransactionAsync("", createTransactionModel); return(transaction); } catch (AvaTaxError e) { throw new CatalystBaseException("AvalaraTaxError", e.error.error.message, e.error.error, 400); } } else { return(new TransactionModel { code = "NotTaxable", totalTax = 0 }); } }
private async Task <OrderTaxCalculation> CreateTransactionAsync(DocumentType docType, OrderWorksheet orderWorksheet, List <OrderPromotion> promotions) { var standardLineItems = orderWorksheet.LineItems.Where(li => li.Product.xp.ProductType == "Standard")?.ToList(); if (standardLineItems.Any()) { try { if (ShouldMockAvalaraResponse()) { return(CreateMockTransactionModel()); } var createTransactionModel = orderWorksheet.ToAvalaraTransactionModel(_companyCode, docType, promotions); var transaction = await _avaTax.CreateTransactionAsync("", createTransactionModel); return(transaction.ToOrderTaxCalculation()); } catch (AvaTaxError e) { throw new CatalystBaseException("AvalaraTaxError", e.error.error.message, e.error.error, 400); } } else { return(new OrderTaxCalculation { OrderID = orderWorksheet.Order.ID, ExternalTransactionID = "NotTaxable", TotalTax = 0 }); } }
private static async Task ConnectThread() { while (!Console.KeyAvailable) { g_Count++; // Allow calls to end after a fixed length if (g_Options.Calls.HasValue && g_Count > g_Options.Calls.Value) { Console.WriteLine("Done."); return; } // Make one tax transaction try { DateTime start = DateTime.UtcNow; var t = await g_Client.CreateTransactionAsync(null, g_Model); TimeSpan ts = DateTime.UtcNow - start; g_TotalDuration.Combine(g_Client.LastCallTime); g_TotalMs += (long)ts.TotalMilliseconds; // Write some information var cd = g_Client.LastCallTime; // Check if user wants us to log everything, or only exceptional delays if ((!g_Options.LogExceptionalDelays) || (ts.TotalMilliseconds > 1000)) { Console.WriteLine($" {g_Count.ToString("0000")} {cd.ServerDuration.TotalMilliseconds.ToString("0000")}ms {cd.DataDuration.TotalMilliseconds.ToString("0000")}ms {cd.ServiceDuration.TotalMilliseconds.ToString("0000")}ms {cd.TransitDuration.TotalMilliseconds.ToString("0000")}ms {(cd.SetupDuration.TotalMilliseconds + cd.ParseDuration.TotalMilliseconds).ToString("0000")}ms {ts.TotalMilliseconds.ToString("0000")}ms"); } // Always log exceptions } catch (Exception ex) { HandleException(ex); Console.WriteLine($" {g_Count.ToString("0000")} EXCEPTION: {ex.Message}"); Console.WriteLine(ex.ToString()); } // Sleep in between calls, if desired if (g_Options.SleepBetweenCalls != 0) { await Task.Delay(g_Options.SleepBetweenCalls); } } }