How to create creditmemo for order item programmatically in magento 2?

We can create credit memo for the specific item based on below way in Magento 2. We need to pass some basic data to generate credit memo in Magento 2.

8 Replies to “How to create creditmemo for order item programmatically in magento 2?”

  1. You can definitely do using CreditmemoFactory but i have taken reference from core Credit memo where original credit memo generates using Magento_Sales module. By above way you can do it single/multiple item credit memo easily.
    You can more details from core Module, Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save.php file

  2. Hi Rakesh Jesadiya,
    I would like to know, if i set do_offline = 0, this return the credit memo amount to customer account / credit card/debit card or to something he/she used to pay online while ordered?

    I need this kind of custom script to refund online.

  3. Hi Rakesh Jesadiya,
    I would like to know, if i set do_offline = 0, this return the credit memo amount to customer account / credit card/debit card or to something he/she used to pay online while ordered?

    I need this kind of custom script to refund online.

  4. How can I pass invoice id? I want to refund for specific items by invoice id. How to pass it?

  5. You can definitely do using CreditmemoFactory but i have taken reference from core Credit memo where original credit memo generates using Magento_Sales module. By above way you can do it single/multiple item credit memo easily.
    You can more details from core Module, MagentoSalesControllerAdminhtmlOrderCreditmemoSave.php file

Leave a Reply