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: /**
29: * Paypal Standard Checkout Controller
30: *
31: * @category Mage
32: * @package Mage_Paypal
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Paypal_StandardController extends Mage_Core_Controller_Front_Action
36: {
37: /**
38: * Order instance
39: */
40: protected $_order;
41:
42: /**
43: * Get order
44: *
45: * @return Mage_Sales_Model_Order
46: */
47: public function getOrder()
48: {
49: if ($this->_order == null) {
50: }
51: return $this->_order;
52: }
53:
54: /**
55: * Send expire header to ajax response
56: *
57: */
58: protected function _expireAjax()
59: {
60: if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
61: $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
62: exit;
63: }
64: }
65:
66: /**
67: * Get singleton with paypal strandard order transaction information
68: *
69: * @return Mage_Paypal_Model_Standard
70: */
71: public function getStandard()
72: {
73: return Mage::getSingleton('paypal/standard');
74: }
75:
76: /**
77: * When a customer chooses Paypal on Checkout/Payment page
78: *
79: */
80: public function redirectAction()
81: {
82: $session = Mage::getSingleton('checkout/session');
83: $session->setPaypalStandardQuoteId($session->getQuoteId());
84: $this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
85: $session->unsQuoteId();
86: $session->unsRedirectUrl();
87: }
88:
89: /**
90: * When a customer cancel payment from paypal.
91: */
92: public function cancelAction()
93: {
94: $session = Mage::getSingleton('checkout/session');
95: $session->setQuoteId($session->getPaypalStandardQuoteId(true));
96: if ($session->getLastRealOrderId()) {
97: $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
98: if ($order->getId()) {
99: $order->cancel()->save();
100: }
101: }
102: $this->_redirect('checkout/cart');
103: }
104:
105: /**
106: * when paypal returns
107: * The order information at this point is in POST
108: * variables. However, you don't want to "process" the order until you
109: * get validation from the IPN.
110: */
111: public function successAction()
112: {
113: $session = Mage::getSingleton('checkout/session');
114: $session->setQuoteId($session->getPaypalStandardQuoteId(true));
115: Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
116: $this->_redirect('checkout/onepage/success', array('_secure'=>true));
117: }
118: }
119: