Reputation: 1722
I am using the shopify_api
gem for an app I am making. The refund process is handled entirely in app and I am only needing to update the order on Shopify as being refunded. I don't need Shopify to do anything other than register the payment status change. I have read that I need to first use Refund.calculate
in the gem to get a transaction parent id before actually making the request to the refund endpoint. My problem is, while reading the docs, I can not decipher how to format the arguments for the .calculate
request. Here is the method in question from the gem.
module ShopifyAPI
class Refund < Base
init_prefix :order
def self.calculate(*args)
options = { :refund => args[0] }
params = {}
params = args[1][:params] if args[1] && args[1][:params]
resource = post(:calculate, params, options.to_json)
instantiate_record(format.decode(resource.body), {})
end
end
end
I have tried Refund.calculate({shipping: { full_refund: true }, currency: 'EUR', refund_line_items: [{line_item_id: 12344556, quantity: 1}, restock: true]}, params: {order_id: 23453245})
I have also tried restock_type: 'restock'
I keep getting 406 or 422 errors.
Upvotes: 0
Views: 199
Reputation: 221
I think you had your refund_line_items
formatted incorrectly. Here is what I used:
ShopifyAPI::Refund.calculate({
refund_line_items: order.line_items.map { |li|
{
line_item_id: li.id,
quantity: li.quantity,
restock_type: 'cancel',
}
},
shipping: { full_refund: true },
}, {
params: { order_id: order.id },
})
Upvotes: 2