This commit is contained in:
rGaillard
2011-07-06 10:10:43 +00:00
parent 31d94236ac
commit d1a13007b9
4695 changed files with 0 additions and 339293 deletions
-200
View File
@@ -1,200 +0,0 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
// <![CDATA[
idSelectedCountry = {if isset($smarty.post.id_state)}{$smarty.post.id_state|intval}{else}false{/if};
countries = new Array();
{foreach from=$countries item='country'}
{if isset($country.states)}
countries[{$country.id_country|intval}] = new Array();
{foreach from=$country.states item='state' name='states'}
countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}';
{/foreach}
{/if}
{/foreach}
//]]>
</script>
<h2>{l s='Check your information' mod='paypal'}</h2>
{assign var='current_step' value='login'}
{include file="$tpl_dir./order-steps.tpl"}
{include file="$tpl_dir./errors.tpl"}
<form action="{$base_dir_ssl}modules/paypal/express/submit.php" method="post" id="account-creation_form" class="std">
<fieldset class="account_creation">
<h3>{l s='Your personal information' mod='paypal'}</h3>
<p class="radio required">
<span>{l s='Title'}</span>
<input type="radio" name="id_gender" id="id_gender1" value="1" {if isset($smarty.post.id_gender) && $smarty.post.id_gender == 1}checked="checked"{/if} />
<label for="id_gender1" class="top">{l s='Mr.' mod='paypal'}</label>
<input type="radio" name="id_gender" id="id_gender2" value="2" {if isset($smarty.post.id_gender) && $smarty.post.id_gender == 2}checked="checked"{/if} />
<label for="id_gender2" class="top">{l s='Ms.' mod='paypal'}</label>
</p>
<p class="required text">
<label for="customer_firstname">{l s='First name' mod='paypal'}</label>
<input onkeyup="$('#firstname').val(this.value);" type="text" class="text" id="customer_firstname" name="customer_firstname" value="{$firstname}" />
<sup>*</sup>
</p>
<p class="required text">
<label for="customer_lastname">{l s='Last name' mod='paypal'}</label>
<input onkeyup="$('#lastname').val(this.value);" type="text" class="text" id="customer_lastname" name="customer_lastname" value="{$lastname}" />
<sup>*</sup>
</p>
<p class="required text">
<label for="email">{l s='E-mail' mod='paypal'}</label>
<input type="text" class="text" id="email" name="email" value="{$email}" />
<sup>*</sup>
</p>
<p class="required password">
<label for="password">{l s='Password' mod='paypal'}</label>
<input type="password" class="text" name="passwd" id="passwd" />
<sup>*</sup>
<span class="form_info">{l s='(5 characters min.)' mod='paypal'}</span>
</p>
<p class="select">
<span>{l s='Birthday' mod='paypal'}</span>
<select id="days" name="days">
<option value="">-</option>
{foreach from=$days item=day}
<option value="{$day|escape:'htmlall':'UTF-8'}" {if ($sl_day == $day)} selected="selected"{/if}>{$day|escape:'htmlall':'UTF-8'}&nbsp;&nbsp;</option>
{/foreach}
</select>
{*
{l s='January' mod='paypal'}
{l s='February' mod='paypal'}
{l s='March' mod='paypal'}
{l s='April' mod='paypal'}
{l s='May' mod='paypal'}
{l s='June' mod='paypal'}
{l s='July' mod='paypal'}
{l s='August' mod='paypal'}
{l s='September' mod='paypal'}
{l s='October' mod='paypal'}
{l s='November' mod='paypal'}
{l s='December' mod='paypal'}
*}
<select id="months" name="months">
<option value="">-</option>
{foreach from=$months key=k item=month}
<option value="{$k|escape:'htmlall':'UTF-8'}" {if ($sl_month == $k)} selected="selected"{/if}>{$month}&nbsp;</option>
{/foreach}
</select>
<select id="years" name="years">
<option value="">-</option>
{foreach from=$years item=year}
<option value="{$year|escape:'htmlall':'UTF-8'}" {if ($sl_year == $year)} selected="selected"{/if}>{$year|escape:'htmlall':'UTF-8'}&nbsp;&nbsp;</option>
{/foreach}
</select>
</p>
<p class="checkbox" >
<input type="checkbox" name="newsletter" id="newsletter" value="1" {if isset($smarty.post.newsletter) AND $smarty.post.newsletter == 1} checked="checked"{/if} />
<label for="newsletter">{l s='Sign up for our newsletter' mod='paypal'}</label>
</p>
<p class="checkbox" >
<input type="checkbox"name="optin" id="optin" value="1" {if isset($smarty.post.optin) AND $smarty.post.optin == 1} checked="checked"{/if} />
<label for="optin">{l s='Receive special offers from our partners' mod='paypal'}</label>
</p>
</fieldset>
<fieldset class="account_creation">
<h3>{l s='Your address' mod='paypal'}</h3>
<p class="text">
<label for="company">{l s='Company' mod='paypal'}</label>
<input type="text" class="text" id="company" name="company" value="{if isset($smarty.post.company)}{$smarty.post.company}{/if}" />
</p>
<p class="required text">
<label for="firstname">{l s='First name' mod='paypal'}</label>
<input type="text" class="text" id="firstname" name="firstname" value="{$firstname}" />
<sup>*</sup>
</p>
<p class="required text">
<label for="lastname">{l s='Last name' mod='paypal'}</label>
<input type="text" class="text" id="lastname" name="lastname" value="{$lastname}" />
<sup>*</sup>
</p>
<p class="required text">
<label for="address1">{l s='Address' mod='paypal'}</label>
<input type="text" class="text" name="address1" id="address1" value="{$street}" />
<sup>*</sup>
</p>
<p class="text">
<label for="address2">{l s='Address (2)' mod='paypal'}</label>
<input type="text" class="text" name="address2" id="address2" value="{if isset($smarty.post.address2)}{$smarty.post.address2}{/if}" />
</p>
<p class="required text">
<label for="postcode">{l s='Postal code / Zip code' mod='paypal'}</label>
<input type="text" class="text" name="postcode" id="postcode" value="{$zip}" />
<sup>*</sup>
</p>
<p class="required text">
<label for="city">{l s='City' mod='paypal'}</label>
<input type="text" class="text" name="city" id="city" value="{$city}" />
<sup>*</sup>
</p>
<p class="required select">
<label for="id_country">{l s='Country' mod='paypal'}</label>
<select name="id_country" id="id_country">
<option value="">-</option>
{foreach from=$countries item=v}
<option value="{$v.id_country}" {if ($sl_country == $v.id_country)} selected="selected"{/if}>{$v.name|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
<sup>*</sup>
</p>
<p class="required id_state select">
<label for="id_state">{l s='State' mod='paypal'}</label>
<select name="id_state" id="id_state">
<option value="">-</option>
</select>
<sup>*</sup>
</p>
<p class="textarea">
<label for="other">{l s='Additional information' mod='paypal'}</label>
<textarea name="other" id="other" cols="26" rows="3">{if isset($smarty.post.other)}{$smarty.post.other}{/if}</textarea>
</p>
<p class="text">
<label for="phone">{l s='Home phone' mod='paypal'}</label>
<input type="text" class="text" name="phone" id="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{/if}" />
</p>
<p class="text">
<label for="phone_mobile">{l s='Mobile phone' mod='paypal'}</label>
<input type="text" class="text" name="phone_mobile" id="phone_mobile" value="{if isset($smarty.post.phone_mobile)}{$smarty.post.phone_mobile}{/if}" />
</p>
<p class="required text" id="address_alias">
<label for="alias">{l s='Assign an address title for future reference' mod='paypal'} !</label>
<input type="text" class="text" name="alias" id="alias" value="{if isset($smarty.post.alias)}{$smarty.post.alias}{else}{l s='My address' mod='paypal'}{/if}" />
<sup>*</sup>
</p>
</fieldset>
<p class="cart_navigation required submit">
<input type="hidden" name="token" value="{$ppToken|escape:'htmlall'|stripslashes}" />
<input type="hidden" name="payerID" value="{$payerID|escape:'htmlall'|stripslashes}" />
<input type="submit" name="submitAccount" id="submitAccount" value="{l s='Continue' mod='paypal'}" class="exclusive" />
<span><sup>*</sup>{l s='Required field' mod='paypal'}</span>
</p>
</form>
-52
View File
@@ -1,52 +0,0 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<h2>{l s='Please log in' mod='paypal'}</h2>
{assign var='current_step' value='login'}
{include file="$tpl_dir./order-steps.tpl"}
{include file="$tpl_dir./errors.tpl"}
<form action="{$base_dir_ssl}modules/paypal/express/submit.php" method="post" id="login_form" class="std">
<fieldset>
<h3>{l s='This email has already been registered, please log in !' mod='paypal'}</h3>
<p class="text">
<label for="email" style="text-align:left; margin-left:10px;">{l s='E-mail address' mod='paypal'}</label>
<span><input type="text" id="email" name="email" value="{$email|escape:'htmlall'|stripslashes}" class="account_input" /></span>
</p>
<p class="text">
<label for="passwd" style="text-align:left; margin-left:10px;">{l s='Password' mod='paypal'}</label>
<span><input type="password" id="passwd" name="passwd" value="{$passwd|escape:'htmlall'|stripslashes}" class="account_input" /></span>
</p>
<p class="submit" style="padding-top:15px;">
<input type="hidden" name="token" value="{$ppToken|escape:'htmlall'|stripslashes}" />
<input type="hidden" name="payerID" value="{$payerID|escape:'htmlall'|stripslashes}" />
<input type="submit" id="submitLogin" name="submitLogin" class="button" value="{l s='Log in' mod='paypal'}" />
</p>
<p class="lost_password center"><a href="{$link->getPageLink('password')}">{l s='Forgot your password?' mod='paypal'}</a></p>
</fieldset>
</form>
-104
View File
@@ -1,104 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PaypalExpress extends Paypal
{
protected $_logs = array();
public function getAuthorisation()
{
global $cookie;
// Getting cart informations
$cart = new Cart((int)($cookie->id_cart));
if (!Validate::isLoadedObject($cart))
$this->_logs[] = $this->l('Not a valid cart');
$currency = new Currency((int)($cart->id_currency));
if (!Validate::isLoadedObject($currency))
$this->_logs[] = $this->l('Not a valid currency');
if (sizeof($this->_logs))
return false;
// Making request
$returnURL = Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/paypal/express/submit.php';
$cancelURL = Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'order.php';
$paymentAmount = (float)($cart->getOrderTotal());
$currencyCodeType = strval($currency->iso_code);
$paymentType = Configuration::get('PAYPAL_CAPTURE') == 1 ? 'Authorization' : 'Sale';
$request = '&Amt='.urlencode($paymentAmount).'&PAYMENTACTION='.urlencode($paymentType).'&ReturnUrl='.urlencode($returnURL).'&CANCELURL='.urlencode($cancelURL).'&CURRENCYCODE='.urlencode($currencyCodeType);
if ($this->_pp_integral)
$request .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
else
$request .= '&SOLUTIONTYPE=Mark&LANDINGPAGE=Login';
$request .= '&LOCALECODE='.strtoupper($this->getCountryCode());
if ($this->_header) $request .= '&HDRIMG='.urlencode($this->_header);
// Customer informations
$customer = new Customer((int)$cart->id_customer);
$request .= '&EMAIL='.urlencode($customer->email);//customer
// address of delivery
$address = new Address((int)$cart->id_address_delivery);
$country = new Country((int)$address->id_country);
if ($address->id_state)
$state = new State((int)$address->id_state);
$request .= '&SHIPTONAME='.urlencode($address->firstname.' '.$address->lastname);
$request .= '&SHIPTOSTREET='.urlencode($address->address1);
$request .= '&SHIPTOSTREET2='.urlencode($address->address2);
$request .= '&SHIPTOCITY='.urlencode($address->city);
$request .= '&SHIPTOSTATE='.($address->id_state ? $state->iso_code : $country->iso_code);
$request .= '&SHIPTOZIP='.urlencode($address->postcode);
$request .= '&SHIPTOCOUNTRY='.urlencode($country->iso_code);
$request .= '&SHIPTOPHONENUM='.urlencode($address->phone);
// Calling PayPal API
include(_PS_MODULE_DIR_.'paypal/api/paypallib.php');
$ppAPI = new PaypalLib();
$result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'SetExpressCheckout', $request);
$this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
return $result;
}
public function getCustomerInfos()
{
global $cookie;
// Making request
$request = '&TOKEN='.urlencode(strval($cookie->paypal_token));
// Calling PayPal API
include(_PS_MODULE_DIR_.'paypal/api/paypallib.php');
$ppAPI = new PaypalLib();
$result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'GetExpressCheckoutDetails', $request);
$this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
return $result;
}
public function getLogs()
{
return $this->_logs;
}
}
-27
View File
@@ -1,27 +0,0 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$base_dir_ssl}modules/paypal/express/submit.php"><img src="{$logo}" alt="paypal" title="{l s='Pay with PayPal Express Checkout' mod='paypal'}" /></a>
-379
View File
@@ -1,379 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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/express/paypalexpress.php');
$ppExpress = new PaypalExpress();
$errors = array();
// #####
// Functions
function getAuthorization()
{
global $ppExpress, $cookie;
$result = $ppExpress->getAuthorisation();
$logs = $ppExpress->getLogs();
if (is_array($result) AND sizeof($result))
{
if (strtoupper($result['ACK']) == 'SUCCESS')
{
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)));
exit;
}
else
$logs[] = '<b>'.$ppExpress->l('No token given by PayPal', 'submit').'</b>';
} else
$logs[] = '<b>'.$ppExpress->l('PayPal returned error', 'submit').'</b>';
}
$ppExpress->displayPayPalAPIError($ppExpress->l('Authorisation to PayPal failed', 'submit'), $logs);
}
function getInfos()
{
global $ppExpress, $cookie;
$result = $ppExpress->getCustomerInfos();
$logs = $ppExpress->getLogs();
if (!is_array($result) OR !isset($result['ACK']) OR strtoupper($result['ACK']) != 'SUCCESS')
{
$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)
{
$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);
}
return $result;
}
function displayProcess($payerID)
{
global $cookie;
$cookie->paypal_token = strval($cookie->paypal_token);
$cookie->paypal_payer_id = $payerID;
Tools::redirect('index.php/order?step=1&back=paypal');
}
function displayConfirm()
{
global $cookie, $smarty, $ppExpress, $cart, $payerID;
if (!$cookie->isLogged(true))
die('Not logged');
if (!$payerID AND !$payerID = Tools::htmlentitiesUTF8(strval(Tools::getValue('payerID'))))
die('No payer ID');
// Display all and exit
include(_PS_ROOT_DIR_.'/header.php');
$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),
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'. $ppExpress->name.'/',
'payerID' => $payerID,
'mode' => 'express/'
));
echo $ppExpress->display('paypal.php', 'confirm.tpl');
include(_PS_ROOT_DIR_.'/footer.php');
die ;
}
function submitConfirm()
{
global $cookie, $smarty, $ppExpress, $cart;
if (!$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))
die('Empty cart');
$ppExpress->makePayPalAPIValidation($cookie, $cart, $currency, $payerID, 'express');
}
function submitAccount()
{
global $cookie, $errors, $smarty;
$email = Tools::getValue('email');
if (empty($email) OR !Validate::isEmail($email))
$errors[] = Tools::displayError('e-mail not valid');
elseif (!Validate::isPasswd(Tools::getValue('passwd')))
$errors[] = Tools::displayError('invalid password');
elseif (Customer::customerExists($email))
$errors[] = Tools::displayError('someone has already registered with this e-mail address');
elseif (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND !(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == ''))
$errors[] = Tools::displayError('invalid birthday');
else
{
$customer = new Customer();
if (Tools::isSubmit('newsletter'))
{
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
$customer->newsletter_date_add = pSQL(date('Y-m-d h:i:s'));
}
$customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']));
/* Customer and address, same fields, caching data */
$errors = $customer->validateControler();
$address = new Address();
$address->id_customer = 1;
$errors = array_unique(array_merge($errors, $address->validateControler()));
if (!sizeof($errors))
{
$customer->active = 1;
if (!$customer->add())
$errors[] = Tools::displayError('an error occurred while creating your account');
else
{
$address->id_customer = (int)($customer->id);
if (!$address->add())
$errors[] = Tools::displayError('an error occurred while creating your address');
else
{
if (Mail::Send((int)($cookie->id_lang), 'account', Mail::l('Welcome!'),
array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname))
$smarty->assign('confirmation', 1);
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
Module::hookExec('createAccount', array(
'_POST' => $_POST,
'newCustomer' => $customer
));
// Next !
$payerID = strval(Tools::getValue('payerID'));
displayProcess($payerID);
}
}
}
}
}
function submitLogin()
{
global $cookie, $errors;
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
if (empty($email))
$errors[] = Tools::displayError('e-mail address is required');
elseif (empty($email) OR !Validate::isEmail($email))
$errors[] = Tools::displayError('invalid e-mail address');
elseif (empty($passwd))
$errors[] = Tools::displayError('password is required');
elseif (Tools::strlen($passwd) > 32)
$errors[] = Tools::displayError('password is too long');
elseif (!Validate::isPasswd($passwd))
$errors[] = Tools::displayError('invalid password');
else
{
$customer = new Customer();
$authentication = $customer->getByemail(trim($email), trim($passwd));
/* Handle brute force attacks */
sleep(1);
if (!$authentication OR !$customer->id)
$errors[] = Tools::displayError('authentication failed');
else
{
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->logged = 1;
$cookie->passwd = $customer->passwd;
$cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
$cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
Module::hookExec('authentication');
// Next !
$payerID = strval(Tools::getValue('payerID'));
displayProcess($payerID);
}
}
}
function displayLogin()
{
global $cookie, $result, $email, $payerID, $errors, $ppExpress, $smarty;
// 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'])
displayProcess($payerID);
elseif ($cookie->isLogged(true))
$cookie->makeNewLog();
// Smarty assigns
$smarty->assign(array(
'email' => $email,
'ppToken' => strval($cookie->paypal_token),
'errors'=> $errors,
'payerID' => $payerID
));
// Display all and exit
include(_PS_ROOT_DIR_.'/header.php');
echo $ppExpress->display('paypal.php', 'express/login.tpl');
include(_PS_ROOT_DIR_.'/footer.php');
die ;
}
function displayAccount()
{
global $cookie, $result, $email, $payerID, $errors, $ppExpress, $smarty;
// Customer does not exists, signup form
// If customer already logged, unlog him
if ($cookie->isLogged(true))
$cookie->makeNewLog();
// Generate years, months and days
if (isset($_POST['years']) AND is_numeric($_POST['years']))
$selectedYears = (int)($_POST['years']);
$years = Tools::dateYears();
if (isset($_POST['months']) AND is_numeric($_POST['months']))
$selectedMonths = (int)($_POST['months']);
$months = Tools::dateMonths();
if (isset($_POST['days']) AND is_numeric($_POST['days']))
$selectedDays = (int)($_POST['days']);
$days = Tools::dateDays();
// Select the most appropriate country
if (Tools::getValue('id_country'))
$selectedCountry = (int)(Tools::getValue('id_country'));
else
$selectedCountry = Country::getByIso(strval($result['COUNTRYCODE']));
$countries = Country::getCountries((int)($cookie->id_lang), true);
// Smarty assigns
$smarty->assign(array(
'years' => $years,
'sl_year' => (isset($selectedYears) ? $selectedYears : 0),
'months' => $months,
'sl_month' => (isset($selectedMonths) ? $selectedMonths : 0),
'days' => $days,
'sl_day' => (isset($selectedDays) ? $selectedDays : 0),
'countries' => $countries,
'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0),
'email' => $email,
'firstname' => (Tools::getValue('customer_firstname') ? Tools::htmlentitiesUTF8(strval(Tools::getValue('customer_firstname'))) : $result['FIRSTNAME']),
'lastname' => (Tools::getValue('customer_lastname') ? Tools::htmlentitiesUTF8(strval(Tools::getValue('customer_lastname'))) : $result['LASTNAME']),
'street' => (Tools::getValue('address1') ? Tools::htmlentitiesUTF8(strval(Tools::getValue('address1'))) : (isset($result['SHIPTOSTREET']) ? $result['SHIPTOSTREET'] : '')),
'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),
'errors'=> $errors
));
// Display all and exit
include(_PS_ROOT_DIR_.'/header.php');
echo $ppExpress->display('paypal.php', 'express/authentication.tpl');
include(_PS_ROOT_DIR_.'/footer.php');
die ;
}
// #####
// Process !!
// No token, we need to get one by making PayPal Authorisation
if (!isset($cookie->paypal_token) OR !$cookie->paypal_token)
getAuthorization();
else
{
// We have token, we need to confirm user informations (login or signup)
if ((int)(Tools::getValue('confirm')))
displayConfirm();
elseif (Tools::isSubmit('submitAccount'))
submitAccount();
elseif (Tools::isSubmit('submitLogin'))
submitLogin();
elseif (Tools::isSubmit('submitPayment'))
submitConfirm();
// 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))
{
// Token expired, unset it
unset($cookie->paypal_token);
Tools::redirect('modules/paypal/express/submit.php');
}
// We didn't submit form, getting PayPal informations
if (!Tools::isSubmit('submitAccount') AND !Tools::isSubmit('submitLogin'))
$result = getInfos();
if (Tools::getValue('email') AND Tools::getValue('payerID'))
{
// Form was submitted (errors)
$email = Tools::htmlentitiesUTF8(strval(Tools::getValue('email')));
$payerID = Tools::htmlentitiesUTF8(strval(Tools::getValue('payerID')));
}
elseif (isset($result['EMAIL']) AND isset($result['PAYERID']))
{
// Displaying form for the first time
$email = $result['EMAIL'];
$payerID = $result['PAYERID'];
}
else
{
// Error in token, we need to make authorization again
unset($cookie->paypal_token);
Tools::redirect('modules/paypal/express/submit.php');
}
if (Customer::customerExists($email) OR Tools::isSubmit('submitLogin'))
displayLogin();
displayAccount();
}
}