taxjar / taxjar-go

Sales Tax API Client for Go
https://developers.taxjar.com/api/reference/?go
MIT License
15 stars 5 forks source link

Line Item Breakdown Tax collected does not sum to order Tax collected #22

Open nikolawannabe opened 4 months ago

nikolawannabe commented 4 months ago

Here's what I got:

taxjar.Tax{OrderTotalAmount:4.99,
 Shipping:0,
 TaxableAmount:4.99,
 AmountToCollect:0.44,
 Rate:0.089,
 HasNexus:true,
 FreightTaxable:true,
 TaxSource:"destination",
 ExemptionType:"",
 Jurisdictions:taxjar.Jurisdictions{Country:"US",
 State:"WA",
 County:"CLALLAM",
 City:"PORT ANGELES"},
 Breakdown:taxjar.Breakdown{
    TaxableAmount:4.99,
     TaxCollectable:0.44,
     CombinedTaxRate:0.089,
     StateTaxableAmount:4.99,
     StateTaxRate:0.065,
     StateTaxCollectable:0.32,
     CountyTaxableAmount:4.99,
     CountyTaxRate:0.004,
     CountyTaxCollectable:0.02,
     CityTaxableAmount:4.99,
     CityTaxRate:0.014,
     CityTaxCollectable:0.07,
     SpecialDistrictTaxableAmount:4.99,
     SpecialTaxRate:0.006,
     SpecialDistrictTaxCollectable:0.03,
     Shipping:taxjar.Shipping{TaxableAmount:0,
     TaxCollectable:0,
     CombinedTaxRate:0.089,
     StateTaxableAmount:0,
     StateSalesTaxRate:0.065,
     StateAmount:0,
     CountyTaxableAmount:0,
     CountyTaxRate:0.004,
     CountyAmount:0,
     CityTaxableAmount:0,
     CityTaxRate:0.014,
     CityAmount:0,
     SpecialTaxableAmount:0,
     SpecialTaxRate:0.006,
     SpecialDistrictAmount:0,
     GSTTaxableAmount:0,
     GSTTaxRate:0,
     GST:0,
     PSTTaxableAmount:0,
     PSTTaxRate:0,
     PST:0,
     QSTTaxableAmount:0,
     QSTTaxRate:0,
     QST:0,
     CountryTaxableAmount:0,
     CountryTaxRate:0,
     CountryTaxCollectable:0},
     LineItems:[]taxjar.LineItemBreakdown{
        taxjar.LineItemBreakdown{
            ID:"33",
             TaxableAmount:1,
             TaxCollectable:0.09,
             CombinedTaxRate:0.089,
             StateTaxableAmount:1,
             StateSalesTaxRate:0.065,
             StateAmount:0.07,
             CountyTaxableAmount:1,
             CountyTaxRate:0.004,
             CountyAmount:0,
             CityTaxableAmount:1,
             CityTaxRate:0.014,
             CityAmount:0.01,
             SpecialDistrictTaxableAmount:1,
             SpecialTaxRate:0.006,
             SpecialDistrictAmount:0.01,
             GSTTaxableAmount:0,
             GSTTaxRate:0,
             GST:0,
             PSTTaxableAmount:0,
             PSTTaxRate:0,
             PST:0,
             QSTTaxableAmount:0,
             QSTTaxRate:0,
             QST:0,
             CountryTaxableAmount:0,
             CountryTaxRate:0,
             CountryTaxCollectable:0
         },
         taxjar.LineItemBreakdown{
             ID:"34",
             TaxableAmount:3.99,
             TaxCollectable:0.36,
             CombinedTaxRate:0.089,
             StateTaxableAmount:3.99,
             StateSalesTaxRate:0.065,
             StateAmount:0.26,
             CountyTaxableAmount:3.99,
             CountyTaxRate:0.004,
             CountyAmount:0.02,
             CityTaxableAmount:3.99,
             CityTaxRate:0.014,
             CityAmount:0.06,
             SpecialDistrictTaxableAmount:3.99,
             SpecialTaxRate:0.006,
             SpecialDistrictAmount:0.02,
             GSTTaxableAmount:0,
             GSTTaxRate:0,
             GST:0,
             PSTTaxableAmount:0,
             PSTTaxRate:0,
             PST:0,
             QSTTaxableAmount:0,
             QSTTaxRate:0,
             QST:0,
             CountryTaxableAmount:0,
             CountryTaxRate:0,
             CountryTaxCollectable:0
         }
     },
     GSTTaxableAmount:0,
     GSTTaxRate:0,
     GST:0,
     PSTTaxableAmount:0,
     PSTTaxRate:0,
     PST:0,
     QSTTaxableAmount:0,
     QSTTaxRate:0,
     QST:0,
     CountryTaxableAmount:0,
     CountryTaxRate:0,
     CountryTaxCollectable:0
}
}

You can see I sent two items, one item listed with TaxableAmount for $1.00 and the other for $3.99. TaxCollectable on the first is 0.09 and TaxCollectable on the second is 0.36. This means total tax collected should be $0.45. But for the order, it shows: AmountToCollect:0.44. The line item total sum (4.99) is the same as the submitted Amount. There is no shipping.

The side effect of this error is that if I store the tax collected by line item and refund each item individually to the user, the refund will be greater than the total amount paid by $0.01, which (sensibly) the payment process does not want to permit. (Nor do I.)

So: I could throw away "TaxCollectable" from the top level and use the sum of the line items, but no telling where the error came from and if that's the right fix.

nikolawannabe commented 2 months ago

We had a lot of talk about this and ended up deciding that legally, tax math with refunds isn't commutative and you should expect to refund slightly more if you refund multiple times due to penny rounding. :shrug: It's a mess.