Weird tax calculation in Create Orders API

Hi Guys,

I’m encountering a weird tax calculation issue which I can’t understand when I’m using the Create Orders API call.

I have define the following tax in my order (response),

"taxes": [
    {
        "uid": "6DAIYJD4V67I3KOQRL7A3AF6", 
        "catalog_object_id": "6DAIYJD4V67I3KOQRL7A3AF6", 
        "name": "State Tax", 
        "type": "ADDITIVE", 
        "percentage": "6.25", 
        "metadata": null, 
        "applied_money": {
            "amount": 62, 
            "currency": "USD"
        }, 
        "scope": "LINE_ITEM"
    }
], 

And given below is how the above tax is calculated to line item one time where I pass two line items.

  "line_items": [
    {
      "quantity": "1",
      "uid": "urTG6vs4NkhxrfAjyp8KLD",
      "name": "Bagels",
      "quantity_unit": null,
      "note": "",
      "catalog_object_id": "**RFXMJ5IA3LM476CAFXYEDTCO**",
      "variation_name": "Regular",
      "metadata": null,
      "modifiers": [...],
      "applied_taxes": [
        {
          "tax_uid": "6DAIYJD4V67I3KOQRL7A3AF6",
          "uid": "rwIjb9RsH7tmkXKN5hf4JB",
          "applied_money": {
            "amount": 16,
            "currency": "USD"
          }
        }
      ],
      "applied_discounts": null,
      "base_price_money": {
        "amount": 250,
        "currency": "USD"
      },
      "variation_total_price_money": {...},
      "gross_sales_money": {...},
      "total_tax_money": {
        "amount": 16,
        "currency": "USD"
      },
      "total_discount_money": {...},
      "total_money": {...}
    },
    {
      "quantity": "3",
      "uid": "CSlnySxdHstYZkFGzjL7ID",
      "name": "Bagels",
      "quantity_unit": null,
      "note": "",
      "catalog_object_id": "**RFXMJ5IA3LM476CAFXYEDTCO**",
      "variation_name": "Regular",
      "metadata": null,
      "modifiers": [...],
      "applied_taxes": [
        {
          "tax_uid": "6DAIYJD4V67I3KOQRL7A3AF6",
          "uid": "equ0K4VYxX5TyNw6qzWQNC",
          "applied_money": {
            "amount": 46,
            "currency": "USD"
          }
        }
      ],
      "applied_discounts": null,
      "base_price_money": {
        "amount": 250,
        "currency": "USD"
      },
      "variation_total_price_money": {...},
      "gross_sales_money": {...},
      "total_tax_money": {
        "amount": 46,
        "currency": "USD"
      },
      "total_discount_money": {...},
      "total_money": {...}
    }
  ],

Look carefully for the applied tax amount for each line item. I’m passing the same catalog item with different quantities (1 with a free modifier and 3 with another free modifier).

