Developer forum

Forum » Development » Implementing a Tax Provider

Implementing a Tax Provider

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

HI there,

I am working on a custom tax provider for a simple use case: when the user is from state X, then a tax of Y percent should be added to the order lines or the complete order.

I assume the TaxProvider is the appropriate base class to use but I am not sue what to exactly. The class has no members you must implement, and a whole bunch of members you could override.

What's the logical thing to do? Which method(s) should I overwrite and with what kind of logic?

Thanks,

Imar


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Imar,

I can understand the confusion. Basically, the only methods, you should consider overriding are AddTaxToProducts, AddTaxToOrder, CommitTaxes and CancelTaxes. For inspiration, you can look at our built-in tax providers. You can find the source code here: http://developer.dynamicweb-cms.com/downloads/source-code.aspx.

CommitTaxes and CancelTaxes are mostly used if you need to commit a transaction or finalize something upon order completion. CommitTaxes is called when the checkout is done and successful, and CancelTaxes is called when the order is deleted from the backend.

AddTaxToProducts is called from the product catalog and gives you the option of adding taxes to the products being displayed in the frontend. Basically, you add a Tax object to the TaxCollection of the relevant products, and that propergates through to the frontend.

AddTaxToOrder is a way to add tax orderline to the order object. You can use the helper method CreateTaxOrderLine, available as a protected method on the TaxProvider base class, to create an orderline. Simply pass in the parent orderline that triggered the tax and the Tax object itself, and you'll get an OrderLine back that you can add to the order's OrderLines collection.

If you need to log something, you can use the protected method on the TaxProvider base class, called SaveLog.

I hope this helps you progress :)

- Jeppe

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Jeppe,

Thanks; it makes sense now and I have successfully implemented my own simple flat fee tax provider.

Imar

 

You must be logged in to post in the forum