/**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  */
 public function place($token, $shippingMethodCode = null)
 {
     $this->updateShippingMethod($shippingMethodCode);
     $isNewCustomer = $this->_prepareQuote();
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $this->_getApi();
     $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID);
     $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId);
     $doAuthorizationReply = $this->_api->doAuthorization($this->_quote);
     $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply));
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     try {
         $service->submitAll();
         // Any exceptions thrown from submitAll indicate an order that failed
         // to be created. In any such cases, the payment auth needs to be voided.
     } catch (Exception $e) {
         $this->_api->doVoidQuote($this->_quote);
         // Throw an exception for the controller to handle. Needs to indicate
         // the failure to complete the PayPal payment as the PayPal process
         // needs to be restarted once the auth was performed.
         throw Mage::exception('EbayEnterprise_PayPal', $this->_helper->__(EbayEnterprise_Paypal_Model_Express_Api::EBAYENTERPRISE_PAYPAL_API_FAILED));
     }
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     switch ($order->getState()) {
         // Even after placement, paypal can disallow authorize/capture
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
 }
 /**
  * Send do express PayPal checkout request and do authorize PayPal request for the given
  * multi-shipping quote and import the reply data to the quote payment.
  *
  * @param  Mage_Sales_Model_Quote
  * @return self
  */
 public function processPaypalExpressPayment(Mage_Sales_Model_Quote $quote)
 {
     /** @var Mage_Sales_Model_Quote_Payment */
     $payment = $quote->getPayment();
     /** @var Varien_Object */
     $paypalData = new Varien_Object($payment->getAdditionalInformation());
     /** @var string */
     $token = $paypalData->getPaypalExpressCheckoutToken();
     /** @var string */
     $payerId = $paypalData->getPaypalExpressCheckoutPayerId();
     /** @var string */
     $paymentMethod = $payment->getMethod();
     if ($quote->getIsMultiShipping() && $paymentMethod === EbayEnterprise_PayPal_Model_Method_Express::CODE) {
         // Collecting totals in order to get eBay Enterprise Tax total for this quote
         $quote->collectTotals();
         /** @var array */
         $data = array_merge($this->api->doExpressCheckout($quote, $token, $payerId), $this->api->doAuthorization($quote));
         $payment->importData($data);
     }
     return $this;
 }
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  */
 public function place($token, $shippingMethodCode = null)
 {
     $this->updateShippingMethod($shippingMethodCode);
     $isNewCustomer = $this->_prepareQuote();
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $this->_getApi();
     $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID);
     $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId);
     $doAuthorizationReply = $this->_api->doAuthorization($this->_quote);
     $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply));
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     switch ($order->getState()) {
         // Even after placement, paypal can disallow authorize/capture
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
 }