Shopify refunds not displaying in admin after API processing

I’m working on an app that handles refunds for unavailable inventory items through the Shopify API. When I make the refund request, everything seems to work fine and I get a proper response, but the refund doesn’t show up in the Shopify admin panel when I look at the order.

I have a collection of items to refund stored in items_to_refund and I’m processing each one individually. Here’s what my implementation looks like:

refund_estimate = ShopifyAPI::Refund.calculate({
  currency: "USD",
  notify: false,
  note: "Item unavailable",
  shipping: { 
    "full_refund": false 
  },  
  refund_line_items: items_to_refund.map { |item|
    {
      line_item_id: item.id,
      quantity: item.quantity,
      restock_type: 'no_restock',
    }
  },
}, { 
    params: { order_id: order.id },
})

processed_refund = ShopifyAPI::Refund.new({
  currency: "USD",
  notify: false,
  note: "Item unavailable",
  shipping: { 
    "full_refund": false 
  },
  refund_line_items: items_to_refund.map { |item|
    {
      line_item_id: item.id,
      quantity: item.quantity,
      restock_type: 'no_restock'
    }
  },
  transactions: refund_estimate.transactions.map { |transaction|
    {
      kind: "refund",
      gateway: transaction.gateway,
      parent_id: transaction.parent_id,
      amount: transaction.amount
    }
  },
}, {
  params: { order_id: order.id }
})

The response I get back shows all the expected data with proper IDs and amounts, but when I check the actual order in Shopify, there’s no refund recorded. Am I missing a step to actually save the refund? Any help would be appreciated.

Had this exact same issue about six months ago and it drove me crazy for hours. The problem is you’re creating the refund object but never actually calling save on it. Creating the ShopifyAPI::Refund instance just builds the object in memory - it doesn’t persist it to Shopify until you explicitly save it. Add processed_refund.save after you create your refund object and before you finish processing. That should push it through to the Shopify admin. Also double check that your API permissions include refund write access, since some apps only get read permissions by default. The fact that you’re getting a proper response back from the calculate method suggests your data structure is correct, just missing that final save step.