Hi, we have seen a rare issue with our order tax calculation when an order amount discount is included. Our tax calculation is off by $0.01.
According to https://docs.clover.com/docs/calculating-order-totals#step-3-order-level-discounts, we group lineitems according to taxes, calculate the per item subtotal after discounts (rounded) for each tax, apply the tax rate to each lineItemPriceAfterDiscounts, sum them and round the answer.
For example, what we do (all prices in cents):
Tax1 = 8.25% ItemPrices= 550, 500, 750, 650 (all items have above tax applied) Discount = 613 OrderDiscountMultiplier: (550 + 500 + 750 + 650 - 613) / (550, 500, 750, 650) = 0.749795918 ItemPricesAfterDiscounts: 550 * 0.749795918 = 412 500 * 0.749795918 = 375 750 * 0.749795918 = 562 650 * 0.749795918 = 487 TaxAmounts 412 * 0.0825 = 33.99 375 * 0.0825 = 30.9375 562 * 0.0825 = 46.365 487 * 0.0825 = 40.1775 TaxAmountRounded = 33.99 + 30.9375 + 46.365 + 40.1775 = 151.47 = 151
However, we noticed that a similar order was calculated with a tax of 152 by clover resulting a 1 cent difference. This means we are doing a rounding off error above.
The problem is that we rely on the calculation to determine the charge amount to pass to the e-commerce API. When this issue occurs, clover considers the order as partially paid since we are charging 1 cent less.
Please help us understand what we are doing wrong here. I feel like we are in accordance with the guides provided in the mentioned link.
Please do not suggest us to set our own totals to the order so that e-commerce doesn't calculate them for us. We can't use that option because then the order will start showing up in the Clover Dashboards and Orders App even if the customer later decides to cancel the payment.