I was trying to understand what's the best way to read incoming IPN messages from PayPal. This need comes from the order workflow we implemented in our website. For example: when a payment is authorized, I would like the order to be set to a particular status. Then, when a payment is captured, I would like the order to be set to another specific status. I believe that IPN is the tool to use when you need the most accurate information about the transaction result, but apparently in Magento 2 it is not easy to reach that message.

So I made a module that extends \Magento\Paypal\Model\Ipn, working with the Magento DI preference way. The module I made resulted in a big copy-paste of a public method and 4 protected methods just to customize 2 of those methods. It is far from ideal. Also, the preference approach can lead to the good old rewrite conflicts.

The plugin approach is not an option, because the methods I needed to intercept are not public.

What I feel is missing here, is some event dispatching. I will open a github issue.

Anyone can suggest some other approach to read the IPN messages?

  • Check sales_order_status_history Table
    – Jackson
    Commented Mar 29, 2017 at 9:36
  • Just wondering if you got any further on this and/or if you can include the github issue as I'm struggling with a very similar problem. Thanks.
    – joesk
    Commented Jun 19, 2017 at 13:46

1 Answer 1

$orderId = 1;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->orderStatusHistorys = $_objectManager->get('Magento\Sales\Model\ResourceModel\Order\Status\History\Collection')->addFieldToFilter('parent_id', $orderId);
foreach ($this->orderStatusHistorys as $orderStatusHistory) {
    $this->orderStatusHistory = $_objectManager->get('Magento\Sales\Api\Data\OrderStatusHistoryInterface')->load($orderStatusHistory->getId());
    echo $this->orderStatusHistory->getComment();
  • Thanks. I was looking for a more robust approach, but I have to admit that yours is not bad.
    – ermannob
    Commented Apr 3, 2017 at 7:40
  • As per @ermannob thanks as this is a completely different way of tackling the problem maybe.
    – joesk
    Commented Jun 19, 2017 at 13:49

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.