Magento 2 API Issue Refund

Refund is the term that no store owner wants to hear. However, no matter how the merchants avoid it, there are many cases in a Magento store when the customers ask for refunds. Therefore, it is essential for any online store to have a transparent and straightforward refund policy. And for any Magento 2 store owners, it’s important to know how to issue a refund in Magento 2 with API.

In this article, I will demonstrate how to issue a refund using API in Magento 2 through the below steps:

Step 1: Issue The Refund

Magento 2.1.3 comes with two endpoints that simplify the process of issuing a refund by creating a credit memo and updating the order or invoice in one call.

Endpoint Description
POST /V1/order//refund Issues an offline refund
POST /V1/invoice//refund Issue a refund with an online payment system

To illustrate the process of issuing a refund in Magento 2 accurately, I take the below example:

The customer is not satisfied with the fit of the Radiant T-M-Orange shirt and requires a refund.

  • This customer made the payment with a bank transfer so that we will make the call POST /V1/order/<order ID>/refund. Then we get the order_item_id for the product is 3.
  • With the arguments object, you can adjust the amount of the credit to be refunded.
  • Because the customer used the tablerate shipping method, which applied to the whole order, we will assume that a refund can’t be applied to the shipping costs. Hence, the shipping_amount is set to 0.
  • If the customer had used the flatrate shipping method ($5 per item), we would set the value of shipping_amount to 5.
  • The return_to_stock_items array specifies which order_item_ids can be returned to stock and be resold.

Endpoint

POST <host>/rest/<store_code>/V1/order/5/refund

Headers

Content-Type application/json

Authorization Bearer <administrator token>

Payload

{
  "items": [
    {
      "order_item_id": 3,
      "qty": 1
    }
  ],
  "notify": true,
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        3
      ]
    }
  }
}

Response

A credit memo id, such as 3.

Step 2: Verify The Results

  • Access your admin panel.
  • Navigate to Sales > Credit Memos, here you will see the credit memo shown in the grid.

Conclusion

Above are the detailed instruction for issuing the refund with Magento 2 API. I hope that this post is helpful for you. If you have any questions or want to discuss something related to this post, don’t hesitate to leave a comment below!

Enjoyed the tutorial? Spread it to your friends!