I’m using order api and I want to specify which line is taxable. For the entire order, there’s setTaxes but I don’t see where to set the OrderLineItemTax object to an OrderLineItem. For the OrderLineItemTax uid, do I need to have a different one for each lines?
This is what I have so far:
$money = new Square\Models\Money();
$money->setCurrency($currency);
$money->setAmount($item_price);
$item = new Square\Models\OrderLineItem($qty);
$item->setName($item_name);
$item->setBasePriceMoney($money);
$taxitem = new Square\Models\OrderLineItemTax();
$taxitem->setUid($uid);
$taxitem->setType(Square\Models\OrderLineItemTaxType::ADDITIVE);
$taxitem->setScope(Square\Models\OrderLineItemTaxScope::LINE_ITEM);
$taxitem->setName($tax_name);
$taxitem->setPercentage($tax_rate);
$applied_tax = new Square\Models\OrderLineItemAppliedTax($uid);
$item->setAppliedTaxes(array($applied_tax));
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:
https://developer.squareup.com/docs/orders-api/apply-taxes-and-discounts/auto-apply-taxes
Additional Documentation
Create Orders
https://developer.squareup.com/docs/orders-api/apply-taxes-and-discounts
https://developer.squareup.com/docs/orders-api/order-ahead-usecase
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.
To specify which line items are taxable in an order, you need to create an OrderLineItemTax object and apply it to the respective OrderLineItem.
In your code, you’ve correctly created the OrderLineItemTax object. However, you need to set the applied_taxes
field of the OrderLineItem object to an array of OrderLineItemAppliedTax objects. Each OrderLineItemAppliedTax object should have its tax_uid
field set to the uid
of the corresponding OrderLineItemTax object.
Here’s how you can modify your code:
$money = new Square\Models\Money();
$money->setCurrency($currency);
$money->setAmount($item_price);
$item = new Square\Models\OrderLineItem($qty);
$item->setName($item_name);
$item->setBasePriceMoney($money);
$taxitem = new Square\Models\OrderLineItemTax();
$taxitem->setUid($uid);
$taxitem->setType(Square\Models\OrderLineItemTaxType::ADDITIVE);
$taxitem->setScope(Square\Models\OrderLineItemTaxScope::LINE_ITEM);
$taxitem->setName($tax_name);
$taxitem->setPercentage($tax_rate);
$applied_tax = new Square\Models\OrderLineItemAppliedTax();
$applied_tax->setTaxUid($uid);
$item->setAppliedTaxes([$applied_tax]);
In this code, the setAppliedTaxes
method is used to apply the tax to the line item. The setTaxUid
method is used to link the applied tax to the tax item.
As for the uid
field in the OrderLineItemTax object, it should be unique within the order. You can use the same uid
for the OrderLineItemTax and the corresponding OrderLineItemAppliedTax objects. However, if you have multiple taxes, each one should have a unique uid
.
This answer was reviewed by @Bryan-Square.
The above is an adhoc tax object but you can also add a tax_id
for a tax that’s already in our Catalog. Be sure to set the scope
to LINE_ITEM
and then you can apply it to each line item with the uid
.
I finally got it, one of my main issues is that I have two taxes so I didn’t know I had to assign different uids for the OrderLineItemTax object.
Thanks!
Fantastic! Glad to hear you got it to work as expected.