Magento 2 Invoice Rest API – Online Refund Payment Process

creditmemoinvoicemagento2ordersrest api

There are some orders on the website that is done by the Paypal online method. Now I want to a partial refund of an order item using the invoice API.

E.g:: /rest/default/V1/invoice/xxxx/refund

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

It is throwing an issue of the Creditmemo Document Validation Error(s):\ The return to stock argument contains a product item that is not part of the original order.

I checked the database of the sale_order_items it is there same order Items id based on the order.

If I follow the blog link: https://www.rakeshjesadiya.com/create-creditmemo-for-order-item-in-magento-2/

Then it does the offline refund, not the online refund.

Can anyone guide how it is possible to do an online refund either using the script or using the API?

Best Answer

Your Payload is wrong.

"return_to_stock_items": [
        1
]

Should be

"return_to_stock_items": [
        20389
]

It should contain the order item ids.

Related Topic