Mage_PaypalUk_ExpressController Class Reference

Inheritance diagram for Mage_PaypalUk_ExpressController:

Mage_Core_Controller_Front_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 getExpress ()
 shortcutAction ()
 cancelAction ()
 returnAction ()
 reviewAction ()
 getReview ()
 saveShippingMethodAction ()
 saveOrderAction ()
 errorAction ()
 updateOrderAction ()

Protected Member Functions

 _expireAjax ()


Detailed Description

Express Checkout Controller

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 33 of file ExpressController.php.


Member Function Documentation

_expireAjax (  )  [protected]

Setting right header of response if session died

Definition at line 39 of file ExpressController.php.

00040     {
00041         if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
00042             $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
00043             exit;
00044         }
00045     }

cancelAction (  ) 

Definition at line 77 of file ExpressController.php.

00078     {
00079         $this->_redirect('checkout/cart');
00080     }

errorAction (  ) 

When there's an API error

Definition at line 260 of file ExpressController.php.

00261     {
00262         $this->_redirect('checkout/cart');
00263     }

getExpress (  ) 

Get singleton with paypal express order transaction information

Returns:
Mage_Paypal_Model_Express

Definition at line 52 of file ExpressController.php.

00053     {
00054         return Mage::getSingleton('paypaluk/express');
00055     }

getReview (  ) 

Get PayPal Onepage checkout model

Returns:
Mage_Paypal_Model_Express_Onepage

Definition at line 114 of file ExpressController.php.

00115     {
00116         return Mage::getSingleton('paypaluk/express_review');
00117     }

returnAction (  ) 

Return here from Paypal before final payment (continue)

Definition at line 86 of file ExpressController.php.

00087     {
00088         $this->getExpress()->returnFromPaypal();
00089 
00090         $this->getResponse()->setRedirect($this->getExpress()->getRedirectUrl());
00091     }

reviewAction (  ) 

Return here from Paypal after final payment (commit) or after on-site order review

Definition at line 97 of file ExpressController.php.

00098     {
00099         $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
00100         if ($payment && $payment->getPaypalPayerId()) {
00101             $this->loadLayout();
00102             $this->_initLayoutMessages('paypaluk/session');
00103             $this->renderLayout();
00104         } else {
00105             $this->_redirect('checkout/cart');
00106         }
00107     }

saveOrderAction (  ) 

Action executed when 'Place Order' button pressed on review page

We can use configuration data for declare new order status

Definition at line 148 of file ExpressController.php.

00149     {
00150         /*
00151         * 1- create order
00152         * 2- place order (call doexpress checkout)
00153         * 3- save order
00154         */
00155         $error_message = '';
00156         $payPalSession = Mage::getSingleton('paypaluk/session');
00157 
00158         try {
00159             $address = $this->getReview()->getQuote()->getShippingAddress();
00160             if (!$address->getShippingMethod()) {
00161                 if ($shippingMethod = $this->getRequest()->getParam('shipping_method')) {
00162                     $this->getReview()->saveShippingMethod($shippingMethod);
00163                  } else if (!$this->getReview()->getQuote()->getIsVirtual()) {
00164                     $payPalSession->addError(Mage::helper('paypalUk')->__('Please select a valid shipping method'));
00165                     $this->_redirect('paypaluk/express/review');
00166                     return;
00167                 }
00168             }
00169             $billing = $this->getReview()->getQuote()->getBillingAddress();
00170             $shipping = $this->getReview()->getQuote()->getShippingAddress();
00171 
00172             $convertQuote = Mage::getModel('sales/convert_quote');
00173             /* @var $convertQuote Mage_Sales_Model_Convert_Quote */
00174             $order = Mage::getModel('sales/order');
00175             /* @var $order Mage_Sales_Model_Order */
00176 
00177             if ($this->getReview()->getQuote()->isVirtual()) {
00178                 $order = $convertQuote->addressToOrder($billing);
00179             } else {
00180                 $order = $convertQuote->addressToOrder($shipping);
00181             }
00182             $order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
00183             $order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
00184             $order->setPayment($convertQuote->paymentToOrderPayment($this->getReview()->getQuote()->getPayment()));
00185 
00186             foreach ($this->getReview()->getQuote()->getAllItems() as $item) {
00187                    $order->addItem($convertQuote->itemToOrderItem($item));
00188             }
00189             /**
00190               * We can use configuration data for declare new order status
00191             */
00192             Mage::dispatchEvent('checkout_type_onepage_save_order', array('order'=>$order, 'quote'=>$this->getReview()->getQuote()));
00193 
00194             //customer checkout from shopping cart page
00195             if (!$order->getCustomerEmail()) {
00196                 $order->setCustomerEmail($shipping->getEmail());
00197             }
00198 
00199             $order->place();
00200 
00201             if (isset($customer) && $customer && $this->getReview()->getQuote()->getCheckoutMethod()==Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER) {
00202                 $customer->save();
00203                 $customer->setDefaultBilling($customerBilling->getId());
00204                 $customerShippingId = isset($customerShipping) ? $customerShipping->getId() : $customerBilling->getId();
00205                 $customer->setDefaultShipping($customerShippingId);
00206                 $customer->save();
00207 
00208                 $order->setCustomerId($customer->getId())
00209                     ->setCustomerEmail($customer->getEmail())
00210                     ->setCustomerPrefix($customer->getPrefix())
00211                     ->setCustomerFirstname($customer->getFirstname())
00212                     ->setCustomerMiddlename($customer->getMiddlename())
00213                     ->setCustomerLastname($customer->getLastname())
00214                     ->setCustomerSuffix($customer->getSuffix())
00215                     ->setCustomerGroupId($customer->getGroupId())
00216                     ->setCustomerTaxClassId($customer->getTaxClassId());
00217 
00218                 $billing->setCustomerId($customer->getId())->setCustomerAddressId($customerBilling->getId());
00219                 $shipping->setCustomerId($customer->getId())->setCustomerAddressId($customerShippingId);
00220             }
00221 
00222         } catch (Mage_Core_Exception $e){
00223             $error_message = $e->getMessage();
00224         } catch (Exception $e){
00225             if (isset($order)) {
00226                 $error_message = $order->getErrors();
00227             } else {
00228                 $error_message = $e->getMessage();
00229             }
00230         }
00231 
00232         if ($error_message) {
00233             $payPalSession->addError($e->getMessage());
00234             $this->_redirect('paypaluk/express/review');
00235             return;
00236         }
00237 
00238         $order->save();
00239 
00240         $this->getReview()->getQuote()->setIsActive(false);
00241         $this->getReview()->getQuote()->save();
00242 
00243         $orderId = $order->getIncrementId();
00244         $this->getReview()->getCheckout()->setLastQuoteId($this->getReview()->getQuote()->getId());
00245         $this->getReview()->getCheckout()->setLastSuccessQuoteId($this->getReview()->getQuote()->getId());
00246         $this->getReview()->getCheckout()->setLastOrderId($order->getId());
00247         $this->getReview()->getCheckout()->setLastRealOrderId($order->getIncrementId());
00248 
00249         $order->sendNewOrderEmail();
00250 
00251         $payPalSession->unsExpressCheckoutMethod();
00252 
00253         $this->_redirect('checkout/onepage/success');
00254     }

