Ejemplo n.º 1
0
 /**
  * Start Express Checkout by requesting initial token and dispatching customer to PayPal
  */
 public function startAction()
 {
     $responseData = array();
     try {
         $_scheme = Mage::app()->getRequest()->getScheme();
         if ($_scheme == 'https') {
             $_secure = true;
         } else {
             $_secure = false;
         }
         $this->_initCheckout();
         if ($this->_getQuote()->getIsMultiShipping()) {
             $this->_getQuote()->setIsMultiShipping(false);
             $this->_getQuote()->removeAllAddresses();
         }
         $customer = Mage::getSingleton('customer/session')->getCustomer();
         $quoteCheckoutMethod = $this->_getQuote()->getCheckoutMethod();
         if ($customer && $customer->getId()) {
             $this->_checkout->setCustomerWithAddressChange($customer, $this->_getQuote()->getBillingAddress(), $this->_getQuote()->getShippingAddress());
         } elseif ((!$quoteCheckoutMethod || $quoteCheckoutMethod != Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) && !Mage::helper('checkout')->isAllowedGuestCheckout($this->_getQuote(), $this->_getQuote()->getStoreId())) {
             Mage::getSingleton('core/session')->addNotice(Mage::helper('paypal')->__('To proceed to Checkout, please log in using your email address.'));
             $this->redirectLogin();
             Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
             return;
         }
         // billing agreement
         $isBARequested = (bool) $this->getRequest()->getParam(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
         if ($customer && $customer->getId()) {
             $this->_checkout->setIsBillingAgreementRequested($isBARequested);
         }
         $new_mage = $this->isNewMagento();
         // Bill Me Later
         if ($new_mage) {
             $this->_checkout->setIsBml((bool) $this->getRequest()->getParam('bml'));
         }
         // giropay
         $this->_checkout->prepareGiropayUrls(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'checkout/onepage/success', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'onepage/express/cancel', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'checkout/onepage/success');
         // fix for newer magentos
         if ($new_mage) {
             $token = $this->_checkout->start(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'onepage/express/return', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'onepage/express/cancel', 1);
         } else {
             $token = $this->_checkout->start(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'onepage/express/return', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'onepage/express/cancel');
         }
         //
         $this->_initToken($token);
         $paypalUrl = Mage::helper('opc')->getPayPalExpressUrl($token);
         $this->_redirectUrl($paypalUrl);
     } catch (Mage_Core_Exception $e) {
         $this->_getSession()->addError($e->getMessage());
         echo "<script>parent.parent.location.href='" . Mage::helper('checkout/url')->getCartUrl() . "'</script>";
     } catch (Exception $e) {
         $this->_getSession()->addError($this->__('Unable to start Express Checkout.'));
         Mage::logException($e);
         echo "<script>parent.parent.location.href='" . Mage::helper('checkout/url')->getCartUrl() . "'</script>";
     }
 }
Ejemplo n.º 2
0
 /**
  * Start Express Checkout by requesting initial token and dispatching customer to PayPal
  */
 public function startAction()
 {
     try {
         $this->_initCheckout();
         if ($this->_getQuote()->getIsMultiShipping()) {
             $this->_getQuote()->setIsMultiShipping(false);
             $this->_getQuote()->removeAllAddresses();
         }
         //$customer = Mage::getSingleton('customer/session')->getCustomer();
         $customerId = Mage::getSingleton('customer/session')->getCustomerId();
         $customer = Mage::getModel('customer/customer')->load($customerId);
         $quoteCheckoutMethod = $this->_getQuote()->getCheckoutMethod();
         if ($customer && $customer->getId()) {
             $this->_checkout->setCustomerWithAddressChange($customer, $this->_getQuote()->getBillingAddress(), $this->_getQuote()->getShippingAddress());
         } elseif ((!$quoteCheckoutMethod || $quoteCheckoutMethod != Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) && !Mage::helper('checkout')->isAllowedGuestCheckout($this->_getQuote(), $this->_getQuote()->getStoreId())) {
             Mage::getSingleton('core/session')->addNotice(Mage::helper('paypal')->__('To proceed to Checkout, please log in using your email address.'));
             $this->redirectLogin();
             Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
             return;
         }
         // billing agreement
         $isBARequested = (bool) $this->getRequest()->getParam(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
         if ($customer && $customer->getId()) {
             $this->_checkout->setIsBillingAgreementRequested($isBARequested);
         }
         // Bill Me Later
         $this->_checkout->setIsBml((bool) $this->getRequest()->getParam('bml'));
         // giropay
         $this->_checkout->prepareGiropayUrls(Mage::getUrl('checkout/onepage/success'), Mage::getUrl('paypal/express/cancel'), Mage::getUrl('checkout/onepage/success'));
         $button = (bool) $this->getRequest()->getParam(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_BUTTON);
         $token = $this->_checkout->start(Mage::getUrl('*/*/return'), Mage::getUrl('*/*/cancel'), $button);
         if ($token && ($url = $this->_checkout->getRedirectUrl())) {
             $this->_initToken($token);
             $this->getResponse()->setRedirect($url);
             return;
         }
     } catch (Mage_Core_Exception $e) {
         $this->_getCheckoutSession()->addError($e->getMessage());
     } catch (Exception $e) {
         $this->_getCheckoutSession()->addError($this->__('Unable to start Express Checkout.'));
         Mage::logException($e);
     }
     $this->_redirect('checkout/cart');
 }