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 class Mage_AmazonPayments_AspController extends Mage_Core_Controller_Front_Action
00035 {
00036
00037
00038
00039
00040
00041 public function getPayment()
00042 {
00043 return Mage::getSingleton('amazonpayments/payment_asp');
00044 }
00045
00046
00047
00048
00049
00050
00051 public function getSession()
00052 {
00053 return Mage::getSingleton('checkout/session');
00054 }
00055
00056
00057
00058
00059
00060
00061 public function payAction()
00062 {
00063 $session = $this->getSession();
00064 $quoteId = $session->getQuoteId();
00065 $lastRealOrderId = $session->getLastRealOrderId();
00066 if (is_null($quoteId) || is_null($lastRealOrderId)){
00067 $this->_redirect('checkout/cart/');
00068 } else {
00069 $session->setAmazonAspQuoteId($quoteId);
00070 $session->setAmazonAspLastRealOrderId($lastRealOrderId);
00071
00072 $order = Mage::getModel('sales/order');
00073 $order->loadByIncrementId($lastRealOrderId);
00074
00075 $payment = $this->getPayment();
00076 $payment->setOrder($order);
00077 $payment->processEventRedirect();
00078
00079 Mage::register('amazonpayments_payment_asp', $payment);
00080 $this->loadLayout();
00081 $this->renderLayout();
00082
00083 $quote = $session->getQuote();
00084 $quote->setIsActive(false);
00085 $quote->save();
00086
00087 $session->setQuoteId(null);
00088 $session->setLastRealOrderId(null);
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097 public function returnSuccessAction()
00098 {
00099 $session = $this->getSession();
00100
00101 $orderId = $session->getAmazonAspLastRealOrderId();
00102 $quoteId = $session->getAmazonAspQuoteId(true);
00103
00104 $order = Mage::getModel('sales/order');
00105 $order->loadByIncrementId($orderId);
00106
00107 if ($order->isEmpty()) { return false;
00108 }
00109
00110 $payment = $this->getPayment();
00111 $payment->setOrder($order);
00112 $payment->processEventReturnSuccess();
00113
00114 $session->setQuoteId($quoteId);
00115 $session->getQuote()->setIsActive(false)->save();
00116 $session->setLastRealOrderId($orderId);
00117
00118 $this->_redirect('checkout/onepage/success');
00119 }
00120
00121
00122
00123
00124
00125
00126 public function returnCancelAction()
00127 {
00128 $session = $this->getSession();
00129 $session->setQuoteId($session->getAmazonAspQuoteId(true));
00130
00131 $order = Mage::getModel('sales/order');
00132 $order->loadByIncrementId($session->getAmazonAspLastRealOrderId());
00133
00134 if ($order->isEmpty()) {
00135 return false;
00136 }
00137
00138 $payment = $this->getPayment();
00139 $payment->setOrder($order);
00140 $payment->processEventReturnCancel();
00141
00142 $this->_redirect('checkout/cart/');
00143 }
00144
00145
00146
00147
00148
00149 public function notificationAction()
00150 {
00151 $this->getPayment()->processNotification($this->getRequest()->getParams());
00152 }
00153 }