Order Details and line items


I hope everyone is doing well.

I’m wondering whhy this is happening to me sometimes.

I have an order with multiple line items that include taxes. I’m mapping the line item taxes IDs (UIDs) to the Order.php->getTaxes() method to retrieve the catalogObjectId for each line item taxes.

However, the problem is that sometimes the getTaxes method doesn’t return a match for all the line items. What concerns me is that the documentation says getTaxes should return all taxes associated with the order, including both order-level and line-item taxes. Am I missing something here?

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Apply Taxes, Discounts, and Service Charges
Orders API
Catalog API

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The issue you’re experiencing might be due to the fact that the getTaxes() method only returns the taxes that are applied at the order level. For taxes that are applied at the line item level, you would need to access them through the line item object itself.

Each line item in an order has its own array of applied taxes. You can access these by calling the getAppliedTaxes() method on the OrderLineItem object. This will return an array of OrderLineItemAppliedTax objects, each of which represents a tax that has been applied to that specific line item.

So, if you’re trying to get all the taxes for all line items in an order, you would need to iterate over each line item and call getAppliedTaxes() on each one. This will give you the complete set of taxes for each line item, in addition to any order-level taxes returned by getTaxes().

This answer was reviewed by @Bryan-Square.