Example #1
0
 public function getAuthorizationCode()
 {
     unset($this->_logs);
     $context = Context::getContext();
     $is_logged = method_exists($context->customer, 'isLogged') ? $context->customer->isLogged() : $context->cookie->isLogged();
     if ($is_logged) {
         return $this->getRefreshToken();
     }
     $params = array('grant_type' => 'authorization_code', 'code' => Tools::getValue('code'), 'redirect_url' => PayPalLogin::getReturnLink());
     $request = http_build_query($params, '', '&');
     $result = $this->paypal_connect->makeConnection($this->getIdentityAPIURL(), $this->getTokenServiceEndpoint(), $request, false, false, true);
     if ($this->enable_log === true) {
         $handle = fopen(dirname(__FILE__) . '/Results.txt', 'a+');
         fwrite($handle, "Request => " . print_r($request, true) . "\r\n");
         fwrite($handle, "Result => " . print_r($result, true) . "\r\n");
         fwrite($handle, "Journal => " . print_r($this->_logs, true . "\r\n"));
         fclose($handle);
     }
     $result = Tools::jsonDecode($result);
     if ($result) {
         $login = new PayPalLoginUser();
         $customer = $this->getUserInformations($result->access_token, $login);
         if (!$customer) {
             return false;
         }
         $temp = PaypalLoginUser::getByIdCustomer((int) $context->customer->id);
         if ($temp) {
             $login = $temp;
         }
         $login->id_customer = $customer->id;
         $login->token_type = $result->token_type;
         $login->expires_in = (string) (time() + (int) $result->expires_in);
         $login->refresh_token = $result->refresh_token;
         $login->id_token = $result->id_token;
         $login->access_token = $result->access_token;
         $login->save();
         return $login;
     }
 }
Example #2
0
 public function getTrackingCode($method)
 {
     if (_PS_VERSION_ < '1.5' && (_THEME_NAME_ == 'prestashop_mobile' || Tools::getValue('ps_mobile_site') == 1)) {
         if (_PS_MOBILE_TABLET_) {
             return TABLET_TRACKING_CODE;
         } elseif (_PS_MOBILE_PHONE_) {
             return SMARTPHONE_TRACKING_CODE;
         }
     }
     //Get Seamless checkout
     $login_user = false;
     if (Configuration::get('PAYPAL_LOGIN')) {
         $login_user = PaypalLoginUser::getByIdCustomer((int) $this->context->customer->id);
         if ($login_user && $login_user->expires_in <= time()) {
             $obj = new PayPalLogin();
             $login_user = $obj->getRefreshToken();
         }
     }
     if ($method == WPS) {
         if ($login_user) {
             return TRACKING_EXPRESS_CHECKOUT_SEAMLESS;
         } else {
             return TRACKING_INTEGRAL;
         }
     }
     if ($method == HSS) {
         return TRACKING_INTEGRAL_EVOLUTION;
     }
     if ($method == ECS) {
         if ($login_user) {
             return TRACKING_EXPRESS_CHECKOUT_SEAMLESS;
         } else {
             return TRACKING_OPTION_PLUS;
         }
     }
     return TRACKING_CODE;
 }
<?php

header('Content-Type: text/html; charset=utf-8');
include_once dirname(__FILE__) . '/../../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../../init.php';
include_once _PS_MODULE_DIR_ . 'paypal/paypal.php';
include_once _PS_MODULE_DIR_ . 'paypal/paypal_login/paypal_login.php';
include_once _PS_MODULE_DIR_ . 'paypal/paypal_login/PayPalLoginUser.php';
$login = new PayPalLogin();
$obj = $login->getAuthorizationCode();
if ($obj) {
    $context = Context::getContext();
    $customer = new Customer((int) $obj->id_customer);
    $context->cookie->id_customer = (int) $customer->id;
    $context->cookie->customer_lastname = $customer->lastname;
    $context->cookie->customer_firstname = $customer->firstname;
    $context->cookie->logged = 1;
    $customer->logged = 1;
    $context->cookie->is_guest = $customer->isGuest();
    $context->cookie->passwd = $customer->passwd;
    $context->cookie->email = $customer->email;
    $context->customer = $customer;
    $context->cookie->write();
}
?>

<script type="text/javascript">
	window.opener.location.reload(false);
	window.close();
</script>
Example #4
0
    if ($id_product > 0 && $id_product_attribute !== false && $product_quantity > 0) {
        setContextData($ppec);
        if (!$ppec->context->cart->add()) {
            $ppec->logs[] = $ppec->l('Cannot create new cart');
            $display = _PS_VERSION_ < '1.5' ? new BWDisplay() : new FrontController();
            $ppec->context->smarty->assign(array('logs' => $ppec->logs, 'message' => $ppec->l('Error occurred:'), 'use_mobile' => (bool) $ppec->useMobile()));
            $template = 'error.tpl';
        } else {
            $ppec->context->cookie->id_cart = (int) $ppec->context->cart->id;
        }
        $ppec->context->cart->updateQty((int) $product_quantity, (int) $id_product, (int) $id_product_attribute);
        $ppec->context->cart->update();
    }
    $login_user = PaypalLoginUser::getByIdCustomer((int) $ppec->context->customer->id);
    if ($login_user && $login_user->expires_in <= time()) {
        $obj = new PayPalLogin();
        $login_user = $obj->getRefreshToken();
    }
    /* Set details for a payment */
    $ppec->setExpressCheckout($login_user ? $login_user->access_token : false);
    if (Tools::getValue('ajax') && Configuration::get('PAYPAL_IN_CONTEXT_CHECKOUT')) {
        $ppec->displayPaypalInContextCheckout();
    }
    if ($ppec->hasSucceedRequest() && !empty($ppec->token)) {
        $ppec->redirectToAPI();
    } else {
        $ppec->displayPayPalAPIError($ppec->l('Error during the preparation of the Express Checkout payment'), $ppec->logs);
    }
} elseif (!empty($ppec->token) && $ppec->token == $token && ($ppec->payer_id = $payer_id)) {
    /* Get payment infos from paypal */
    $ppec->getExpressCheckout();