Get Quote/Order ID in Payment Controller – Magento 1.9

checkoutmagento-1.9orderspayment-methods

The payment method I have uses a third party gateway. I need to forward the Increment Order ID to them.

public function getOrderPlaceRedirectUrl() {
    return Mage::getUrl('shopping/checkout/forwardweb', array('_secure' => true));
}

What I would like to do is to get the order and send the $order->getIncrementId().

I tried using $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();

But for some reason, it's always returning the same order id, no matter how many times I check out my cart, and if I go to the website, and list the orders, the new orders are not being added to the list, and it's always empty.

Best Answer

You can get the last order increment id by

$last_order_increment_id = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();

You will need to save reserveOrderId in quote.

Mage_Sales_Model_Quote::reserveOrderId()

Paypal express method doing the same in function

Mage_Paypal_Model_Express_Checkout::start()

You can follow the way it is doing and send your increment id same way for your payment method.

Related Topic