This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

Step 10. Issue a partial refund

Order processing tutorial

Magento 2.1.3 introduced two endpoints that streamline the process of issuing a refund by creating a creditmemo and updating the order or invoice in one call.

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

In this example, the customer did not like the fit of the Radiant T-M-Orange shirt and wants a refund.

Since the customer paid for the order with a bank transfer, we’ll call POST /V1/order/<order ID>/refund. The order_item_id for the Radiant Tee-M-Orange is 3.

The arguments object allows you to adjust the amount of the credit to be refunded. Since the customer used the tablerate shipping method, which applied to the whole order, we’ll assume that a refund can’t be applied to the shipping costs. Therefore, the shipping_amount is set to 0.

If the customer had selected 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "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.

Verify this step

Log in to Admin. Click Sales > Credit Memos. The credit memo is displayed in the grid.

Congratulations! You’ve finished.

Related topics