3

I'm working on an extension for Magento (1.4 CE) that needs to be triggered once an order has been paid for. I'm having trouble finding an event to hook in to that will trigger when Paypal IPN (Paypal Standard) has done its thing.

I've tried using the sales_order_invoice_save_after and sales_order_invoice_register events, but neither of these seem to be triggered by a Paypal IPN response.

I'm now trying to use the sales_order_save_after event to detect when the order enters the "processing" status, like so:

class Lightbulb_Blastramp_Model_Observer {

    public function sendOrderToBlastramp(Varien_Event_Observer $observer) {

        Mage::log('Start' . "\n\n", null, 'blastramp.log');

        $order = $observer->getEvent()->getOrder(); // get order data

        // make sure the order is in the processing state
        if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING) {
            Mage::log('Not processing, return.' . "\n\n", null, 'blastramp.log');
            return $this;
        }
        // order has reached "processing" state, do stuff...
    }
}

From the log files I can see that my code is triggered when the order is initially created with the "payment pending" state, but does not get triggered when it moves to the "processing" state. Is there some event I can hook in to that will trigger when an order hits the "processing" stage as set by Paypal IPN?

Cheers

gregdev
  • 1,863
  • 3
  • 23
  • 28

2 Answers2

2

After struggling with this for a while, I eventually had success with this by overriding the _isCaptureFinal($amount) method in Mage_Sales_Model_Order_Payment.

eg.

class Lightbulb_Blastramp_Model_Order_Payment extends Mage_Sales_Model_Order_Payment {
    public function _isCaptureFinal($amount) {
        // do things here
        return parent::_isCaptureFinal($amount);
    }
}

This is thanks to the answer to another question: https://stackoverflow.com/a/5024475/602734

Hopefully this helps someone!

Community
  • 1
  • 1
gregdev
  • 1,863
  • 3
  • 23
  • 28
1

In case anyone stumbled upon this question like i did, an observer that does this as was originally requested;

checkout_onepage_controller_success_action

This returns just the order id, so;

$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);

and you see that the order status is 'processing' and the payment is aproved (or not).

rhif wervl
  • 136
  • 1
  • 1
  • 6