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 class Mage_AmazonPayments_CbaController extends Mage_Core_Controller_Front_Action
00028 {
00029
00030
00031
00032
00033
00034 public function getCheckout()
00035 {
00036 return Mage::getSingleton('checkout/session');
00037 }
00038
00039
00040
00041
00042
00043
00044 public function getCba()
00045 {
00046 return Mage::getSingleton('amazonpayments/payment_cba');
00047 }
00048
00049
00050
00051
00052
00053 public function shortcutAction()
00054 {
00055 if (!$this->getCba()->isAvailable()) {
00056 $this->_redirect('checkout/cart/');
00057 }
00058 $session = $this->getCheckout();
00059 if ($quoteId = $this->getCheckout()->getQuoteId()) {
00060 $quote = Mage::getModel('sales/quote')->load($quoteId);
00061
00062
00063 if ($quote->hasItems()) {
00064 $session->setAmazonQuoteId($quoteId);
00065
00066 $quote->getPayment()->setMethod($this->getCba()->getCode());
00067 $quote->setIsActive(false);
00068 $quote->save();
00069
00070 $this->getResponse()->setBody($this->getLayout()->createBlock('amazonpayments/cba_redirect')->toHtml());
00071
00072 if ($session->hasData('quote_id_'.Mage::app()->getStore()->getWebsiteId())) {
00073 $session->unsetData('quote_id_'.Mage::app()->getStore()->getWebsiteId());
00074 }
00075 } else {
00076 $this->_redirect('checkout/cart/');
00077 }
00078 } else {
00079 $this->_redirect('checkout/cart/');
00080 }
00081 }
00082
00083
00084
00085
00086
00087 public function successAction()
00088 {
00089 #$amazonOrderID = Mage::app()->getRequest()->getParam('amznPmtsOrderIds');
00090 #$referenceId = Mage::app()->getRequest()->getParam('amznPmtsOrderIds');
00091
00092 $this->getCba()->returnAmazon();
00093
00094 $this->loadLayout();
00095 #$this->_initLayoutMessages('amazonpayments/session');
00096 $this->renderLayout();
00097 }
00098
00099
00100
00101
00102
00103 public function callbackAction()
00104 {
00105 $response = '';
00106 $session = $this->getCheckout();
00107
00108 $_request = Mage::app()->getRequest()->getParams();
00109
00110 try {
00111 if ($_request) {
00112 $response = $this->getCba()->handleCallback($_request);
00113 } else {
00114 $e = new Exception('Inavlid Shipping Address');
00115 }
00116 }
00117 catch (Exception $e) {
00118
00119 $response = $this->getCba()->callbackXmlError($e);
00120 }
00121 echo $response;
00122 exit(0);
00123 }
00124
00125 public function notificationAction()
00126 {
00127 $response = '';
00128 $session = $this->getCheckout();
00129
00130 $_request = Mage::app()->getRequest()->getParams();
00131
00132 try {
00133 $this->getCba()
00134 ->handleNotification($_request);
00135 }
00136 catch (Exception $e) {
00137
00138 $response = $this->getCba()->callbackXmlError($e);
00139 }
00140 $this->getResponse()
00141 ->setHttpResponseCode(200);
00142 }
00143
00144
00145
00146
00147
00148 public function cancelAction()
00149 {
00150 $session = $this->getCheckout();
00151 if ($quoteId = $session->getAmazonQuoteId()) {
00152 $quote = Mage::getModel('sales/quote')->load($quoteId);
00153 $quote->setIsActive(true);
00154 $quote->save();
00155 $session->setQuoteId($quoteId);
00156 }
00157 if ($this->getCba()->getDebug()) {
00158 $_request = Mage::app()->getRequest()->getParams();
00159 $debug = Mage::getModel('amazonpayments/api_debug')
00160 ->setResponseBody(print_r($_request, 1))
00161 ->setRequestBody(time() .' - cancel')
00162 ->save();
00163 }
00164 $this->_redirect('checkout/cart/');
00165 }
00166
00167 }