Now given below is another scenario where I pass same catalog object like above with another different quantity (2) including the above two quantities. So altogether I’m passing 3 line items with 3 different quantities. The only difference is each of them have unique modifier. They don’t have discounts also.

  "line_items": [
    {
      "quantity": "1",
      "uid": "UQCYNoI25TQ8aj0uVFt8s",
      "name": "Bagels",
      "quantity_unit": null,
      "note": "",
      "catalog_object_id": "**RFXMJ5IA3LM476CAFXYEDTCO**",
      "variation_name": "Regular",
      "metadata": null,
      "modifiers": [...],
      "applied_taxes": [
        {
          "tax_uid": "6DAIYJD4V67I3KOQRL7A3AF6",
          "uid": "5c6FIdshNN3l0JOCPh6OwC",
          "applied_money": {
            "amount": 16,
            "currency": "USD"
          }
        }
      ],
      "applied_discounts": null,
      "base_price_money": {
        "amount": 250,
        "currency": "USD"
      },
      "variation_total_price_money": {...},
      "gross_sales_money": {...},
      "total_tax_money": {
        "amount": 16,
        "currency": "USD"
      },
      "total_discount_money": {...},
      "total_money": {...}
    },
    {
      "quantity": "2",
      "uid": "ZFybcPBulZkN3yegtFkKWC",
      "name": "Bagels",
      "quantity_unit": null,
      "note": "",
      "catalog_object_id": "**RFXMJ5IA3LM476CAFXYEDTCO**",
      "variation_name": "Regular",
      "metadata": null,
      "modifiers": [...],
      "applied_taxes": [
        {
          "tax_uid": "6DAIYJD4V67I3KOQRL7A3AF6",
          "uid": "AJB6EjBvISliFmx9rs9RX",
          "applied_money": {
            "amount": 31,
            "currency": "USD"
          }
        }
      ],
      "applied_discounts": null,
      "base_price_money": {
        "amount": 250,
        "currency": "USD"
      },
      "variation_total_price_money": {...},
      "gross_sales_money": {...},
      "total_tax_money": {
        "amount": 31,
        "currency": "USD"
      },
      "total_discount_money": {...},
      "total_money": {..}
    },
    {
      "quantity": "3",
      "uid": "r4OWcyUxCmt42aS64iBCGB",
      "name": "Bagels",
      "quantity_unit": null,
      "note": "",
      "catalog_object_id": "RFXMJ5IA3LM476CAFXYEDTCO",
      "variation_name": "Regular",
      "metadata": null,
      "modifiers": [...],
      "applied_taxes": [
        {
          "tax_uid": "6DAIYJD4V67I3KOQRL7A3AF6",
          "uid": "myfiBDHTGOgUs6E7SGHGa",
          "applied_money": {
            "amount": 47,
            "currency": "USD"
          }
        }
      ],
      "applied_discounts": null,
      "base_price_money": {
        "amount": 250,
        "currency": "USD"
      },
      "variation_total_price_money": {...},
      "gross_sales_money": {...},
      "total_tax_money": {
        "amount": 47,
        "currency": "USD"
      },
      "total_discount_money": {...},
      "total_money": {...}
    }
  ],

In the line items where I pass the quantity as 3 in above two cases see how the applied tax amount change? The only difference between the two orders are I pass a extra line item with another unique modifier. But for the same line item, tax gets applied in different manner.

Given below is the overall taxes response for second case

  "taxes": [
    {
      "uid": "6DAIYJD4V67I3KOQRL7A3AF6",
      "catalog_object_id": "6DAIYJD4V67I3KOQRL7A3AF6",
      "name": "State Tax",
      "type": "ADDITIVE",
      "percentage": "6.25",
      "metadata": null,
      "applied_money": {
        "amount": 94,
        "currency": "USD"
      },
      "scope": "LINE_ITEM"
    }
  ],

Hi @kokilaw welcome to the forums!

I believe the taxes are being calculated as a whole, and then divided up among the quantity. So for the first example, it appears to be a total of 1000 ($10), and 1000 * 0.0625 = 62.5, and using bankers rounding, it rounds down to 62. So, 62 is the total tax, then it divides that up based on the quantity:

1 (out of 4 total) is 62 * 0.25 = 15.5 => 16.
3 (out of 4 total) is 62 * 0.75 = 46.5 => 46.

In your second example we have 6 items total, for a total of 1500 ($15). The total tax should be 1500 * 0.625 = 93.75 => 94. So based on the quantity:

1 (out of 6 total) is 94 * .166… ~ 15.66…04 => 16
2 (out of 6 total) is 94 * 0.33… ~ 31.33…02 => 31
3 (out of 6 total) is 94 * 0.5 = 47

For more info, take a look at our developer docs on this. Hope that makes sense, but let me know if you have any questions.

Oh okay got it. My bad I didn’t see that developer docs page first. Anyway thanks for the quick response!