Created
May 3, 2017 05:52
-
-
Save rintoug/c8f2f7df4bf26ad03f84837423edab56 to your computer and use it in GitHub Desktop.
Create a Custom Payment Method Module in Magento - PaymentController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // app/code/local/Tutsplanet/Localpay/controllers/PaymentController.php | |
| class Tutsplanet_Localpay_PaymentController extends Mage_Core_Controller_Front_Action | |
| { | |
| /** | |
| * Rendering the layout | |
| */ | |
| public function redirectAction() | |
| { | |
| $this->loadLayout(); | |
| $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'localpay', array('template' => 'localpay/redirect.phtml')); | |
| $this->getLayout()->getBlock('content')->append($block); | |
| $this->renderLayout(); | |
| } | |
| /** | |
| * print the output | |
| */ | |
| public function responseAction() | |
| { | |
| if ($this->getRequest()->getQuery("vpc_TxnResponseCode") == 0 || ($this->getRequest()->getQuery("vpc_TxnResponseCode") == '00')) { | |
| $orderId = Mage::getSingleton('checkout/session')->getLastOrderId(); | |
| $order = Mage::getModel('sales/order')->load($orderId); | |
| $comment = 'vpc_Currency=' . $this->getRequest()->getQuery("vpc_Currency"); | |
| $comment .= ',vpc_Message=' . $this->getRequest()->getQuery("vpc_Message"); | |
| $comment .= ',<br>vpc_OrderInfo=' . $this->getRequest()->getQuery("vpc_OrderInfo"); | |
| $comment .= ',vpc_ReceiptNo=' . $this->getRequest()->getQuery("vpc_ReceiptNo"); | |
| $comment .= ',<br>vpc_TransactionNo=' . $this->getRequest()->getQuery("vpc_TransactionNo"); | |
| $comment .= ',vpc_TxnResponseCode=' . $this->getRequest()->getQuery("vpc_TxnResponseCode"); | |
| $comment .= ',<br>vpc_Amount=' . $this->getRequest()->getQuery("vpc_Amount"); | |
| $comment .= ',vpc_Card=' . $this->getRequest()->getQuery("vpc_Card"); | |
| $comment .= ',<br>vpc_CardNum=' . $this->getRequest()->getQuery("vpc_CardNum"); | |
| //$order->addStatusHistoryComment($comment); | |
| $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $comment); | |
| $order->save(); | |
| Mage::getSingleton('checkout/session')->unsQuoteId(); | |
| Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure' => false)); | |
| } else { | |
| if ($lastQuoteId = Mage::getSingleton('checkout/session')->getLastQuoteId()) { | |
| $quote = Mage::getModel('sales/quote')->load($lastQuoteId); | |
| $quote->setIsActive(true)->save(); | |
| } | |
| Mage::getSingleton('core/session')->addError('Error sending mail'); | |
| Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/index', array('_secure' => false)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment