Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to issue a refund using API in Magento 2

Vinh Jacker | 12-18-2024

How to issue a refund using API in Magento 2

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!

Magento API Integration Service by Mageplaza

Connect your store with any 3rd-party software and boost customer experience quickly and efficiently.

Learn more
Magento API Integration service
x
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services