RefundOrder mutation not refunding the shipping amount

I created a mutation to refund an order

{
  "query": "\n        mutation RefundCreate($input: RefundInput!) {\n          refundCreate(input: $input) {\n            refund {\n              id\n              totalRefundedSet {\n                presentmentMoney {\n                  amount\n                  currencyCode\n                }\n                shopMoney {\n                  amount\n                  currencyCode\n                }\n              }\n            }\n            userErrors {\n              field\n              message\n            }\n          }\n        }\n      ",
  "variables": {
    "input": {
      "refundLineItems": [
        {
          "lineItemId": "gid://shopify/LineItem/",
          "quantity": 2,
          "restockType": "NO_RESTOCK"
        },
        {
          "lineItemId": "gid://shopify/LineItem/",
          "quantity": 1,
          "restockType": "NO_RESTOCK"
        }
      ],
      "notify": true,
      "orderId": "gid://shopify/Order/",
      "shipping": { "amount": "7.95" },
      "currency": "USD",
      "transactions": [
        {
          "orderId": "gid://shopify/Order/",
          "parentId": "gid://shopify/OrderTransaction/",
          "gateway": "shopify_payments",
          "amount": "78.66",
          "kind": "REFUND"
        }
      ]
    }
  }
}

The request is successful but the shipping amount is not refunded.
In this case only the amount in the transaction is refunded.

Response

{
  "data": {
    "refundCreate": {
      "refund": {
        "id": "gid://shopify/Refund/",
        "totalRefundedSet": {
          "presentmentMoney": { "amount": "78.66", "currencyCode": "USD" },
          "shopMoney": { "amount": "78.66", "currencyCode": "USD" }
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 20,
      "actualQueryCost": 20,
      "throttleStatus": {
        "maximumAvailable": 20000.0,
        "currentlyAvailable": 19980,
        "restoreRate": 1000.0
      }
    }
  }
}

Even though the request is successful the shipping is not refunded.

1 Like

Hey @Dev_Siena,

Just looking at this. Can you confirm that after refunding this order that the order still has $7.95 remaining to be refunded?

Did you include the $7.95 in the amount of the transaction? I’m just looking to have a more clear picture so I can replicate.

Yes after the refund was made it still had $7.95 to be refunded, which was later manually refunded.
No, I didn’t include the $7.95 in the transaction, it was only included in the shipping as per the documentation, which only says to include the shipping and doesn’t say anything about including the shipping in the transaction.

 "shipping": { "amount": "7.95" },

Thanks for sharing that. What’s happening here is the shipping amount isn’t being refunded because it needs to be included in your transaction amount. The transaction amount field is where you specify the total refund value, which should include both the line items and shipping amounts you want to refund.

In your case, you correctly specified "shipping": { "amount": "7.95" } but your transaction amount was only set to $78.66, which didn’t include this shipping amount. To properly refund both the items and shipping, you should set the transaction amount to $86.61 (your current $78.66 plus the $7.95 shipping). The shipping field tells Shopify how much of that total transaction amount should be allocated specifically to shipping, but doesn’t automatically add to the transaction total.

Hey @Dev_Siena, do you still see issues after applying the above, or can I mark this as solved?

Yes this resolves my issues. Thank you!

1 Like