FROM CACHE - en_header

How to calculate the new subtotal for a line_item with refunded items

17 0 3



I am working on an integration for a client and found and inconsistency in the calculation of the subtotal of a line_item after items are refunded.


For instance, when I receive the following payload for a line_item:


"line_item": {
  "id": 5195269406805,
  "sku": "99HGD8",
  "name": "Callaway MAVRIK Driver",
  "price": "349.99",
  "quantity": 5,
  "discount_allocations": [
      "amount": "524.98",

The way I go about calculating the subtotal is multiplying price(349.99) by quantity(5), minus the discount (524.98) = 1224.97


When 2 units are refunded I get this on the payload:


"refund_line_items": [
    "id": 159966003285,
    "quantity": 2,
    "line_item_id": 5195269406805,
    "subtotal": 489.98,

Where subtotal equals (quantity * price - discount). So I subtract 1224.97 - 489.98 to get 734.99, the remaining subtotal for that line_item. The problem is that when I get into Shopify's dashboard, I see the amount as 734.98 (there's a one-cent difference). My guess is that the discount_allocations amount is being rounded. My question is: How can I then get the exact value using only the data provided in the APIs.



Replies 0 (0)