Welcome! Today we are going to learn about implementing taxes for your Moltin store. We’ll start broad with the different taxation strategies you can you implement, then narrowing down to the implementation pattern, and finishing by walking through a code example. By the time this has finished, you should have all the knowledge you need to add taxes into your Moltin project today.
Why you need to care about taxes
Not implementing taxation correctly can be an extremely costly mistake. There are a number of things you need to take into account when designing your eCommerce taxation strategy, including:
The location of your own business.
- The location of your shipping warehouses or nexuses.
- The location of your customers.
- The tax category of the different products you sell.
Given this information, in real time, you must be able to calculate the overall tax per product in a customers cart, present them with this information, apply it to the cart (honoring discount strategies), and ensure that it is accurately reflected on the customer’s order. Not only this, but you must consider post order changes, for example, if the customer enters the wrong shipping address. Let’s walk this through in three stages:
1. Collecting and storing the required variables:
No doubt you already know the location of your own business and locations of your warehouses. You can store this information in a Moltin Flow, so you can fetch it any time from the Moltin API. You can also use Flows to extend the Moltin product to store a field called something like `tax category`, and add the correct category for each product you make available. The location of your customer may be a little trickier, as it’s dependant on the address the user enters/chooses at checkout. This should be handled within your website code at the time of checkout.
2. Given the variables, real-time calculation of taxation amounts:
Now everything is available and your user is at a stage where taxes should be presented to them. At this point, we introduce a second service called Taxjar which will help you do the real-time calculations. Specifically, we’ll be using an API of theirs called SmartCalcs, and access starts from $17 per month. You make a single API to their service, providing all of the variables collected above, and they will return the tax to be collected per product.
3. Presenting calculated amounts to the customer and applying them to the cart
We’re ready to apply the tax to the Moltin cart on behalf of the user! Moltin offers tax as sub-items on each cart item. That means that each product in the cart will have its own tax amount. This is helpful when there are products of different tax categories in the cart together. It also means if a customer removes a product from the cart, the tax is automatically removed, too. When you add a tax item to a cart item, you add a number of fields:
- Name: name of the tax item
- Jurisdiction: relevant tax jurisdiction
- Code: tax code
- Rate: percentage of the cart item
One thing to be careful of here, you should make sure that for every cart updated call your application makes, you should recalculate the taxes, and re-add them, to prevent your user from attempting to manipulate the cart just to lower the tax amount.
Once you have added a tax item to a cart item, you can fetch the cart from Moltin, and you will see there is a display price for with tax and without tax, where we have taken the sum of all the tax items in the cart and used them to calculate the correct totals.
Promotions are applied post-tax, so they will discount the entire cart including the tax amounts.