0

I have requirement when done Payment with Paypal using Capture Method.

It automatically creates Invoice.

I need to stop that. How to achieve Programmatically?

1 Answer 1

3

In order to stop create an invoice when customer done Payment with Paypal.

Then need to rewrite class the model class Magento\Paypal\Model\Ipn and stop create invoice at function _registerPaymentCapture

di.xml at app/code/[Vendor]/[Modulename]/etc/

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Paypal\Model\Ipn" type="[Vendor]\[Modulename]\Model\Paypal\Ipn" />
</config>

rewrite class Ipn.php

location: app/code/[Vendor]/[Modulename]/Model/Paypal

<?php
/**
 * @category   [Vendor]
 * @package    [Vendor]_[Modulename]
 * @author     Amit Bera <[email protected]>
 * @website    http://www.amitbera.com
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
namespace [Vendor]\[Modulename]\Model\Paypal;
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Paypal\Model\Info;
class Ipn extends \Magento\Paypal\Model\Ipn
{

    public function __construct(
        \Magento\Paypal\Model\ConfigFactory $configFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
         \Magento\Sales\Model\OrderFactory $orderFactory,
        Info $paypalInfo,
        OrderSender $orderSender,
        CreditmemoSender $creditmemoSender,
        $data = array()
    ) {
        parent::__construct($configFactory, $logger, $curlFactory,
                             $orderFactory, $paypalInfo, $orderSender,$creditmemoSender,$data);
    }
    protected function _registerPaymentCapture($skipFraudDetection = false)
    {
        if ($this->getRequestData('transaction_entity') == 'auth') {
            return;
        }
        $parentTransactionId = $this->getRequestData('parent_txn_id');
        $this->_importPaymentInformation();
        $payment = $this->_order->getPayment();
        $payment->setTransactionId(
            $this->getRequestData('txn_id')
        );
        $payment->setCurrencyCode(
            $this->getRequestData('mc_currency')
        );
        $payment->setPreparedMessage(
            $this->_createIpnComment('')
        );
        $payment->setParentTransactionId(
            $parentTransactionId
        );
        $payment->setShouldCloseParentTransaction(
            'Completed' === $this->getRequestData('auth_status')
        );
        $payment->setIsTransactionClosed(
            0
        );
        $payment->registerCaptureNotification(
            $this->getRequestData('mc_gross'),
            $skipFraudDetection && $parentTransactionId
        );
        $this->_order->save();

        // notify customer
        if ($this->_order->getEmailSent()) {
            $this->orderSender->send($this->_order);

        }
    }

}
2
  • its not work in magento2.3.1 Commented Aug 8, 2019 at 10:09
  • i am using Paypal Express checkout , i need to stop auto invoice create Commented Aug 8, 2019 at 11:18

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.