How to Restock via API when payment gateway does not support refunds?

Solved
mistahenry
Tourist
9 0 6

My app helps with returns management. In certain instances, we need to restock returned items without creating a true refund. We flow through the `POST /admin/api/2021-07/orders/{order_id}/refunds/calculate.json` endpoint, get a transaction, and then set the amount to zero for all line items before invoking `POST /admin/api/2021-07/orders/{order_id}/refunds.json` such that we are restocking with a zero dollar refund. To my knowledge, this is the only way to restock via the API.

We have now encountered a customer using a payment gateway that has disabled refund support. In the /admin UI, the "Refund" button does not appear. Instead, a "Restock" button appears. When I attempt to use the `refunds/calculate.json` API, though, I get back zero transactions. How can I restock this items via the API?

Accepted Solution (1)

Accepted Solutions
_JCC_
Shopify Staff
Shopify Staff
170 24 32

This is an accepted solution.

Hey @mistahenry,

The refund endpoint in your instance doesn't need to specify an actual transaction. You can make the refund request to the REST endpoint without specifying a transaction (skipping the calculate step) and simply set all your line item amounts to zero as you do in your other example. Doing this will mean that inventory is returned but no transaction amount is refunded on the order in Shopify. I believe this works for your example where the merchant has disabled refunds for the associated payment gateway on the order.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)
_JCC_
Shopify Staff
Shopify Staff
170 24 32

This is an accepted solution.

Hey @mistahenry,

The refund endpoint in your instance doesn't need to specify an actual transaction. You can make the refund request to the REST endpoint without specifying a transaction (skipping the calculate step) and simply set all your line item amounts to zero as you do in your other example. Doing this will mean that inventory is returned but no transaction amount is refunded on the order in Shopify. I believe this works for your example where the merchant has disabled refunds for the associated payment gateway on the order.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

mistahenry
Tourist
9 0 6

@_JCC_ This worked like a charm for restocking these gateways that don't support refund, thank you so much!

On a related note, I tried the same approach for a true refund, in which the actual refund is done externally but my app attempts to make the books right. More technically, I bypassed the `/calculate` endpoint, and sent back a refund like:

 

{
    "refund": {
        "currency": "MYR",
        "notify": false,
        "refund_line_items": [
            {
                "line_item_id": 123456,
                "quantity": 1,
                "restock_type": "return",
                "amount": 59,
                "location_id": 554324231
            }
        ]
    }
}

 

This worked, but I still notice some strange effects when looking at the sales metrics.
 
If I search total sales, this refund doesn't appear as a "Return" and does not decrement the total sales by the returned amount. Effectively, no matter what I do, Shopify treats my refund as a 0 amount. If I look at Sales Over Time, I see two entries for the Return I did. One with the value -59 and one with 59, which is the same result I get when I do a 0 amount restock. 

What can I do to have this refund be treated as a negative sale to offset the original sale such that Shopify's metrics aren't overstating the sales amount for every returned item in which the payment provider doesn't support refunds? These definitely still get refunded so I really feel like there must be a way. 
mistahenry
Tourist
9 0 6

@_JCC_ here's another thread of people asking essentially my same question (albeit in the context of external refunds when the gateway provider may support refunds):
https://community.shopify.com/c/shopify-apis-and-sdks/create-a-return-without-a-refund-via-api/m-p/1...