/** * Set return URL * * @param string $url URL to set * * @return void */ public function setReturnURL($url) { if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable() && \XLite\Core\Request::getInstance()->cancelUrl) { $url = $this->getShopURL(\XLite\Core\Request::getInstance()->cancelUrl, \XLite\Core\Config::getInstance()->Security->customer_security); } parent::setReturnURL($url); }
/** * doActionStartExpressCheckout * * @return void */ protected function doActionStartExpressCheckout() { if (Paypal\Main::isExpressCheckoutEnabled()) { $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $this->getCart()->setPaymentMethod($paymentMethod); $this->updateCart(); \XLite\Core\Session::getInstance()->ec_type = Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; $processor = $paymentMethod->getProcessor(); $token = $processor->doSetExpressCheckout($paymentMethod); if (isset($token)) { \XLite\Core\Session::getInstance()->ec_token = $token; \XLite\Core\Session::getInstance()->ec_date = \XLite\Core\Converter::time(); \XLite\Core\Session::getInstance()->ec_payer_id = null; $processor->redirectToPaypal($token); exit; } else { if (\XLite\Core\Request::getInstance()->inContext) { \XLite\Core\Session::getInstance()->cancelUrl = \XLite\Core\Request::getInstance()->cancelUrl; \XLite\Core\Session::getInstance()->inContextRedirect = true; $this->setReturnURL($this->buildURL('checkout_failed')); } \XLite\Core\TopMessage::getInstance()->addError($processor->getErrorMessage() ?: 'Failure to redirect to PayPal.'); } } }
/** * Return form attributes * * @return array */ protected function getFormAttributes() { $list = parent::getFormAttributes(); if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable()) { $list['data-paypal-id'] = \XLite\Module\CDev\Paypal\Main::getMerchantId(); } return $list; }
/** * Get JS files * * @return array */ public function getJSFiles() { $list = parent::getJSFiles(); if ((!$this->isTokenValid() || \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT !== \XLite\Core\Session::getInstance()->ec_type) && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable()) { $list[] = 'modules/CDev/Paypal/checkout/payment.js'; } return $list; }
/** * Add CSS files * * @return array */ public function getCSSFiles() { $list = parent::getCSSFiles(); $cart = $this->getCart(); if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled($cart)) { $list[] = 'modules/CDev/Paypal/button/add2cart_popup/style.css'; } return $list; }
/** * getJSFiles * * @return array */ public function getJSFiles() { $list = parent::getJSFiles(); if (!\XLite::isAdminZone() && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable()) { $list[] = 'modules/CDev/Paypal/button/in_context.js'; } else { $list[] = 'modules/CDev/Paypal/button/default.js'; } return $list; }
/** * Process 'Add item' success * * @return void */ protected function processAddItemSuccess() { // todo: rewrite add2cartPopup top message block // parent::processAddItemSuccess(); if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled()) { if (!\XLite\Core\Request::getInstance()->expressCheckout) { \XLite\Core\TopMessage::addInfo(new \XLite\Module\CDev\Paypal\View\Button\TopMessage\ExpressCheckout()); } } else { parent::processAddItemSuccess(); } }
/** * getFormDefaultParams * * @return array */ protected function getFormDefaultParams() { $list = parent::getFormDefaultParams(); if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled()) { $list['expressCheckout'] = false; if (\XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable()) { $list['inContext'] = true; $list['cancelUrl'] = $this->isAjax() ? $this->getReferrerURL() : \XLite\Core\URLManager::getSelfURI(); } } return $list; }
/** * doActionStartExpressCheckout * * @return void */ protected function doActionStartExpressCheckout() { if (\XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled()) { $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $this->getCart()->setPaymentMethod($paymentMethod); $this->updateCart(); \XLite\Core\Session::getInstance()->ec_type = \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; $token = $paymentMethod->getProcessor()->doSetExpressCheckout($paymentMethod); if (isset($token)) { \XLite\Core\Session::getInstance()->ec_token = $token; \XLite\Core\Session::getInstance()->ec_date = time(); \XLite\Core\Session::getInstance()->ec_payer_id = null; $paymentMethod->getProcessor()->redirectToPaypal($token); } else { \XLite\Core\TopMessage::getInstance()->addError('Failure to redirect to PayPal.'); } } }
/** * Returns true if widget is visible * * @return boolean */ protected function isVisible() { $cart = $this->getCart(); return parent::isVisible() && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled($cart); }
/** * Check if widget is visible * * @return boolean */ protected function isVisible() { return parent::isVisible() && (!$this->isTokenValid() || \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT !== \XLite\Core\Session::getInstance()->ec_type) && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && \XLite\Module\CDev\Paypal\Main::isInContextCheckoutAvailable(); }
/** * isExpressCheckoutEnabled * * @return void */ protected function isVisible() { return parent::isVisible() && \XLite\Module\CDev\Paypal\Main::isExpressCheckoutEnabled() && $this->getCart() && 0 < $this->getCart()->getTotal(); }
/** * Additional check for PPS * * @return boolean */ public function isEnabled() { $result = parent::isEnabled(); if ($result && Paypal\Main::PP_METHOD_PPS == $this->getServiceName()) { $result = !$this->getProcessor()->isPaypalAdvancedEnabled(); } if (Paypal\Main::PP_METHOD_PC == $this->getServiceName()) { $result = Paypal\Main::isExpressCheckoutEnabled() && $this->getSetting('enabled'); } return $result; }