question

sebadinamic avatar image
sebadinamic asked David Marginian Deactivated edited

How can i add tax to an order with REST API

Hi!

I successfully create an order with multiple products in clover via API REST but i cant add an order tax like in the attached image.

I can't fin instructions to do this in the API REST documentation. Thanks!


OrdersTaxes
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

Maybe this will help - https://community.clover.com/questions/11871/tax-not-appearing-in-receipt-in-order-created-by-a.html

Update:

Actually, I don't see the above being accurate. The tax rates are set on inventory items. What API are you using to create and pay for the order?

7 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sebadinamic avatar image sebadinamic commented ·

Hi David!

To create the order i'm using https://sandbox.dev.clover.com/v3/merchants/mId/orders, update with https://sandbox.dev.clover.com/v3/merchants/mId/orders/orderId and add product with https://sandbox.dev.clover.com/v3/merchants/mId/orders/orderId/bulk_line_items. Then, we pay with the iframe integration. Everything works fine but my client need to add the taxes as i show it with the image.


I tryed to add the taxes by product in the line items but the result is no as expect. I attached another image.


Thanks!



0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ sebadinamic commented ·

What endpoint are you using to pay? v1/charges or v1/orders?

1 Like 1 ·
sebadinamic avatar image sebadinamic David Marginian ♦♦ commented ·

I'm using v1/orders/XXXX/pay endpoint.

0 Likes 0 ·
Show more comments
Show more comments
David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

Our orders API is, well, a bit confusing to say the least. There are two scenarios, the first is if you are using the line_items endpoint (one line item at a time, which is not recommended if you have many items to add). The second scenario is if you are using the bulk_line_items endpoint to add multiple items at once.

Scenario 1: https://docs.clover.com/reference/orders-1#ordercreatelineitem-2

For this scenario the above endpoint is used to add a single line item to an order. The POST body can be as simple as:

{
    "item": {
       "id": "QV...X6"
    }
}

This request assumes the merchant has set-up inventory/tax rates, etc. QV...X6 is the id of an existing Clover inventory item (for the merchant). When the line item is posted the item from the merchant's inventory will be associated with the line item (name, price, taxRates, etc.). E.g. - QV...X6 correlates to the merchant's hotdog (5$) inventory item and the merchant has set a flat tax of .10 cents for this item. If this is the only line item on the order the receipt will show "hotdog" with a price of 5$ and a tax of .10 cents. You must (* see note below) properly set the total on the order (5.10 in this case, calculation details here - https://docs.clover.com/docs/working-with-orders#section-calculating-order-totals).

Scenario 2: https://docs.clover.com/reference/orders-1#orderbulkcreatelineitems-2

Now, things get a bit messy with the bulk_line_items endpoint. Regardless of what the API docs indicate, the item (inventory) being passed is ignored and all items are treated as custom. This means that the name/price/taxRates must be specified. So the request will need to look like:

{
    "items": [
        {        
            "name": "hotdog",
            "price": 500,
            "taxRates": [
                {
                    "name": "hotDogTax",
                    "taxAmount": 10,
                    "rate": 0,
                    "id": "J4W1A09QZJRJ8" // Must be an existing tax rate id.
                }
            ]
        }
    ]
}

Generally, your application will want to pull in the inventory taxRates upon inventory retrieval (expand on taxRates). As per the prior case, your application will also need (* see note below) to update the order total accordingly (https://docs.clover.com/docs/working-with-orders#section-calculating-order-totals).

*Note - You can get by without setting an order total if you use the Ecomm v1/order/pay endpoint - https://docs.clover.com/docs/ecommerce-accepting-payments#section-step-01-creating-an-order. If the order does not have a total and you use this endpoint, the order total will be calculated for you.


10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community