Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions src/AvalaraTaxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class AvalaraTaxProvider : TaxProvider, IParameterOptions
/// <summary>
/// Gets the names for ItemCode and TaxCode field.
/// </summary>
internal const string ItemCodeFieldName = "ItemCode";
internal const string TaxCodeFieldName = "TaxCode";
internal const string ExemptionNumberFieldName = "ExemptionNumber";
internal const string EntityUseCodeFieldName = "EntityUseCode";
internal const string ItemCodeFieldName = "AvalaraItemCode";
internal const string TaxCodeFieldName = "AvalaraTaxCode";
internal const string ExemptionNumberFieldName = "AvalaraExemptionNumber";
internal const string EntityUseCodeFieldName = "AvalaraEntityUseCode";
public const string BeforeTaxCalculation = "Ecom7CartBeforeTaxCalculation";
public const string BeforeTaxCommit = "Ecom7CartBeforeTaxCommit";
public const string OnGetCustomerCode = "Ecom7CartAvalaraOnGetCustomerCode";
Expand Down Expand Up @@ -509,21 +509,21 @@ public static void VerifyCustomFields()
var itemCodeColl = ProductField.FindProductFieldsBySystemName(ItemCodeFieldName);
var taxCodeColl = ProductField.FindProductFieldsBySystemName(TaxCodeFieldName);

if (itemCodeColl.Count() == 0)
if (!itemCodeColl.Any())
{
var productField = new ProductField();
productField.Name = ItemCodeFieldName;
productField.Name = "Avalara Item Code";
productField.SystemName = ItemCodeFieldName;
productField.TemplateName = ItemCodeFieldName;
productField.TypeId = 1;
productField.TypeName = "Text";
productField.Save(ItemCodeFieldName);
}

if (taxCodeColl.Count() == 0)
if (!taxCodeColl.Any())
{
var productField = new ProductField();
productField.Name = TaxCodeFieldName;
productField.Name = "Avalara Tax Code";
productField.SystemName = TaxCodeFieldName;
productField.TemplateName = TaxCodeFieldName;
productField.TypeId = 15;
Expand All @@ -533,40 +533,41 @@ public static void VerifyCustomFields()
}

string tableName = "AccessUser";
var systemFields = SystemField.GetSystemFields(tableName);
var customFields = CustomField.GetCustomFields(tableName);

// ExemptionNumber
{
SystemField exemptionNumberField = new SystemField(ExemptionNumberFieldName, tableName, Types.Text, ExemptionNumberFieldName);
if (!systemFields.ContainsSystemField(exemptionNumberField))
exemptionNumberField.Save();
}
// ExemptionNumber
var exemptionNumberField = new CustomField(ExemptionNumberFieldName, tableName, Types.Text);
exemptionNumberField.Name = "Avalara Exemption Number";
if (!customFields.ContainsCustomField(exemptionNumberField))
exemptionNumberField.Save();

// EntityUseCode
var entityUseCodeField = new CustomField(EntityUseCodeFieldName, tableName, Types.DropDown);
entityUseCodeField.Name = "Avalara Entity Use Code";

