/** * doExpressCheckoutReturn * * @return void */ protected function doActionExpressCheckoutReturn() { $request = \XLite\Core\Request::getInstance(); $cart = $this->getCart(); \XLite\Module\CDev\Paypal\Main::addLog('doExpressCheckoutReturn()', $request->getData()); if (isset($request->cancel)) { \XLite\Core\Session::getInstance()->ec_token = null; \XLite\Core\Session::getInstance()->ec_date = null; \XLite\Core\Session::getInstance()->ec_payer_id = null; \XLite\Core\Session::getInstance()->ec_type = null; $cart->unsetPaymentMethod(); \XLite\Core\TopMessage::getInstance()->addWarning('Express Checkout process stopped.'); } elseif (!isset($request->token) || $request->token != \XLite\Core\Session::getInstance()->ec_token) { \XLite\Core\TopMessage::getInstance()->addError('Wrong token of Express Checkout.'); } elseif (!isset($request->PayerID)) { \XLite\Core\TopMessage::getInstance()->addError('PayerID value was not returned by PayPal.'); } else { // Express Checkout shortcut flow processing \XLite\Core\Session::getInstance()->ec_type = \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; \XLite\Core\Session::getInstance()->ec_payer_id = $request->PayerID; $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $buyerData = $paymentMethod->getProcessor()->doGetExpressCheckoutDetails($paymentMethod, $request->token); if (empty($buyerData)) { \XLite\Core\TopMessage::getInstance()->addError('Your address data was not received from PayPal.'); } else { // Fill the cart with data received from Paypal $this->requestData = $this->prepareBuyerData($buyerData); $this->updateProfile(); $this->requestData['billingAddress'] = $this->requestData['shippingAddress']; $this->requestData['same_address'] = true; $this->updateShippingAddress(); $this->updateBillingAddress(); } } }
/** * Get publisher id * * @param string $email Email * * @return string */ public function getPublisherId($email) { $publisherId = null; $sellerName = \XLite\Core\Config::getInstance()->Company->company_name; $data = array('sellerName' => $sellerName, 'emailAddress' => $email, 'bnCode' => static::BN_CODE); $request = new \XLite\Core\HTTP\Request(static::END_POINT); if (function_exists('curl_version')) { $request->setAdditionalOption(\CURLOPT_SSLVERSION, 1); $curlVersion = curl_version(); if ($curlVersion && $curlVersion['ssl_version'] && 0 !== strpos($curlVersion['ssl_version'], 'NSS')) { $request->setAdditionalOption(\CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); } } $request->body = json_encode($data); $request->verb = 'POST'; $timeStamp = LC_START_TIME . '000'; $authorization = 'FPA ' . static::CLIENT_KEY; $authorization .= ':' . sha1(static::SHARED_SECRET . $timeStamp); $authorization .= ':' . $timeStamp; $request->setHeader('Authorization', $authorization); $request->setHeader('Accept', 'application/json'); $request->setHeader('Content-Type', 'application/json'); $response = $request->sendRequest(); \XLite\Module\CDev\Paypal\Main::addLog('getPublisherId', $response->body); if (201 == $response->code) { $responseData = json_decode($response->body, true); if ($responseData && isset($responseData['publisherId'])) { $publisherId = $responseData['publisherId']; } } return $publisherId; }
/** * Perform login action * * @return void */ protected function doActionLogin() { $loginApi = new \XLite\Module\CDev\Paypal\Core\Login(); $requestProcessed = false; $returnURL = ''; \XLite\Module\CDev\Paypal\Main::addLog('Login return', \XLite\Core\Request::getInstance()->getData()); if ($loginApi->checkRequest()) { $accessToken = $loginApi->createFromAuthorisationCode(\XLite\Core\Request::getInstance()->code); $profileInfo = isset($accessToken['access_token']) ? $loginApi->getUserinfo($accessToken['access_token']) : null; if ($profileInfo && !empty($profileInfo['user_id']) && !empty($profileInfo['email'])) { $profile = $this->getSocialLoginProfile($profileInfo['email'], 'PayPal', $profileInfo['user_id'], $profileInfo); if ($profile) { if ($profile->isEnabled()) { \XLite\Core\Auth::getInstance()->loginProfile($profile); $accessToken['expirationTime'] = LC_START_TIME + $accessToken['expires_in']; \XLite\Core\Session::getInstance()->paypalAccessToken = $accessToken; // We merge the logged in cart into the session cart $profileCart = $this->getCart(); $profileCart->login($profile); \XLite\Core\Database::getEM()->flush(); if ($profileCart->isPersistent()) { $this->updateCart(); } $returnURL = $this->getAuthReturnURL(); } else { \XLite\Core\TopMessage::addError('Profile is disabled'); $returnURL = $this->getAuthReturnURL(true); } } else { $provider = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $profileInfo['email'], 'order' => null))->getSocialLoginProvider(); if ($provider) { $signInVia = 'Please sign in with ' . $provider . '.'; } else { $signInVia = 'Profile with the same e-mail address already registered. ' . 'Please sign in the classic way.'; } \XLite\Core\TopMessage::addError($signInVia); $returnURL = $this->getAuthReturnURL(true); } $requestProcessed = true; } } if (!$requestProcessed) { \XLite\Core\TopMessage::addError('We were unable to process this request'); $returnURL = ''; } $this->closePopup($returnURL); }
/** * Get URL of the page to display within iframe * * @return string */ protected function getIframeData() { $token = $this->doCreateSecureToken(); $result = $token ? $this->getPostURL($this->iframeURL, $this->getIframeParams($token)) : null; Paypal\Main::addLog('getIframeData()', $result); return $result; }
/** * Redirect customer to Paypal server for authorization and address selection * * @param string $token Express Checkout token * * @return void */ public function redirectToPaypal($token) { $url = $this->getRedirectURL($this->getPostParams($token)); \XLite\Module\CDev\Paypal\Main::addLog('redirectToPaypal()', $url); $page = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body onload="self.location = '{$url}';"> </body> </html> HTML; print $page; }
/** * doExpressCheckoutReturn * * @return void */ protected function doActionExpressCheckoutReturn() { $request = \XLite\Core\Request::getInstance(); $cart = $this->getCart(); Paypal\Main::addLog('doExpressCheckoutReturn()', $request->getData()); $checkoutAction = false; if (isset($request->cancel)) { \XLite\Core\Session::getInstance()->ec_token = null; \XLite\Core\Session::getInstance()->ec_date = null; \XLite\Core\Session::getInstance()->ec_payer_id = null; \XLite\Core\Session::getInstance()->ec_type = null; $cart->unsetPaymentMethod(); \XLite\Core\TopMessage::getInstance()->addWarning('Express Checkout process stopped.'); } elseif (!isset($request->token) || $request->token != \XLite\Core\Session::getInstance()->ec_token) { \XLite\Core\TopMessage::getInstance()->addError('Wrong token of Express Checkout.'); } elseif (!isset($request->PayerID)) { \XLite\Core\TopMessage::getInstance()->addError('PayerID value was not returned by PayPal.'); } else { // Express Checkout shortcut flow processing \XLite\Core\Session::getInstance()->ec_type = Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; \XLite\Core\Session::getInstance()->ec_payer_id = $request->PayerID; $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $processor = $paymentMethod->getProcessor(); $buyerData = $processor->doGetExpressCheckoutDetails($paymentMethod, $request->token); if (empty($buyerData)) { \XLite\Core\TopMessage::getInstance()->addError('Your address data was not received from PayPal.'); } else { // Fill the cart with data received from Paypal $this->requestData = $this->prepareBuyerData($processor, $buyerData); if (!\XLite\Core\Auth::getInstance()->isLogged()) { $this->updateProfile(); } $modifier = $cart->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING'); if ($modifier && $modifier->canApply()) { $this->requestData['billingAddress'] = $this->requestData['shippingAddress']; $this->requestData['same_address'] = true; $this->updateShippingAddress(); $this->updateBillingAddress(); } $this->setCheckoutAvailable(); $this->updateCart(); $this->doActionCheckout(); $checkoutAction = true; } } if (!$checkoutAction) { $this->setReturnURL(\XLite\Core\Request::getInstance()->cancelUrl ?: $this->buildURL('checkout')); } }
/** * Add log message * * @param string $message Text message OPTIONAL * @param mixed $data Data OPTIONAL * * @return void */ protected function addLog($message = null, $data = null) { \XLite\Module\CDev\Paypal\Main::addLog($message, $data); }
/** * Get IPN verification status * * @return boolean TRUE if verification status is received */ protected function getIPNVerification() { $ipnRequest = new \XLite\Core\HTTP\Request($this->getIPNURL()); if (function_exists('curl_version')) { $ipnRequest->setAdditionalOption(\CURLOPT_SSLVERSION, 1); $curlVersion = curl_version(); if ($curlVersion && $curlVersion['ssl_version'] && 0 !== strpos($curlVersion['ssl_version'], 'NSS')) { $ipnRequest->setAdditionalOption(\CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); } } $ipnRequest->body = \XLite\Core\Request::getInstance()->getData(); $ipnResult = $ipnRequest->sendRequest(); if ($ipnResult) { \XLite\Module\CDev\Paypal\Main::addLog('getIPNVerification()', $ipnResult->body); $result = 0 < preg_match('/VERIFIED/i', $ipnResult->body) ? self::IPN_VERIFIED : self::IPN_DECLINED; } else { $result = self::IPN_REQUEST_ERROR; } return $result; }
/** * Get IPN verification status * * @return boolean TRUE if verification status is received */ protected function getIPNVerification() { $ipnRequest = new \XLite\Core\HTTP\Request($this->getIPNURL()); $ipnRequest->body = \XLite\Core\Request::getInstance()->getData(); $ipnResult = $ipnRequest->sendRequest(); if ($ipnResult) { \XLite\Module\CDev\Paypal\Main::addLog('getIPNVerification()', $ipnResult->body); $result = 0 < preg_match('/VERIFIED/i', $ipnResult->body) ? self::IPN_VERIFIED : self::IPN_DECLINED; } else { $result = self::IPN_REQUEST_ERROR; } return $result; }
/** * Do HTTPS request to Paypal server with data set depended on $requestType. * Returns an array represented a parsed response from Paypal * * @param string $requestType Type of request * @param \XLite\Model\Payment\BackendTransaction $transaction Backend transaction object OPTIONAL * * @return array */ protected function doRequest($requestType, $transaction = null) { $responseData = array(); if (!isset($this->transaction)) { $this->transaction = $transaction; } $params = $this->getRequestParams($requestType, $transaction); $request = new \XLite\Core\HTTP\Request($this->getPostURL()); $request->body = $params; $request->verb = 'POST'; $response = $request->sendRequest(); if (200 == $response->code && !empty($response->body)) { $responseData = $this->getParsedResponse($response->body); if (!empty($transaction) && !empty($responseData)) { $this->saveFilteredData($responseData, $transaction); } } \XLite\Module\CDev\Paypal\Main::addLog('doRequest', array('requestType' => $requestType, 'request' => $request->body, 'response' => $response, 'parsedResponse' => $responseData)); return $responseData; }