/**
  * Place the order when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  * @return Mage_Sales_Model_Order
  */
 public function placeOrder($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     if (!$this->_quote->getCustomerId()) {
         $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
     }
     $this->_ignoreAddressValidation();
     $order = Mage::getModel('sales/service_quote', $this->_quote)->submit();
     $this->_quote->save();
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             // TODO
             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:
             $order->sendNewOrderEmail();
             break;
     }
     return $order;
 }
Beispiel #2
0
 /**
  * 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)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case Mage_Checkout_Model_Type_Onepage::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $parameters = array('quote' => $this->_quote);
     $service = Mage::getModel('Mage_Sales_Model_Service_Quote', $parameters);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $this->_recurringPaymentProfiles = $service->getRecurringPaymentProfiles();
     // TODO: send recurring profile emails
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     $this->_billingAgreement = $order->getPayment()->getBillingAgreement();
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
             // regular placement, when everything is ok
         // 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;
 }