/** * 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'); } }
/** * Start Express Checkout by requesting initial token and dispatching customer to PayPal */ public function startAction() { try { $this->_initCheckout(); $token = $this->_checkout->start(Mage::getUrl('*/*/return'), Mage::getUrl('*/*/cancel')); 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'); }
/** * Start Express Checkout by requesting initial token and dispatching customer to PayPal */ public function startAction() { $responseData = array(); 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::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . 'checkout/onepage/success', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true), Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . 'checkout/onepage/success'); $token = $this->_checkout->start(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . 'onepage/express/return', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . 'onepage/express/cancel'); $url = $this->getRequest()->getParam('redirect', false); if ($url) { Mage::getSingleton('core/session')->setExpressRedirect($url); } else { Mage::getSingleton('core/session')->setExpressRedirect('checkout/cart'); } if ($token && ($url = $this->_checkout->getRedirectUrl())) { $this->_initToken($token); $responseData['error'] = false; $responseData['token'] = $token; } } catch (Mage_Core_Exception $e) { $responseData['error'] = true; $responseData['message'] = $e->getMessage(); } catch (Exception $e) { $responseData['error'] = true; $responseData['message'] = $this->__('Unable to start Express Checkout.'); Mage::logException($e); } $this->getResponse()->setHeader('Content-type', 'application/json', true); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($responseData)); }
/** * 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'); }
/** * Submit the order */ public function placeOrderAction() { try { $this->_initCheckout(); $order = $this->_checkout->placeOrder($this->_initToken()); // prepare session to success or cancellation page $quoteId = $this->_getQuote()->getId(); $this->_getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId)->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId()); if ($url = $this->_checkout->getRedirectUrl()) { $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'); }
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'); } }
/** * 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'); }