/**
  * Submit the order
  */
 public function placeOrderAction()
 {
     try {
         $requiredAgreements = $this->_checkoutHelper->getRequiredAgreementIds();
         if ($requiredAgreements) {
             $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
             if (array_diff($requiredAgreements, $postedAgreements)) {
                 Mage::throwException($this->_helper->__('Please agree to all the terms and conditions before placing the order.'));
             }
         }
         $this->_initCheckout();
         $this->_checkout->place($this->_initToken());
         // prepare session to success or cancellation page
         $session = $this->_getCheckoutSession();
         $session->clearHelperData();
         // last successful quote
         $quoteId = $this->_getQuote()->getId();
         $session->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId);
         // an order may be created
         $order = $this->_checkout->getOrder();
         if ($order) {
             $session->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId());
         }
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (EbayEnterprise_PayPal_Exception $e) {
         $this->_checkoutHelper->sendPaymentFailedEmail($this->_getQuote(), $e->getMessage());
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         // If a PayPal exception is thrown while trying to place the order,
         // the PayPal transaction failed or was voided and customer needs to
         // begin PayPal flow again. Place error message in checkout session
         // so it will be displayed in the cart and redirect back to the cart
         // for the checkout flow to begin again.
         $this->_getCheckoutSession()->addError($e->getMessage());
         $this->_redirect('checkout/cart');
     } catch (Mage_Core_Exception $e) {
         $this->_checkoutHelper->sendPaymentFailedEmail($this->_getQuote(), $e->getMessage());
         $this->_getSession()->addError($e->getMessage());
         $this->_redirect('*/*/review');
     } catch (Exception $e) {
         $this->_checkoutHelper->sendPaymentFailedEmail($this->_getQuote(), $this->__('Unable to place the order.'));
         $this->_getSession()->addError($this->__('Unable to place the order.'));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         $this->_redirect('*/*/review');
     }
 }