1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class Phoenix_Moneybookers_ProcessingController extends Mage_Core_Controller_Front_Action
21: {
22: 23: 24: 25: 26:
27: protected function _getCheckout()
28: {
29: return Mage::getSingleton('checkout/session');
30: }
31:
32: 33: 34:
35: public function placeformAction()
36: {
37: $this->loadLayout();
38: $this->renderLayout();
39: }
40:
41: 42: 43:
44: public function paymentAction()
45: {
46: try {
47: $session = $this->_getCheckout();
48:
49: $order = Mage::getModel('sales/order');
50: $order->loadByIncrementId($session->getLastRealOrderId());
51: if (!$order->getId()) {
52: Mage::throwException('No order for processing found');
53: }
54: $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
55: Mage::helper('moneybookers')->__('The customer was redirected to Moneybookers.')
56: );
57: $order->save();
58:
59: $session->setMoneybookersQuoteId($session->getQuoteId());
60: $session->setMoneybookersRealOrderId($session->getLastRealOrderId());
61: $session->getQuote()->setIsActive(false)->save();
62: $session->clear();
63:
64: $this->loadLayout();
65: $this->renderLayout();
66: } catch (Exception $e){
67: Mage::logException($e);
68: parent::_redirect('checkout/cart');
69: }
70: }
71:
72: 73: 74:
75: public function successAction()
76: {
77: $event = Mage::getModel('moneybookers/event')
78: ->setEventData($this->getRequest()->getParams());
79: try {
80: $quoteId = $event->successEvent();
81: $this->_getCheckout()->setLastSuccessQuoteId($quoteId);
82: $this->_redirect('checkout/onepage/success');
83: return;
84: } catch (Mage_Core_Exception $e) {
85: $this->_getCheckout()->addError($e->getMessage());
86: } catch(Exception $e) {
87: Mage::logException($e);
88: }
89: $this->_redirect('checkout/cart');
90: }
91:
92: 93: 94: 95: 96:
97: public function cancelAction()
98: {
99: $event = Mage::getModel('moneybookers/event')
100: ->setEventData($this->getRequest()->getParams());
101: $message = $event->cancelEvent();
102:
103:
104: $session = $this->_getCheckout();
105: if ($quoteId = $session->getMoneybookersQuoteId()) {
106: $quote = Mage::getModel('sales/quote')->load($quoteId);
107: if ($quote->getId()) {
108: $quote->setIsActive(true)->save();
109: $session->setQuoteId($quoteId);
110: }
111: }
112:
113: $session->addError($message);
114: $this->_redirect('checkout/cart');
115: }
116:
117: 118: 119: 120:
121: public function statusAction()
122: {
123: $event = Mage::getModel('moneybookers/event')
124: ->setEventData($this->getRequest()->getParams());
125: $message = $event->processStatusEvent();
126: $this->getResponse()->setBody($message);
127: }
128:
129: 130: 131: 132: 133: 134: 135:
136: protected function _redirect($path, $arguments=array())
137: {
138: $this->getResponse()->setBody(
139: $this->getLayout()
140: ->createBlock('moneybookers/redirect')
141: ->setRedirectUrl(Mage::getUrl($path, $arguments))
142: ->toHtml()
143: );
144: return $this;
145: }
146: }
147: