1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Paypal
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Hosted Pro Checkout Controller
29: *
30: * @category Mage
31: * @package Mage_Paypal
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Paypal_HostedproController extends Mage_Core_Controller_Front_Action
35: {
36: /**
37: * When a customer return to website from gateway.
38: */
39: public function returnAction()
40: {
41: $session = $this->_getCheckout();
42: //TODO: some actions with order
43: if ($session->getLastRealOrderId()) {
44: $this->_redirect('checkout/onepage/success');
45: }
46: }
47:
48: /**
49: * When a customer cancel payment from gateway.
50: */
51: public function cancelAction()
52: {
53: $gotoSection = $this->_cancelPayment();
54: $redirectBlock = $this->_getIframeBlock()
55: ->setGotoSection($gotoSection)
56: ->setTemplate('paypal/hss/redirect.phtml');
57: //TODO: clarify return logic whether customer will be returned in iframe or in parent window
58: $this->getResponse()->setBody($redirectBlock->toHtml());
59: }
60:
61: /**
62: * Cancel order, return quote to customer
63: *
64: * @param string $errorMsg
65: * @return mixed
66: */
67: protected function _cancelPayment($errorMsg = '')
68: {
69: $gotoSection = false;
70: $session = $this->_getCheckout();
71: if ($session->getLastRealOrderId()) {
72: $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
73: if ($order->getId()) {
74: //Cancel order
75: if ($order->getState() != Mage_Sales_Model_Order::STATE_CANCELED) {
76: $order->registerCancellation($errorMsg)->save();
77: }
78: $quote = Mage::getModel('sales/quote')
79: ->load($order->getQuoteId());
80: //Return quote
81: if ($quote->getId()) {
82: $quote->setIsActive(1)
83: ->setReservedOrderId(NULL)
84: ->save();
85: $session->replaceQuote($quote);
86: }
87: //Unset data
88: $session->unsLastRealOrderId();
89: //Redirect to payment step
90: $gotoSection = 'payment';
91: }
92: }
93:
94: return $gotoSection;
95: }
96:
97: /**
98: * Get frontend checkout session object
99: *
100: * @return Mage_Checkout_Model_Session
101: */
102: protected function _getCheckout()
103: {
104: return Mage::getSingleton('checkout/session');
105: }
106:
107: /**
108: * Get iframe block
109: *
110: * @return Mage_Paypal_Block_Hosted_Pro_Iframe
111: */
112: protected function _getIframeBlock()
113: {
114: $this->loadLayout('paypal_hosted_pro_iframe');
115: return $this->getLayout()
116: ->getBlock('hosted.pro.iframe');
117: }
118: }
119: