0

I'm trying to make online refund using this method:

// \Magento\Sales\Model\Order\Invoice $_invoiceModel
// \Magento\Sales\Model\Order\CreditmemoFactory $_creditmemoFactory
// \Magento\Sales\Model\Service\CreditmemoService $_creditmemoService

$invoiceobj = $this->_invoiceModel->loadByIncrementId('000000073');
$creditmemoObject = $this->_creditmemoFactory->createByOrder($order);
$creditmemoObject->setInvoice($invoiceobj);
$this->_creditmemoService->refund($creditmemoObject);

And I'm receiving following error:

We don't have enough information to save the parent transaction ID.
1
  • try createByInvoice instead of createByOrder and pass the invoice object to it and $creditmemo->setInvoice($invoiceobj); do not need anymore
    – bxN5
    Jun 21, 2017 at 12:39

1 Answer 1

3

Try the service layer. This interface was added in 2.1.3 for exactly this purpose:

\Magento\Sales\Api\RefundInvoiceInterface

// Inject \Magento\Sales\Api\RefundInvoiceInterface $invoiceRefunder
$invoiceRefunder->execute(
    123, // Invoice ID (NOTE: not increment ID)
    [], // Items array (default all)
    true // Online refund--send to payment gateway
);

There are several additional optional arguments for notifying the customer and adding a comment.

If you're curious, you can find the implementation here: https://github.com/magento/magento2/blob/2.1-develop/app/code/Magento/Sales/Model/RefundInvoice.php#L127

4
  • I tried that method too. I placed entity_id instead increment ID but still receiving same error: main.CRITICAL: Magento\Framework\Exception\LocalizedException: We don't have enough information to save the parent transaction ID. in /data/web/magento2/vendor/magento/module-sales/Model/ResourceModel/Order/Payment/Transaction.php:145 Jun 20, 2017 at 1:35
  • Also I debug it and my $txnId is set to zero. What is $txnId? If I try to make online refund from Magento admin panel - it works perfect. But from my code - no Jun 20, 2017 at 1:36
  • What payment method?
    – Ryan Hoerr
    Jun 20, 2017 at 2:46
  • Authorize.NET CIM - authorize and capture Jun 20, 2017 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.