OrderCloud.Integrations.Tax.Avalara 1.0.2-alpha

This is a prerelease version of OrderCloud.Integrations.Tax.Avalara.
There is a newer version of this package available.
See the version list below for details.
dotnet add package OrderCloud.Integrations.Tax.Avalara --version 1.0.2-alpha                
NuGet\Install-Package OrderCloud.Integrations.Tax.Avalara -Version 1.0.2-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OrderCloud.Integrations.Tax.Avalara" Version="1.0.2-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OrderCloud.Integrations.Tax.Avalara --version 1.0.2-alpha                
#r "nuget: OrderCloud.Integrations.Tax.Avalara, 1.0.2-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OrderCloud.Integrations.Tax.Avalara as a Cake Addin
#addin nuget:?package=OrderCloud.Integrations.Tax.Avalara&version=1.0.2-alpha&prerelease

// Install OrderCloud.Integrations.Tax.Avalara as a Cake Tool
#tool nuget:?package=OrderCloud.Integrations.Tax.Avalara&version=1.0.2-alpha&prerelease                

OrderCloud.Integrations.Tax.Avalara

This project brings easy tax calculation to your ecommerce app using the Avalara API. It is published as a nuget code library and conforms to standard tax interfaces published in the base library OrderCloud.Catalyst.

Basics and Installation

  1. If you haven't, please read How to Calculate Tax with OrderCloud. In short, webhooks from the platform make requests to solution-custom API routes that contain tax calculation logic.
  2. This library can be installed in the context of a .NET API project that responds to those webhooks. If you already have a .NET API project, great. If not, you can follow this guide. After you have published your API, you will need to configure OrderCloud to point its Integration Event webhooks at your API.
  3. In your .NET project, add the OrderCloud.Integrations.Tax.Avalara nuget package with either the Visual Studio UI or the dotnet CLI.

dotnet add package OrderCloud.Integrations.Tax.Avalara

Authentication and Injection

You will need these configuration data points to authneticate to the Avalara API - BaseUrl, AccountID, LicenseKey, and CompanyCode. Create an account with avalara and get these from the admin portal.

var avalaraService = new AvalaraService(new AvalaraConfig()
{
	BaseUrl = "https://sandbox-rest.avatax.com/api/v2",
	LicenseKey = "...",
	AccountID = "...",
	CompanyCode = "...",
});

For efficient use of compute resources and clean code, create 1 AvalaraService object and make it available throughout your project using inversion of control dependency injection.

services.AddSingleton<ITaxCalculator>(avalaraService);
services.AddSingleton<ITaxCodeProvider>(avalaraService);

Notice that the interfaces being used to register avalaraService are not specific to Avalara. They are general to the domain of tax and come from the upstream OrderCloud.Catalyst package.

Usage

Create routes that respond to the OrderCloud platform's Integration Event webhooks. Inject the tax interfaces like ITaxCalculator and use them within the logic of the route. It is not recommended to rely directly on AvalaraService anywhere. The layer of abstraction that ITaxCalculator provides decouples your code from Avalara as a specific provider and hides some internal complexity of tax calculation.

public class CheckoutIntegrationEventController : CatalystController
{
	private readonly ITaxCalculator _taxCalculator;

	public CheckoutIntegrationEventController(ITaxCalculator taxCalculator)
	{
		// Inject interface. Implementation will depend on how services were registered, AvalaraService in this case.
		_taxCalculator = taxCalculator; 
	}

	....

	[HttpPost, Route("ordercalculate")] // route and method specified by OrderCloud platform
	[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
	public async Task<OrderCalculateResponse> CalculateOrder([FromBody] OrderCalculatePayload<CheckoutConfig> payload)
	{
		// custom logic and mapping 

		var summary = new OrderSummaryForTax() { ... }
		OrderTaxCalculation taxCalculation = await _taxCalculator.CalculateEstimateAsync(summary);
		response.TaxTotal = calculation.TotalTax; // Populate Total Tax field on the Order

		...
	}

	[HttpPost, Route("ordersubmit")] // route and method specified by OrderCloud platform
	[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
	public async Task<OrderSubmitResponse> HandleOrderSubmit([FromBody] OrderCalculatePayload<CheckoutConfig> payload)
	{
		// custom logic and mapping 

		var summary = new OrderSummaryForTax() { ... }
		await _taxCalculator.CommitTransactionAsync(summary);

		...
	}
}

This library also supports more complex cases that require mulitple tax accounts with different credentials. For example, in a franchise business model where each location is independent but all sell on one ecommerce solution. In that case, still inject one instance of AvalaraService exactly as above. You can provide empty strings for the fields. However, when you call methods on the interfaces, provide the optional configOverride parameter.

AvalaraConfig configOverride = await FetchTaxAccountCredentials(supplierID);
var summary = new OrderSummaryForTax() { ... }
OrderTaxCalculation taxCalculation = await _taxCalculator.CalculateEstimateAsync(summary, configOverride);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 9,044 10/31/2022
1.0.2-alpha 2,076 4/20/2022
1.0.1-alpha 209 4/20/2022