// Context part 27
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7812 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -38,13 +38,12 @@ if (!$paypal->active)
|
||||
|
||||
$ppExpress = new PaypalExpress();
|
||||
$errors = array();
|
||||
|
||||
// #####
|
||||
// Functions
|
||||
|
||||
function getAuthorization()
|
||||
{
|
||||
global $ppExpress, $cookie;
|
||||
global $ppExpress;
|
||||
|
||||
$result = $ppExpress->getAuthorisation();
|
||||
$logs = $ppExpress->getLogs();
|
||||
@@ -54,9 +53,9 @@ function getAuthorization()
|
||||
{
|
||||
if (isset($result['TOKEN']))
|
||||
{
|
||||
$cookie->paypal_token = strval($result['TOKEN']);
|
||||
$cookie->paypal_token_date = time();
|
||||
header('Location: https://'.$ppExpress->getPayPalURL().'/webscr&cmd=_express-checkout&token='.urldecode(strval($cookie->paypal_token)));
|
||||
Context::getContext()->cookie->paypal_token = strval($result['TOKEN']);
|
||||
Context::getContext()->cookie->paypal_token_date = time();
|
||||
header('Location: https://'.$ppExpress->getPayPalURL().'/webscr&cmd=_express-checkout&token='.urldecode(strval(Context::getContext()->cookie->paypal_token)));
|
||||
exit;
|
||||
}
|
||||
else
|
||||
@@ -70,7 +69,7 @@ function getAuthorization()
|
||||
|
||||
function getInfos()
|
||||
{
|
||||
global $ppExpress, $cookie;
|
||||
global $ppExpress;
|
||||
|
||||
$result = $ppExpress->getCustomerInfos();
|
||||
$logs = $ppExpress->getLogs();
|
||||
@@ -80,7 +79,7 @@ function getInfos()
|
||||
$logs[] = '<b>'.$ppExpress->l('Cannot retrieve PayPal account information', 'submit').'</b>';
|
||||
$ppExpress->displayPayPalAPIError($ppExpress->l('PayPal returned error', 'submit'), $logs);
|
||||
}
|
||||
elseif (!isset($result['TOKEN']) OR $result['TOKEN'] != $cookie->paypal_token)
|
||||
elseif (!isset($result['TOKEN']) OR $result['TOKEN'] != Context::getContext()->cookie->paypal_token)
|
||||
{
|
||||
$logs[] = '<b>'.$ppExpress->l('Token given by PayPal is not the same as the cookie token', 'submit').'</b>';
|
||||
$ppExpress->displayPayPalAPIError($ppExpress->l('PayPal returned error', 'submit'), $logs);
|
||||
@@ -90,18 +89,16 @@ function getInfos()
|
||||
|
||||
function displayProcess($payerID)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$cookie->paypal_token = strval($cookie->paypal_token);
|
||||
$cookie->paypal_payer_id = $payerID;
|
||||
Context::getContext()->cookie->paypal_token = strval(Context::getContext()->cookie->paypal_token);
|
||||
Context::getContext()->cookie->paypal_payer_id = $payerID;
|
||||
Tools::redirect('index.php?controller=order&step=1&back=paypal');
|
||||
}
|
||||
|
||||
function displayConfirm()
|
||||
{
|
||||
global $cookie, $smarty, $ppExpress, $cart, $payerID;
|
||||
global $ppExpress, $payerID;
|
||||
|
||||
if (!$cookie->isLogged(true))
|
||||
if (!Context::getContext()->cookie->isLogged(true))
|
||||
die('Not logged');
|
||||
if (!$payerID AND !$payerID = Tools::htmlentitiesUTF8(strval(Tools::getValue('payerID'))))
|
||||
die('No payer ID');
|
||||
@@ -109,13 +106,13 @@ function displayConfirm()
|
||||
// Display all and exit
|
||||
include(_PS_ROOT_DIR_.'/header.php');
|
||||
|
||||
$smarty->assign(array(
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'back' => 'paypal',
|
||||
'logo' => $ppExpress->getLogo(),
|
||||
'ppToken' => strval($cookie->paypal_token),
|
||||
'cust_currency' => $cart->id_currency,
|
||||
'currencies' => $ppExpress->getCurrency((int)$cart->id_currency),
|
||||
'total' => $cart->getOrderTotal(true, Cart::BOTH),
|
||||
'ppToken' => strval(Context::getContext()->cookie->paypal_token),
|
||||
'cust_currency' => Context::getContext()->cart->id_currency,
|
||||
'currencies' => $ppExpress->getCurrency((int)Context::getContext()->cart->id_currency),
|
||||
'total' => Context::getContext()->cart->getOrderTotal(true, Cart::BOTH),
|
||||
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'. $ppExpress->name.'/',
|
||||
'payerID' => $payerID,
|
||||
'mode' => 'express/'
|
||||
@@ -128,18 +125,18 @@ function displayConfirm()
|
||||
|
||||
function submitConfirm()
|
||||
{
|
||||
global $cookie, $smarty, $ppExpress, $cart;
|
||||
global $ppExpress;
|
||||
|
||||
if (!$cookie->isLogged(true))
|
||||
if (!Context::getContext()->cookie->isLogged(true))
|
||||
die('Not logged');
|
||||
elseif (!$currency = (int)(Tools::getValue('currency_payement')))
|
||||
die('No currency');
|
||||
elseif (!$payerID = Tools::htmlentitiesUTF8(strval(Tools::getValue('payerID'))))
|
||||
die('No payer ID');
|
||||
elseif (!$cart->getOrderTotal(true, Cart::BOTH))
|
||||
elseif (!Context::getContext()->cart->getOrderTotal(true, Cart::BOTH))
|
||||
die('Empty cart');
|
||||
|
||||
$ppExpress->makePayPalAPIValidation($cookie, $cart, $currency, $payerID, 'express');
|
||||
$ppExpress->makePayPalAPIValidation(Context::getContext()->cookie, Context::getContext()->cart, $currency, $payerID, 'express');
|
||||
}
|
||||
|
||||
function submitAccount()
|
||||
@@ -250,20 +247,20 @@ function submitLogin()
|
||||
|
||||
function displayLogin()
|
||||
{
|
||||
global $cookie, $result, $email, $payerID, $errors, $ppExpress, $smarty;
|
||||
global $result, $email, $payerID, $errors, $ppExpress;
|
||||
|
||||
// Customer exists, login form
|
||||
|
||||
// If customer already logged, check if same mail than PayPal, and go through, or unlog
|
||||
if ($cookie->isLogged(true) AND isset($result['EMAIL']) AND $cookie->email == $result['EMAIL'])
|
||||
if (Context::getContext()->cookie->isLogged(true) AND isset($result['EMAIL']) AND Context::getContext()->cookie->email == $result['EMAIL'])
|
||||
displayProcess($payerID);
|
||||
elseif ($cookie->isLogged(true))
|
||||
$cookie->makeNewLog();
|
||||
elseif (Context::getContext()->cookie->isLogged(true))
|
||||
Context::getContext()->cookie->makeNewLog();
|
||||
|
||||
// Smarty assigns
|
||||
$smarty->assign(array(
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'email' => $email,
|
||||
'ppToken' => strval($cookie->paypal_token),
|
||||
'ppToken' => strval(Context::getContext()->cookie->paypal_token),
|
||||
'errors'=> $errors,
|
||||
'payerID' => $payerID
|
||||
));
|
||||
@@ -277,13 +274,13 @@ function displayLogin()
|
||||
|
||||
function displayAccount()
|
||||
{
|
||||
global $cookie, $result, $email, $payerID, $errors, $ppExpress, $smarty;
|
||||
global $result, $email, $payerID, $errors, $ppExpress;
|
||||
|
||||
// Customer does not exists, signup form
|
||||
|
||||
// If customer already logged, unlog him
|
||||
if ($cookie->isLogged(true))
|
||||
$cookie->makeNewLog();
|
||||
if (Context::getContext()->cookie->isLogged(true))
|
||||
Context::getContext()->cookie->makeNewLog();
|
||||
|
||||
// Generate years, months and days
|
||||
if (isset($_POST['years']) AND is_numeric($_POST['years']))
|
||||
@@ -303,10 +300,10 @@ function displayAccount()
|
||||
{
|
||||
$selectedCountry = Country::getByIso(strval($result['COUNTRYCODE']));
|
||||
}
|
||||
$countries = Country::getCountries((int)($cookie->id_lang), true);
|
||||
$countries = Country::getCountries((int)(Context::getContext()->cookie->id_lang), true);
|
||||
|
||||
// Smarty assigns
|
||||
$smarty->assign(array(
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'years' => $years,
|
||||
'sl_year' => (isset($selectedYears) ? $selectedYears : 0),
|
||||
'months' => $months,
|
||||
@@ -322,7 +319,7 @@ function displayAccount()
|
||||
'city' => (Tools::getValue('city') ? Tools::htmlentitiesUTF8(strval(Tools::getValue('city'))) : (isset($result['SHIPTOCITY']) ? $result['SHIPTOCITY'] : '')),
|
||||
'zip' => (Tools::getValue('postcode') ? Tools::htmlentitiesUTF8(strval(Tools::getValue('postcode'))) : (isset($result['SHIPTOZIP']) ? $result['SHIPTOZIP'] : '')),
|
||||
'payerID' => $payerID,
|
||||
'ppToken' => strval($cookie->paypal_token),
|
||||
'ppToken' => strval(Context::getContext()->cookie->paypal_token),
|
||||
'errors'=> $errors
|
||||
));
|
||||
|
||||
@@ -335,16 +332,16 @@ function displayAccount()
|
||||
|
||||
// #####
|
||||
// Process !!
|
||||
/*if (!$cookie->isLogged(true))
|
||||
/*if (!Context::getContext()->cookie->isLogged(true))
|
||||
{
|
||||
displayAccount();
|
||||
die('Not logged');
|
||||
}*/
|
||||
if (!$cart->getOrderTotal(true, Cart::BOTH))
|
||||
if (!Context::getContext()->cart->getOrderTotal(true, Cart::BOTH))
|
||||
die('Empty cart');
|
||||
|
||||
// No token, we need to get one by making PayPal Authorisation
|
||||
if (!isset($cookie->paypal_token) OR !$cookie->paypal_token)
|
||||
if (!isset(Context::getContext()->cookie->paypal_token) OR !Context::getContext()->cookie->paypal_token)
|
||||
getAuthorization();
|
||||
else
|
||||
{
|
||||
@@ -361,10 +358,10 @@ else
|
||||
// We got an error or we still not submit form
|
||||
if ((!Tools::isSubmit('submitAccount') AND !Tools::isSubmit('submitLogin')) OR sizeof($errors))
|
||||
{
|
||||
if (isset($cookie->paypal_token) AND isset($cookie->paypal_token_date) AND (time() - 10800 > $cookie->paypal_token_date))
|
||||
if (isset(Context::getContext()->cookie->paypal_token) AND isset(Context::getContext()->cookie->paypal_token_date) AND (time() - 10800 > Context::getContext()->cookie->paypal_token_date))
|
||||
{
|
||||
// Token expired, unset it
|
||||
unset($cookie->paypal_token);
|
||||
unset(Context::getContext()->cookie->paypal_token);
|
||||
Tools::redirect('modules/paypal/express/submit.php');
|
||||
}
|
||||
// We didn't submit form, getting PayPal informations
|
||||
@@ -386,7 +383,7 @@ else
|
||||
else
|
||||
{
|
||||
// Error in token, we need to make authorization again
|
||||
unset($cookie->paypal_token);
|
||||
unset(Context::getContext()->cookie->paypal_token);
|
||||
Tools::redirect('modules/paypal/express/submit.php');
|
||||
}
|
||||
if (Customer::customerExists($email) OR Tools::isSubmit('submitLogin'))
|
||||
|
||||
Reference in New Issue
Block a user