I'm creating refunds from my app for specific orders.
When I run the refund call, the refund seems to be successful in that it is shown as persisted. But when i check in Shopify the order is unchanged.
This is my refund call code:
refund_calculation = ShopifyAPI::Refund.calculate({ currency: "USD", notify: false, note: "Out of stock", shipping: { "full_refund": false }, refund_line_items: refund_line_items.map { |li| { line_item_id: li.id, quantity: li.quantity, restock_type: 'no_restock', } }, }, { params: { order_id: shopify_order.id }, }) order_refund = ShopifyAPI::Refund.new({ currency: "USD", notify: false, note: "Out of stock", shipping: { "full_refund": false }, refund_line_items: refund_line_items.map { |li| { line_item_id: li.id, quantity: li.quantity, restock_type: 'no_restock' } }, transactions: refund_calculation.transactions.map { |tr| { kind: "refund", gateway: tr.gateway, parent_id: tr.parent_id, amount: tr.amount } }, }, { params: { order_id: shopify_order.id } })
Can anyone point out what I'm doing wrong?
Solved! Go to the solution
Here is the output of the refund call:
#<ShopifyAPI::Refund:0x0000561b935e4700 @attributes= {"currency"=>"USD", "notify"=>false, "note"=>"Out of stock", "shipping"=> #<ShopifyAPI::Refund::Shipping:0x0000561b935e40c0 @attributes={"full_refund"=>false}, @persisted={:params=>{:order_id=>2528875905114}}, @prefix_options={}>, "refund_line_items"=> [#<ShopifyAPI::Refund::RefundLineItem:0x0000561b935ef830 @attributes= {"line_item_id"=>5596452192346, "quantity"=>1, "restock_type"=>"no_restock"}, @persisted={:params=>{:order_id=>2528875905114}}, @prefix_options={}>], "transactions"=> [#<ShopifyAPI::Transaction:0x0000561b935ef038 @attributes= {"kind"=>"refund", "gateway"=>"shopify_payments", "parent_id"=>3161136562266, "amount"=>"11.72"}, @persisted={:params=>{:order_id=>2528875905114}}, @prefix_options={}>]}, @persisted={:params=>{:order_id=>2528875905114}}, @prefix_options={}>
It seems to show the refund was persisted, but nothing shows up in Shopify.
This is an accepted solution.
I found the issue.
I had to specify the order id as a prefix_option and explicitly save the record.
Like this:
# Create refund on Shopify order_refund = ShopifyAPI::Refund.new({ currency: "USD", notify: false, note: "Out of stock", shipping: { "full_refund": false }, refund_line_items: refund_line_items.map { |li| { line_item_id: li.id, quantity: li.quantity, restock_type: 'cancel' } }, transactions: refund_calculation.transactions.map { |tr| { kind: "refund", gateway: tr.gateway, parent_id: tr.parent_id, amount: tr.amount } }, }, { params: { order_id: shopify_order.id } }) order_refund.prefix_options = { order_id: shopify_order.id } order_refund.save
User | Count |
---|---|
16 | |
12 | |
7 | |
6 | |
5 |