saveShippingMethodAction (  ) 

Definition at line 122 of file ExpressController.php.

00123     {
00124         if ($this->getRequest()->getParam('ajax')) {
00125             $this->_expireAjax();
00126         }
00127 
00128         if (!$this->getRequest()->isPost()) {
00129             return;
00130         }
00131 
00132         $data = $this->getRequest()->getParam('shipping_method', '');
00133 
00134         $result = $this->getReview()->saveShippingMethod($data);
00135 
00136         if ($this->getRequest()->getParam('ajax')) {
00137             $this->loadLayout('paypaluk_express_review_details');
00138             $this->getResponse()->setBody($this->getLayout()->getBlock('root')->toHtml());
00139         } else {
00140             $this->_redirect('paypaluk/express/review');
00141         }
00142     }

shortcutAction (  ) 

When a customer clicks Paypal button on shopping cart

Definition at line 61 of file ExpressController.php.

00062     {
00063         /*
00064         * set the express checkout
00065         * retrieve token
00066         */
00067         $this->getExpress()->shortcutSetExpressCheckout();
00068         /*
00069         * rediret to payapl
00070         */
00071         $this->getResponse()->setRedirect($this->getExpress()->getRedirectUrl());
00072     }

updateOrderAction (  ) 

Method to update order if customer used PayPal Express as payment method not a separate checkout from shopping cart

Definition at line 270 of file ExpressController.php.

00270                                         {
00271         $error_message = '';
00272         $payPalSession = Mage::getSingleton('paypal/session');
00273 
00274         $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
00275 
00276         if ($order->getId()) {
00277             $comment = null;
00278             if ($order->canInvoice() && $this->getExpress()->getPaymentAction() == Mage_Paypal_Model_Api_Abstract::PAYMENT_TYPE_SALE) {
00279                 $invoice = $order->prepareInvoice();
00280                 $invoice->register()->capture();
00281                 Mage::getModel('core/resource_transaction')
00282                     ->addObject($invoice)
00283                     ->addObject($invoice->getOrder())
00284                     ->save();
00285 
00286                 $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
00287                 $orderStatus = $this->getExpress()->getConfigData('order_status');
00288                 $comment = Mage::helper('paypal')->__('Invoice #%s created', $invoice->getIncrementId());
00289             } else {
00290                 $this->getExpress()->placeOrder($order->getPayment());
00291 
00292                 $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
00293                 $orderStatus = $this->getExpress()->getConfigData('order_status');
00294             }
00295 
00296             if (!$orderStatus) {
00297                 $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
00298             }
00299             if (!$comment) {
00300                 $comment = Mage::helper('paypal')->__('Customer returned from PayPal site.');
00301             }
00302 
00303             $order->setState($orderState, $orderStatus, $comment, $notified = true);
00304             $order->save();
00305 
00306             Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false);
00307             Mage::getSingleton('checkout/session')->getQuote()->save();
00308 
00309             $order->sendNewOrderEmail();
00310         }
00311 
00312         $payPalSession->unsExpressCheckoutMethod();
00313 
00314         $this->_redirect('checkout/onepage/success');
00315     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:33 2009 for Magento by  doxygen 1.5.8