/** * Start Express Checkout by requesting initial token and dispatching customer to PayPal */ public function startAction() { try { $this->_initCheckout(); $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')); $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 { $_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>"; } }
/** * 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() { 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'); }
/** * 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)); }
/** * 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(); 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, $_secure) . 'checkout/onepage/success', Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure), Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, $_secure) . 'checkout/onepage/success'); $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()); } catch (Exception $e) { $this->_getSession()->addError($this->__('Unable to start Express Checkout.')); Mage::logException($e); } }
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; }