00001 <?php
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 class Mage_Paypal_StandardController extends Mage_Core_Controller_Front_Action
00036 {
00037     
00038 
00039 
00040 
00041     protected $_order;
00042 
00043 
00044 
00045 
00046 
00047 
00048     public function getOrder()
00049     {
00050         if ($this->_order == null) {
00051         }
00052         return $this->_order;
00053     }
00054 
00055     protected function _expireAjax()
00056     {
00057         if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
00058             $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
00059             exit;
00060         }
00061     }
00062 
00063 
00064 
00065 
00066 
00067 
00068     public function getStandard()
00069     {
00070         return Mage::getSingleton('paypal/standard');
00071     }
00072 
00073 
00074 
00075 
00076 
00077     public function redirectAction()
00078     {
00079         $session = Mage::getSingleton('checkout/session');
00080         $session->setPaypalStandardQuoteId($session->getQuoteId());
00081         $this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
00082         $session->unsQuoteId();
00083     }
00084 
00085 
00086 
00087 
00088     public function cancelAction()
00089     {
00090         $session = Mage::getSingleton('checkout/session');
00091         $session->setQuoteId($session->getPaypalStandardQuoteId(true));
00092 
00093         
00094         if ($session->getLastRealOrderId()) {
00095             $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
00096             if ($order->getId()) {
00097                 $order->cancel()->save();
00098             }
00099         }
00100 
00101         
00102 
00103         
00104 
00105         
00106         
00107         
00108         $this->_redirect('checkout/cart');
00109     }
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117     public function  successAction()
00118     {
00119         $session = Mage::getSingleton('checkout/session');
00120         $session->setQuoteId($session->getPaypalStandardQuoteId(true));
00121 
00122 
00123 
00124         Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
00125 
00126         
00127 
00128         $this->_redirect('checkout/onepage/success', array('_secure'=>true));
00129     }
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137     public function ipnAction()
00138     {
00139         if (!$this->getRequest()->isPost()) {
00140             $this->_redirect('');
00141             return;
00142         }
00143 
00144         if($this->getStandard()->getDebug()){
00145             $debug = Mage::getModel('paypal/api_debug')
00146                 ->setApiEndpoint($this->getStandard()->getPaypalUrl())
00147                 ->setRequestBody(print_r($this->getRequest()->getPost(),1))
00148                 ->save();
00149         }
00150 
00151         $this->getStandard()->setIpnFormData($this->getRequest()->getPost());
00152         $this->getStandard()->ipnPostSubmit();
00153     }
00154     
00155 }