Mage_Paypal_ExpressController Class Reference

Inheritance diagram for Mage_Paypal_ExpressController:

Mage_Core_Controller_Front_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

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

Protected Member Functions

 _expireAjax ()


Detailed Description

Express Checkout Controller

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

Definition at line 32 of file ExpressController.php.


Member Function Documentation

_expireAjax (  )  [protected]

Setting right header of response if session died

Definition at line 38 of file ExpressController.php.

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

cancelAction (  ) 

When user camcels transaction on paypal site and return back in store

Definition at line 68 of file ExpressController.php.

00069     {
00070         $this->_redirect('checkout/cart');
00071     }

editAction (  ) 

Definition at line 82 of file ExpressController.php.

00083     {
00084         $this->getResponse()->setRedirect($this->getExpress()->getApi()->getPaypalUrl());
00085     }

errorAction (  ) 

When there's an API error

Definition at line 59 of file ExpressController.php.

00060     {
00061         $this->_redirect('checkout/cart');
00062     }

getExpress (  ) 

Get singleton with paypal express order transaction information

Returns:
Mage_Paypal_Model_Express

Definition at line 51 of file ExpressController.php.

00052     {
00053         return Mage::getSingleton('paypal/express');
00054     }

getReview (  ) 

Get PayPal Onepage checkout model

Returns:
Mage_Paypal_Model_Express_Onepage

Definition at line 118 of file ExpressController.php.

00119     {
00120         return Mage::getSingleton('paypal/express_review');
00121     }

returnAction (  ) 

Return here from Paypal before final payment (continue)

Definition at line 91 of file ExpressController.php.

00092     {
00093         $this->getExpress()->returnFromPaypal();
00094         $this->getResponse()->setRedirect($this->getExpress()->getRedirectUrl());
00095     }

reviewAction (  ) 

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

Definition at line 101 of file ExpressController.php.

00102     {
00103         $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
00104         if ($payment && $payment->getPaypalPayerId()) {
00105             $this->loadLayout();
00106             $this->_initLayoutMessages('paypal/session');
00107             $this->renderLayout();
00108         } else {
00109             $this->_redirect('checkout/cart');
00110         }
00111     }

saveOrderAction (  ) 

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

1- create order 2- place order (call doexpress checkout) 3- save order

We can use configuration data for declare new order status

Definition at line 152 of file ExpressController.php.

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

saveShippingMethodAction (  ) 

Action for ajax request to save selected shipping and return html block

Definition at line 127 of file ExpressController.php.

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

shortcutAction (  ) 

When a customer clicks Paypal button on shopping cart

Definition at line 76 of file ExpressController.php.

00077     {
00078         $this->getExpress()->shortcutSetExpressCheckout();
00079         $this->getResponse()->setRedirect($this->getExpress()->getRedirectUrl());
00080     }

updateOrderAction (  ) 

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

Definition at line 268 of file ExpressController.php.

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


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

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