// EntityUseCode
if (!customFields.ContainsCustomField(entityUseCodeField))
{
SystemField entityUseCodeField = new SystemField(EntityUseCodeFieldName, tableName, Types.DropDown, EntityUseCodeFieldName);
if (!systemFields.ContainsSystemField(entityUseCodeField))
{
var options = new CustomFieldOptions();
options.DataType = Types.Text;
options.Add(new KeyValuePair<string, object>("", ""));
options.Add(new KeyValuePair<string, object>("Federal government", "A"));
options.Add(new KeyValuePair<string, object>("State government", "B"));
options.Add(new KeyValuePair<string, object>("Tribe / Status Indian / Indian Band", "C"));
options.Add(new KeyValuePair<string, object>("Foreign diplomat", "D"));
options.Add(new KeyValuePair<string, object>("Charitable or benevolent org", "E"));
options.Add(new KeyValuePair<string, object>("Religious org", "F"));
options.Add(new KeyValuePair<string, object>("Education org", "M"));
options.Add(new KeyValuePair<string, object>("Resale", "G"));
options.Add(new KeyValuePair<string, object>("Commercial agricultural production", "H"));
options.Add(new KeyValuePair<string, object>("Industrial production / manufacturer", "I"));
options.Add(new KeyValuePair<string, object>("Direct pay permit", "J"));
options.Add(new KeyValuePair<string, object>("Direct mail", "K"));
options.Add(new KeyValuePair<string, object>("Other (requires Exempt Reason Desc)", "L"));
options.Add(new KeyValuePair<string, object>("Local government", "N"));
entityUseCodeField.Options = options;
entityUseCodeField.Save();
}
var options = new CustomFieldOptions();
options.DataType = Types.Text;
options.Add(new KeyValuePair<string, object>("", ""));
options.Add(new KeyValuePair<string, object>("Federal government", "A"));
options.Add(new KeyValuePair<string, object>("State government", "B"));
options.Add(new KeyValuePair<string, object>("Tribe / Status Indian / Indian Band", "C"));
options.Add(new KeyValuePair<string, object>("Foreign diplomat", "D"));
options.Add(new KeyValuePair<string, object>("Charitable or benevolent org", "E"));
options.Add(new KeyValuePair<string, object>("Religious org", "F"));
options.Add(new KeyValuePair<string, object>("Education org", "M"));
options.Add(new KeyValuePair<string, object>("Resale", "G"));
options.Add(new KeyValuePair<string, object>("Commercial agricultural production", "H"));
options.Add(new KeyValuePair<string, object>("Industrial production / manufacturer", "I"));
options.Add(new KeyValuePair<string, object>("Direct pay permit", "J"));
options.Add(new KeyValuePair<string, object>("Direct mail", "K"));
options.Add(new KeyValuePair<string, object>("Other (requires Exempt Reason Desc)", "L"));
options.Add(new KeyValuePair<string, object>("Local government", "N"));
options.Add(new KeyValuePair<string, object>("Non-Exempt taxable customer", "TAXABLE"));

entityUseCodeField.Options = options;
entityUseCodeField.Save();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>10.15.0</VersionPrefix>
<VersionPrefix>10.17.0</VersionPrefix>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Avalara</Title>
<Description>Avalara tax provider</Description>
Expand All @@ -24,8 +24,8 @@
<PackageIcon>Avalara-logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb" Version="10.15.1" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.15.1" />
<PackageReference Include="Dynamicweb" Version="10.17.4" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.17.4" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dynamicweb.Ecommerce.TaxProviders.AvalaraTaxProvider.Model.Enums;
using System;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

Expand All @@ -23,15 +22,15 @@ internal sealed class CreateTransactionRequest
[DataMember(Name = "customerCode", IsRequired = true)]
public string CustomerCode { get; set; }

[DataMember(Name = "customerUsageType", EmitDefaultValue = false)]
public string CustomerUsageType { get; set; }

[DataMember(Name = "discount", EmitDefaultValue = false)]
public double? Discount { get; set; }

[DataMember(Name = "exemptionNo", EmitDefaultValue = false)]
public string ExemptionNumber { get; set; }

[DataMember(Name = "entityUseCode", EmitDefaultValue = false)]
public string EntityUseCode { get; set; }

[DataMember(Name = "addresses", EmitDefaultValue = false)]
public Addresses Addresses { get; set; }

Expand Down
26 changes: 26 additions & 0 deletions src/Service/AvalaraException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Net;

namespace Dynamicweb.Ecommerce.TaxProviders.AvalaraTaxProvider.Service;

/// <summary>
/// Custom exception for Avalara API errors
/// </summary>
internal sealed class AvalaraException : Exception
{
public HttpStatusCode? StatusCode { get; }
public ApiCommand Command { get; }

public AvalaraException(string message, ApiCommand command, HttpStatusCode? statusCode)
: base(message)
{
Command = command;
StatusCode = statusCode;
}

public AvalaraException(string message, ApiCommand command, Exception innerException)
: base(message, innerException)
{
Command = command;
}
}
Loading