/// <summary> /// Calculate taxes using overrides /// </summary> /// <remarks>Accepts transaction and tax rate override data to perform tax calculations with the provided /// override information.</remarks> /// <param name="request">Transaction data to be processed and tax rate override list.</param> /// <returns>An array of TaxData objects that contain the information about the taxes applied.</returns> public async Task <TaxData[]> CalculateTaxesWithOverrides(CalculateWithOverridesRequest request) { HttpResponseMessage response = await httpClient.PostAsJsonAsync($"api/v1/CalculateWithOverrides/Taxes", request); if (!response.IsSuccessStatusCode) { string error = response.Headers.Contains(ErrorHeader) ? response.Headers.GetValues(ErrorHeader).FirstOrDefault() : null; throw new AfcRestException(response.StatusCode, error); } string content = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <TaxData[]>(content)); }
/// <summary> /// Example showing how to calculate taxes on a transaction while overriding tax rate for a specific tax. /// </summary> private static void CalculateTaxesWithOverrides() { PrintSeparator(); Console.WriteLine($"API: POST {BaseAddress}/api/v1/CalculateWithOverrides/Taxes"); Console.WriteLine(); using (var client = new AfcRestClient(BaseAddress, UserName, Password, ClientId, ClientProfileId)) { try { // Create a CalculateWithOverridesRequest object to specify the trasaction and override data var request = new CalculateWithOverridesRequest { Overrides = new TaxRateOverrideInfo[] { new TaxRateOverrideInfo { Pcode = 4133800, // PCode for Seattle, WA LevelExemptible = true, Scope = 1, // State-level scope TaxLevel = 1, // State-level tax TaxType = 1, // Sales tax type BracketInfo = new [] { new TaxBracketInfo { MaxBase = int.MaxValue, // Use max value if bracket has no limit Rate = 0.0123 // Enter rate as decimal for percentage-based taxes } }.ToList() } }.ToList(), Transaction = new Transaction { BillToPCode = 4133800, // PCode for Seattle, WA BusinessClass = 0, // ILEC Charge = 25.95, CompanyIdentifier = "TST", CustomerType = 0, // Residential Date = DateTime.Today, FacilitiesBased = true, Franchise = true, Incorporated = true, Lifeline = false, Lines = 1, Locations = 0, Minutes = 0, OriginationPCode = 4133800, // PCode for Seattle, WA Regulated = false, Sale = true, ServiceClass = 1, // Primary long distance ServiceType = 15, // Product TerminationPCode = 4133800, // PCode for Seattle, WA TransactionType = 10 // Sales } }; Console.WriteLine($"REQUEST BODY:"); Console.WriteLine(request.ToJson()); Console.WriteLine(); // Invoke REST API to calculate taxes on the transaction using the specified tax rate override TaxData[] taxes = client.CalculateTaxesWithOverrides(request).Result; Console.WriteLine($"RESPONSE:"); Console.WriteLine(JsonConvert.SerializeObject(taxes, Formatting.Indented)); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } } }