question

liju avatar image
liju asked Alan commented

Tax calculation for orders created via API

Hello, I would like to understand how to calculate tax for orders created via API. Per Clover documentation at https://docs.clover.com/build/web-app...

I see tax calculation is only done at once on order working total. How is this possible to calculate it at order level since every inventory item in clover can be associated with one or more tax rates? How do i apply these tax rates at order level?

I am using pay api to make a payment for the order with my calculated totals that is turning out a cent less or more that the order total that clover calculates thru the Orders app. So i would like to know how to calculate tax properly if it needs to be done per item and its tax rates and/or on whole order sum total?

Could you kindly clarify?

Regards, Liju

OrdersTaxes
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jacob Abrams avatar image
Jacob Abrams answered Alan commented

Since you are performing this calculation on your server you will need to do a little bit more work. We provide a pure Java calc.jar that we use to perform calculations. You can get it here: https://github.com/clover/clover-andr...

Import that JAR into your project and then use the internal Calc class to perform computations. You will probably want to have some kind of Java classes to represent Clover orders that you convert from JSON, you can GSON or Jackson to convert the JSON to your instances. Once you have Order objects you need to implement the Calc.Order interface and give it to Calc instance like so:

com.clover.core.internal.calc.Calc.Order calcOrder = new com.clover.core.internal.calc.Calc.Order() {

  // TODO: Implement all Calc.Order methods using your own Clover Order object

};

Calc c = new Calc(calcOrder);
c.getTax();

Take a look at https://github.com/clover/clover-andr... for an example how we implemented this interface for our Android SDK, you won't be able to use our v3 classes on your server, you will implement the interface using your own classes.

5 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

liju avatar image liju commented ·

Thanks for your reply, but I am doing the calculations on my web-server. Both order creation and payment for the orders are being done via Clover REST API calls.

0 Likes 0 ·
liju avatar image liju commented ·

Actually, my web server is written in NodeJs, do you have anything to help with this to do the calculations?

0 Likes 0 ·
Jacob Abrams avatar image Jacob Abrams ♦♦ commented ·

Sorry we don't supply a Javascript calculation library. You could try using a Node.js to Java bridge such as https://github.com/joeferner/node-java

0 Likes 0 ·
liju avatar image liju commented ·

Jacob, Thanks for your responses. Will take a look at the resources you have provided for a a solution. Appreciate your help.

0 Likes 0 ·
Alan avatar image Alan commented ·

@Liju By any chance, have you found a solution for nodejs tax calculation?

0 Likes 0 ·

Welcome to the
Clover Developer Community