Beispiel #1
0
 /**
  * Submit the order
  */
 public function placeOrderAction()
 {
     try {
         $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();
         if ($requiredAgreements) {
             $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
             if (array_diff($requiredAgreements, $postedAgreements)) {
                 Mage::throwException(Mage::helper('paypal')->__('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());
             // as well a billing agreement can be created
             $agreement = $this->_checkout->getBillingAgreement();
             if ($agreement) {
                 $session->setLastBillingAgreementId($agreement->getId());
             }
         }
         // recurring profiles may be created along with the order or without it
         $profiles = $this->_checkout->getRecurringPaymentProfiles();
         if ($profiles) {
             $ids = array();
             foreach ($profiles as $profile) {
                 $ids[] = $profile->getId();
             }
             $session->setLastRecurringProfileIds($ids);
         }
         // redirect if PayPal specified some URL (for example, to Giropay bank)
         $url = $this->_checkout->getRedirectUrl();
         if ($url) {
             $this->getResponse()->setRedirect($url);
             return;
         }
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (Mage_Paypal_Model_Api_ProcessableException $e) {
         $this->_processPaypalApiError($e);
     } catch (Mage_Core_Exception $e) {
         Mage::helper('checkout')->sendPaymentFailedEmail($this->_getQuote(), $e->getMessage());
         $this->_getSession()->addError($e->getMessage());
         $this->_redirect('*/*/review');
     } catch (Exception $e) {
         Mage::helper('checkout')->sendPaymentFailedEmail($this->_getQuote(), $this->__('Unable to place the order.'));
         $this->_getSession()->addError($this->__('Unable to place the order.'));
         Mage::logException($e);
         $this->_redirect('*/*/review');
     }
 }
 /** The problem is that Paypal doesn't display the Shipping name that's sent across to it, it's displaying the shipping code.
  *  So to get the shipping options looking pretty in Paypal you just switch around the name and code values
  */
 protected function _prepareShippingOptions(Mage_Sales_Model_Quote_Address $address, $mayReturnEmpty = false, $calculateTax = false)
 {
     $options = parent::_prepareShippingOptions($address, $mayReturnEmpty, $calculateTax);
     foreach ($options as &$option) {
         $tmp = $option->name;
         $option->name = $option->code;
         $option->code = $tmp;
     }
     return $options;
 }
Beispiel #3
0
 /**
  * Submit the order
  */
 public function placeOrderAction()
 {
     try {
         $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());
             // as well a billing agreement can be created
             $agreement = $this->_checkout->getBillingAgreement();
             if ($agreement) {
                 $session->setLastBillingAgreementId($agreement->getId());
             }
         }
         // recurring profiles may be created along with the order or without it
         $profiles = $this->_checkout->getRecurringPaymentProfiles();
         if ($profiles) {
             $ids = array();
             foreach ($profiles as $profile) {
                 $ids[] = $profile->getId();
             }
             $session->setLastRecurringProfileIds($ids);
         }
         // redirect if PayPal specified some URL (for example, to Giropay bank)
         $url = $this->_checkout->getRedirectUrl();
         if ($url) {
             $this->getResponse()->setRedirect($url);
             return;
         }
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (Mage_Core_Exception $e) {
         $this->_getSession()->addError($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError($this->__('Unable to place the order.'));
         Mage::logException($e);
     }
     $this->_redirect('*/*/review');
 }
 /**
  * Return from PayPal and dispatch customer to order review page
  */
 public function returnAction()
 {
     try {
         $this->_initCheckout();
         $this->_checkout->returnFromPaypal($this->_initToken());
         Mage::getSingleton('core/session')->unsPplRedirect();
         echo "<script>parent.parent.location.href='" . Mage::getUrl('paypal/express/review', array('_secure' => true)) . "'</script>";
         return;
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('checkout/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Express Checkout approval.'));
         Mage::logException($e);
     }
     $this->_redirect('checkout/cart', array('_secure' => true));
 }
 /**
  * Return from PayPal and dispatch customer to order review page
  */
 public function returnAction()
 {
     $new_mage = $this->isNewMagento();
     if ($new_mage) {
         // for newer magentos
         if ($this->getRequest()->getParam('retry_authorization') == 'true' && is_array($this->_getCheckoutSession()->getPaypalTransactionData())) {
             $this->_forward('placeOrder');
             return;
         }
         try {
             $this->_getCheckoutSession()->unsPaypalTransactionData();
             $this->_checkout = $this->_initCheckout();
             $this->_checkout->returnFromPaypal($this->_initToken());
             if ($this->_checkout->canSkipOrderReviewStep()) {
                 $this->_forward('placeOrder');
             } else {
                 Mage::getSingleton('core/session')->unsPplRedirect();
                 $this->_redirect('paypal/express/review', array('_secure' => true));
             }
             return;
         } catch (Mage_Core_Exception $e) {
             Mage::getSingleton('checkout/session')->addError($e->getMessage());
         } catch (Exception $e) {
             Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Express Checkout approval.'));
             Mage::logException($e);
         }
         $this->_redirect('checkout/cart');
     } else {
         // for older magentos
         try {
             $this->_initCheckout();
             $this->_checkout->returnFromPaypal($this->_initToken());
             Mage::getSingleton('core/session')->unsPplRedirect();
             echo "<script>parent.parent.location.href='" . Mage::getUrl('paypal/express/review', array('_secure' => true)) . "'</script>";
             return;
         } catch (Mage_Core_Exception $e) {
             Mage::getSingleton('checkout/session')->addError($e->getMessage());
         } catch (Exception $e) {
             Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Express Checkout approval.'));
             Mage::logException($e);
         }
         echo "<script>parent.parent.location.href='" . Mage::getUrl('checkout/cart', array('_secure' => true)) . "'</script>";
     }
 }
 /**
  * Submit the order
  */
 public function placeOrderAction()
 {
     try {
         $this->_initCheckout();
         $order = $this->_checkout->placeOrder($this->_initToken());
         // prepare session to success page
         $quoteId = $this->_getQuote()->getId();
         Mage::getSingleton('checkout/session')->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId)->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId());
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (Mage_Core_Exception $e) {
         $this->_getSession()->addError($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError($this->__('Unable to place the order.'));
         Mage::logException($e);
     }
     $this->_redirect('*/*/review');
 }
 public function place($token, $shippingMethodCode = null)
 {
     $shippingMethodFromReq = Mage::app()->getRequest()->getPost('shipping_method');
     if (!$shippingMethodCode && $shippingMethodFromReq) {
         $this->updateShippingMethod($shippingMethodFromReq);
     }
     try {
         parent::place($token, $shippingMethodCode);
         $orderId = $this->getOrder() instanceof Mage_Sales_Model_Order ? $this->getOrder()->getId() : null;
     } catch (Exception $e) {
         Mage::logException($e);
         $orderId = null;
     }
     $recurringProfiles = $this->getRecurringPaymentProfiles();
     $recurringProfileIds = array();
     foreach ($recurringProfiles as $recProfile) {
         $recurringProfileIds[] = $recProfile->getId();
     }
     Mage::dispatchEvent('aitcheckoutfields_paypal_express_order_place_after', array('order_id' => $orderId, 'recurring_profile_ids' => $recurringProfileIds));
 }
Beispiel #8
0
 /**
  * Set shipping method to quote, if needed
  * @param string $methodCode
  */
 public function updateShippingMethod($methodCode)
 {
     parent::updateShippingMethod($methodCode);
     $this->_quote->save();
 }
 /**
  * Set sandbox flag and get api
  *
  * @return Mage_Paypal_Model_Api_Nvp
  */
 protected function _getApi()
 {
     $this->_setSandboxFlag();
     return parent::_getApi();
 }
Beispiel #10
0
 public function startAction()
 {
     $isNewMage = $this->isNewMagento();
     if (!$isNewMage) {
         try {
             $this->_initCheckout();
             if ($this->_getQuote()->getIsMultiShipping()) {
                 $this->_getQuote()->setIsMultiShipping(false);
                 $this->_getQuote()->removeAllAddresses();
             }
             $customer = Mage::getSingleton('customer/session')->getCustomer();
             if ($customer && $customer->getId()) {
                 $this->_checkout->setCustomerWithAddressChange($customer, null, $this->_getQuote()->getShippingAddress());
             }
             // 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);
             }
             // giropay
             $this->_checkout->prepareGiropayUrls(Mage::getUrl('checkout/onepage/success'), Mage::getUrl('paypal/express/cancel'), Mage::getUrl('checkout/onepage/success'));
             $type = $this->_configMethod;
             $type = str_replace('_', '/', $type);
             $token = $this->_checkout->start(Mage::getUrl($type . '/return'), Mage::getUrl($type . '/cancel'));
             if ($token && ($url = $this->_checkout->getRedirectUrl())) {
                 $this->_initToken($token);
                 echo $token;
                 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);
         }
         echo Mage::getUrl('checkout/cart');
     } else {
         try {
             $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.'));
                 Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
                 $this->setFlag('', 'no-dispatch', true);
                 echo Mage::getUrl('onepage');
                 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);
             $type = $this->_configMethod;
             $type = str_replace('_', '/', $type);
             $token = $this->_checkout->start(Mage::getUrl($type . '/return'), Mage::getUrl($type . '/cancel'), true);
             if ($token && ($url = $this->_checkout->getRedirectUrl())) {
                 $this->_initToken($token);
                 echo $token;
                 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);
         }
         echo Mage::getUrl('checkout/cart');
     }
 }
Beispiel #11
0
 /**
  * Submit the order
  */
 public function placeOrderAction()
 {
     try {
         //            $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();
         //            if ($requiredAgreements) {
         //                $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
         //                if (array_diff($requiredAgreements, $postedAgreements)) {
         //                    Mage::throwException(Mage::helper('paypal')->__('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());
             // as well a billing agreement can be created
             $agreement = $this->_checkout->getBillingAgreement();
             if ($agreement) {
                 $session->setLastBillingAgreementId($agreement->getId());
             }
         }
         // recurring profiles may be created along with the order or without it
         $profiles = $this->_checkout->getRecurringPaymentProfiles();
         if ($profiles) {
             $ids = array();
             foreach ($profiles as $profile) {
                 $ids[] = $profile->getId();
             }
             $session->setLastRecurringProfileIds($ids);
         }
         // redirect if PayPal specified some URL (for example, to Giropay bank)
         $url = $this->_checkout->getRedirectUrl();
         if ($url) {
             $this->getResponse()->setRedirect($url);
             return;
         }
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (Mage_Core_Exception $e) {
         if ($e->getCode() == 3 && $e->getMessage() == 'This customer email already exists') {
             $message = $e->getMessage() . '. If you are sure that it is your email address, <a href="#" onclick="popupPaypalReviewLogin(';
             $message .= "'" . $this->getRequest()->getPost('customer-email') . "'" . ');">click here</a> to login.';
             $this->_getSession()->addError($message);
         } else {
             $this->_getSession()->addError($e->getMessage());
         }
     } catch (Exception $e) {
         $this->_getSession()->addError($this->__('Unable to place the order.'));
         Mage::logException($e);
     }
     $this->_redirect('*/*/review');
 }
 public function start($returnUrl, $cancelUrl, $button = null)
 {
     if (!Mage::helper('imagecc')->isActive()) {
         return parent::start($returnUrl, $cancelUrl, $button);
     }
     $version = Mage::getVersion();
     if (version_compare($version, '1.9.0.0') >= 0) {
         return $this->_start190($returnUrl, $cancelUrl, $button);
     }
     $this->_quote->collectTotals();
     if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
         Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
     }
     $this->_quote->reserveOrderId()->save();
     // prepare API
     $this->_getApi();
     $this->_api->setAmount($this->_quote->getGrandTotal())->setCurrencyCode($this->_quote->getQuoteCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction);
     if ($this->_giropayUrls) {
         list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls;
         $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl));
     }
     $this->_setBillingAgreementRequest();
     $version = Mage::getVersion();
     if (version_compare($version, '1.7.0.0') >= 0) {
         if ($this->_config->requireBillingAddress == Mage_Paypal_Model_Config::REQUIRE_BILLING_ADDRESS_ALL) {
             $this->_api->setRequireBillingAddress(1);
         }
     }
     // supress or export shipping address
     if ($this->_quote->getIsVirtual()) {
         if ($this->_config->requireBillingAddress == Mage_Paypal_Model_Config::REQUIRE_BILLING_ADDRESS_VIRTUAL) {
             $this->_api->setRequireBillingAddress(1);
         }
         $this->_api->setSuppressShipping(true);
     } else {
         $address = $this->_quote->getShippingAddress();
         $isOverriden = 0;
         if (true === $address->validate()) {
             $isOverriden = 1;
             $this->_api->setAddress($address);
         }
         $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden);
         $this->_quote->getPayment()->save();
     }
     // add line items
     $paypalCart = Mage::getModel('paypal/cart', array($this->_quote));
     $this->_api->setPaypalCart($paypalCart)->setIsLineItemsEnabled($this->_config->lineItemsEnabled);
     // add shipping options if needed and line items are available
     if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) {
         if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) {
             if ($options = $this->_prepareShippingOptions($address, true)) {
                 $this->_api->setShippingOptionsCallbackUrl(Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId())))->setShippingOptions($options);
             }
         }
     }
     // add recurring payment profiles information
     if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) {
         foreach ($profiles as $profile) {
             $profile->setMethodCode(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
             if (!$profile->isValid()) {
                 Mage::throwException($profile->getValidationErrors(true, true));
             }
         }
         $this->_api->addRecurringPaymentProfiles($profiles);
     }
     $this->_config->exportExpressCheckoutStyleSettings($this->_api);
     // call API and redirect with token
     $this->_api->callSetExpressCheckout();
     $token = $this->_api->getToken();
     $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token);
     $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
     $this->_quote->getPayment()->save();
     return $token;
 }