本文整理汇总了C#中IInvoice.AsTaxRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IInvoice.AsTaxRequest方法的具体用法?C# IInvoice.AsTaxRequest怎么用?C# IInvoice.AsTaxRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInvoice
的用法示例。
在下文中一共展示了IInvoice.AsTaxRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateTaxForInvoice
/// <summary>
/// The calculate tax for invoice.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="taxAddress">
/// The tax address.
/// </param>
/// <param name="quoteOnly">
/// A value indicating whether or not this is a tax quote or a formal tax submission
/// </param>
/// <returns>
/// The <see cref="ITaxCalculationResult"/>.
/// </returns>
public ITaxCalculationResult CalculateTaxForInvoice(IInvoice invoice, IAddress taxAddress, bool quoteOnly)
{
var defaultStoreAddress = _settings.DefaultStoreAddress;
string prefix = invoice.InvoiceNumberPrefix;
if (quoteOnly)
{
invoice.InvoiceNumberPrefix = string.Format("Quote-{0}", Guid.NewGuid());
}
var request = invoice.AsTaxRequest(defaultStoreAddress, quoteOnly);
if (quoteOnly) invoice.InvoiceNumberPrefix = prefix;
request.CompanyCode = _settings.CompanyCode;
var avaTaxResult = _avaTaxService.GetTax(request);
if (avaTaxResult.ResultCode == SeverityLevel.Success)
{
var extendedData = new ExtendedDataCollection();
extendedData.SetValue(Core.Constants.ExtendedDataKeys.TaxTransactionResults, JsonConvert.SerializeObject(avaTaxResult));
return new TaxCalculationResult(TaxMethod.Name, -1, avaTaxResult.TotalTax, extendedData);
}
IEnumerable<ApiResponseMessage> messages;
try
{
messages = avaTaxResult.Messages;
}
catch (Exception)
{
messages = Enumerable.Empty<ApiResponseMessage>();
}
var exception = new AvaTaxApiException(string.Format("AvaTax returned result code: {0}. {1}", avaTaxResult.ResultCode, string.Join(Environment.NewLine, messages.Select(x => x.Details))));
LogHelper.Error<AvaTaxTaxationGatewayMethod>("AvaTax API returned an exception", exception);
throw exception;
}