Difference between revisions of "Integrating A Tax Provider"
m (→Deployment) |
(remove definitions for itaxprovider and taxproviderbase, replace with a skeleton code class suitable for customer extension) |
||
Line 1: | Line 1: | ||
− | == | + | == Sample Provider == |
− | To integrate a tax provider with Ablecommerce 7 you | + | To integrate a tax provider with Ablecommerce 7 you must implement '''CommerceBuilder.Taxes.Providers.ITaxProvider''' interface. This interface defines how tax providers interact with Ablecommerce. This should be done by extending the TaxProviderBase class. Below is a sample code to get you started. |
− | + | <code lang="csharp"> | |
− | <code> | + | using System; |
− | + | using System.Collections.Generic; | |
− | + | using System.Text; | |
− | + | using CommerceBuilder.Common; | |
− | + | using CommerceBuilder.Orders; | |
− | public | + | using CommerceBuilder.Taxes.Providers; |
+ | |||
+ | namespace SampleTaxProvider | ||
+ | { | ||
+ | public class TaxProvider : TaxProviderBase | ||
{ | { | ||
− | + | #region Properties | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
/// <summary> | /// <summary> | ||
/// The name of the tax provider implementation | /// The name of the tax provider implementation | ||
/// </summary> | /// </summary> | ||
− | string Name { get; } | + | public override string Name |
+ | { | ||
+ | get { throw new Exception("The method or operation is not implemented."); } | ||
+ | } | ||
/// <summary> | /// <summary> | ||
/// The version of the tax provider implementation | /// The version of the tax provider implementation | ||
/// </summary> | /// </summary> | ||
− | string Version { get; } | + | public override string Version |
+ | { | ||
+ | get { throw new Exception("The method or operation is not implemented."); } | ||
+ | } | ||
/// <summary> | /// <summary> | ||
/// Is the tax provider activated or not | /// Is the tax provider activated or not | ||
/// </summary> | /// </summary> | ||
− | bool Activated | + | public override bool Activated |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
{ | { | ||
− | get { | + | get { throw new Exception("The method or operation is not implemented."); } |
− | + | ||
} | } | ||
− | + | #endregion | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
/// <summary> | /// <summary> | ||
Line 110: | Line 45: | ||
/// <param name="taxGatewayId">The tax gateway id</param> | /// <param name="taxGatewayId">The tax gateway id</param> | ||
/// <param name="configurationData">Configuration data in the form of name value paris</param> | /// <param name="configurationData">Configuration data in the form of name value paris</param> | ||
− | public | + | public override void Initialize(int taxGatewayId, Dictionary<string, string> configurationData) |
{ | { | ||
− | + | base.Initialize(taxGatewayId, configurationData); | |
} | } | ||
/// <summary> | /// <summary> | ||
− | /// | + | /// Calculate the taxes using this provider for the given basket |
/// </summary> | /// </summary> | ||
− | /// < | + | /// <param name="basket">The basket to calculate tax for</param> |
− | + | /// <returns>Total tax calculated</returns> | |
+ | public override LSDecimal Calculate(Basket basket) | ||
{ | { | ||
− | + | throw new Exception("The method or operation is not implemented."); | |
− | + | ||
} | } | ||
Line 129: | Line 64: | ||
/// </summary> | /// </summary> | ||
/// <param name="basket">The basket for which to cancel the taxes</param> | /// <param name="basket">The basket for which to cancel the taxes</param> | ||
− | public | + | public override void Cancel(Basket basket) |
+ | { | ||
+ | throw new Exception("The method or operation is not implemented."); | ||
+ | } | ||
/// <summary> | /// <summary> | ||
Line 135: | Line 73: | ||
/// </summary> | /// </summary> | ||
/// <param name="order">The order for which to commit the taxes</param> | /// <param name="order">The order for which to commit the taxes</param> | ||
− | public | + | public override void Commit(Order order) |
− | + | { | |
− | + | throw new Exception("The method or operation is not implemented."); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | } | |
</code> | </code> | ||
− | |||
== Implementing Required Methods == | == Implementing Required Methods == | ||
Line 173: | Line 105: | ||
== Resources == | == Resources == | ||
− | |||
* [http://forums.ablecommerce.com/viewtopic.php?f=42&t=5935 Community Forums Discussion] | * [http://forums.ablecommerce.com/viewtopic.php?f=42&t=5935 Community Forums Discussion] |
Revision as of 15:34, 2 September 2009
Contents
Sample Provider
To integrate a tax provider with Ablecommerce 7 you must implement CommerceBuilder.Taxes.Providers.ITaxProvider interface. This interface defines how tax providers interact with Ablecommerce. This should be done by extending the TaxProviderBase class. Below is a sample code to get you started.
using System;
using System.Collections.Generic;
using System.Text;
using CommerceBuilder.Common;
using CommerceBuilder.Orders;
using CommerceBuilder.Taxes.Providers;
namespace SampleTaxProvider {
public class TaxProvider : TaxProviderBase { #region Properties /// <summary> /// The name of the tax provider implementation /// </summary> public override string Name { get { throw new Exception("The method or operation is not implemented."); } }
/// <summary> /// The version of the tax provider implementation /// </summary> public override string Version { get { throw new Exception("The method or operation is not implemented."); } }
/// <summary> /// Is the tax provider activated or not /// </summary> public override bool Activated { get { throw new Exception("The method or operation is not implemented."); } } #endregion
/// <summary> /// Initialize the tax provider with the given configuration data. Called by AC at the time of initialization. /// </summary> /// <param name="taxGatewayId">The tax gateway id</param> /// <param name="configurationData">Configuration data in the form of name value paris</param> public override void Initialize(int taxGatewayId, Dictionary<string, string> configurationData) { base.Initialize(taxGatewayId, configurationData); }
/// <summary> /// Calculate the taxes using this provider for the given basket /// </summary> /// <param name="basket">The basket to calculate tax for</param> /// <returns>Total tax calculated</returns> public override LSDecimal Calculate(Basket basket) { throw new Exception("The method or operation is not implemented."); }
/// <summary> /// Cancel the taxes by this provider for the given basket /// </summary> /// <param name="basket">The basket for which to cancel the taxes</param> public override void Cancel(Basket basket) { throw new Exception("The method or operation is not implemented."); }
/// <summary> /// Commit the taxes by this provider for the given order /// </summary> /// <param name="order">The order for which to commit the taxes</param> public override void Commit(Order order) { throw new Exception("The method or operation is not implemented."); } }
}
Implementing Required Methods
When you extend TaxProviderBase class you need to implement the abstract methods and properties defined in this class. Some of the properties and methods are for information purposes only and are easy to implement. For example Name and Version.
The important methods to implement are Calculate, Commit and Cancel.
Calculate
This method takes a basket object as input. From there, you can get the billing and shipping addresses as well as line items. What you need to do is determine the tax to charge - then add line items to the basket (BasketItem class) for each line item. The method returns the total tax that was added to the basket.
Commit
This method takes an order object as input and commits any taxes that were charged. This may not be required by your integration. Some providers may need to know what taxes were actually charged in order to produce accurate reports on tax liability.
Cancel
This method takes a basket object as input. When called, it cancels any tax charges currently in progress. Your integration may or may not require this. Some providers may use this to reset the calculations for a particular order in progress.
Deployment
Once your class is implemented and compiled, you need to register it with the store. Since we did not include our tax providers, there is no web based interface to do this yet. The simplest choice, if available, is to add a record to the database in the ac_TaxGateways table:
TaxGatewayId = auto number ID
StoreId = ID of your store, probably 1
Name = Name of your gateway
ClassId = .NET Class ID used to create an instance of your gateway. For examples, you can look in ac_PaymentGateways (assuming you have a gateway configured).
ConfigData = If you need to provide configuration data it can be stored here in a url encoded string. For example, key1=value&key2=value. The values in the field will be accessible in your integration by using the GetConfigData() method. If you are producing an integration only for yourselves, you don't need to worry about this as any configuration should be hard coded instead.