public IHttpActionResult CancelTax(CustomerOrder order) { if (!string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password) && !string.IsNullOrEmpty(_taxSettings.ServiceUrl) && !string.IsNullOrEmpty(_taxSettings.CompanyCode) && _taxSettings.IsEnabled) { var taxSvc = new JsonTaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl); var request = order.ToAvaTaxCancelRequest(_taxSettings.CompanyCode, CancelCode.DocVoided); var cancelTaxResult = taxSvc.CancelTax(request); if (!cancelTaxResult.ResultCode.Equals(SeverityLevel.Success)) { var error = string.Join(Environment.NewLine, cancelTaxResult.Messages.Select(m => m.Details)); return BadRequest(error); } return Ok(cancelTaxResult); } return BadRequest(); }
public virtual void CancelTaxDocument(CustomerOrder order) { LogInvoker<AvalaraLogger.TaxRequestContext>.Execute(log => { if (IsEnabled && !string.IsNullOrEmpty(AccountNumber) && !string.IsNullOrEmpty(LicenseKey) && !string.IsNullOrEmpty(ServiceUrl) && !string.IsNullOrEmpty(CompanyCode)) { var request = order.ToAvaTaxCancelRequest(CompanyCode, CancelCode.DocDeleted); if (request != null) { log.docCode = request.DocCode; log.docType = request.DocType.ToString(); var taxSvc = new JsonTaxSvc(AccountNumber, LicenseKey, ServiceUrl); var getTaxResult = taxSvc.CancelTax(request); if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success)) { var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Summary)); throw new Exception(error); } } } else { throw new Exception("AvaTax credentials not provided or tax calculation disabled"); } }) .OnError(_logger, AvalaraLogger.EventCodes.TaxCalculationError) .OnSuccess(_logger, AvalaraLogger.EventCodes.GetTaxRequestTime); }