This commit is contained in:
rGaillard
2011-07-06 10:54:11 +00:00
parent 4d2c770c6f
commit 8fc7f11014
5398 changed files with 482149 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
{*
* 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: 6844 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<p class="payment_module" height="">
<a href="{$base_dir_ssl}modules/paypal/payment/submit.php" title="{l s='Pay with PayPal' mod='paypal'}">
<img src="{$logo}" alt="{l s='Pay with PayPal' mod='paypal'}" style="float:left;" />
<br />
{if $integral}
{l s='Pay with your PayPal account, credit card (CB, Visa, Mastercard...), or private credit card' mod='paypal'}
{else}
{l s='Pay with your PayPal account' mod='paypal'}
{/if}
<br style="clear:both" />
</a>
</p>
+119
View File
@@ -0,0 +1,119 @@
<?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: 7040 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PaypalPayment extends Paypal
{
protected $_logs = array();
public function PayPalRound($value)
{
return (floor($value * 100) / 100);
}
public function getAuthorisation()
{
global $cookie, $cart;
// Getting cart informations
$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
$vars = '?fromPayPal=1';
$returnURL = Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/paypal/payment/submit.php'.$vars;
$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).'&NOSHIPPING=1';
if (Configuration::get('PAYPAL_PAYMENT_METHOD') == 0)
$request .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
else
$request .= '&SOLUTIONTYPE=Mark&LANDINGPAGE=Login';
$request .= '&LOCALECODE='.strtoupper(Language::getIsoById($cart->id_lang));
if (Configuration::get('PAYPAL_HEADER'))
$request .= '&HDRIMG='.urlencode(Configuration::get('PAYPAL_HEADER'));
// Customer informations
$customer = new Customer((int)$cart->id_customer);
$request .= '&EMAIL='.urlencode($customer->email);//customer
// address of delivery
$id_address = $cart->id_address_delivery;
$address = new Address((int)$id_address);
$country = new Country((int)$address->id_country);
if ($address->id_state)
$state = new State((int)$address->id_state);
$discounts = (float)($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
if ($discounts == 0)
{
$products = $cart->getProducts();
$amt = 0;
for ($i = 0; $i < sizeof($products); $i++)
{
$request .= '&L_NAME'.$i.'='.substr(urlencode($products[$i]['name'].(isset($products[$i]['attributes'])?' - '.$products[$i]['attributes']:'').(isset($products[$i]['instructions'])?' - '.$products[$i]['instructions']:'') ), 0, 127);
$request .= '&L_AMT'.$i.'='.urlencode($this->PayPalRound($products[$i]['price_wt']));
$request .= '&L_QTY'.$i.'='.urlencode($products[$i]['cart_quantity']);
$amt += $this->PayPalRound($products[$i]['price_wt']*$products[$i]['cart_quantity']);
}
$shipping = $this->PayPalRound($cart->getOrderShippingCost($cart->id_carrier, false));
$request .= '&ITEMAMT='.urlencode($amt);
$request .= '&SHIPPINGAMT='.urlencode($shipping);
$request .= '&TAXAMT='.urlencode((float)max($this->PayPalRound($paymentAmount - $amt - $shipping), 0));
}
else
{
$products = $cart->getProducts();
$description = 0;
for ($i = 0; $i < sizeof($products); $i++)
$description .= ($description == ''?'':', ').$products[$i]['cart_quantity']." x ".$products[$i]['name'].(isset($products[$i]['attributes'])?' - '.$products[$i]['attributes']:'').(isset($products[$i]['instructions'])?' - '.$products[$i]['instructions']:'') ;
$request .= '&ORDERDESCRIPTION='.urlencode(substr($description, 0, 120));
}
$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);
$request .= '&ADDROVERRIDE=1';
// 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 getLogs()
{
return $this->_logs;
}
}
+168
View File
@@ -0,0 +1,168 @@
<?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: 7310 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
$useSSL = true;
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/payment/paypalpayment.php');
$paypal = new Paypal();
if (!$paypal->active)
exit;
$ppPayment = new PaypalPayment();
$errors = array();
// #####
// Functions
function getAuthorization()
{
global $ppPayment, $cookie, $cart;
$result = $ppPayment->getAuthorisation();
$logs = $ppPayment->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://'.$ppPayment->getPayPalURL().'/webscr&cmd=_express-checkout&token='.urldecode(strval($cookie->paypal_token)).'&useraction=commit');
exit;
}
else
$logs[] = '<b>'.$ppPayment->l('No token given by PayPal', 'submit').'</b>';
} else
$logs[] = '<b>'.$ppPayment->l('PayPal returned error', 'submit').'</b>';
}
$ppPayment->displayPayPalAPIError($ppPayment->l('Authorisation to PayPal failed', 'submit'), $logs);
}
function displayConfirm()
{
global $cookie, $smarty, $ppPayment, $cart;
if (!$cookie->isLogged(true))
{
header('location:../../../'); exit;
die('Not logged');
}
unset($cookie->paypal_token);
if ($cart->id_currency != $ppPayment->getCurrency((int)$cart->id_currency)->id)
{
$cart->id_currency = (int)($ppPayment->getCurrency((int)$cart->id_currency)->id);
$cookie->id_currency = (int)($cart->id_currency);
$cart->update();
Tools::redirect('modules/'.$ppPayment->name.'/payment/submit.php');
}
// Display all and exit
include(_PS_ROOT_DIR_.'/header.php');
$smarty->assign(array(
'logo' => $ppPayment->getLogo(),
'cust_currency' => $cart->id_currency,
'currency' => $ppPayment->getCurrency((int)$cart->id_currency),
'total' => $cart->getOrderTotal(true, Cart::BOTH),
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'. $ppPayment->name.'/',
'mode' => 'payment/'
));
echo $ppPayment->display('paypal.php', 'confirm.tpl');
include(_PS_ROOT_DIR_.'/footer.php');
die ;
}
function submitConfirm()
{
global $cookie, $smarty, $ppPayment, $cart;
if (!$cookie->isLogged(true))
{
header('location:../../../'); exit;
die('Not logged');
}
elseif (!$id_currency = (int)(Tools::getValue('currency_payement')))
die('No currency');
elseif (!$cart->getOrderTotal(true, Cart::BOTH))
die('Empty cart');
$currency = new Currency((int)($id_currency));
if (!Validate::isLoadedObject($currency))
die('Invalid currency');
$cookie->id_currency = (int)($id_currency);
getAuthorization();
}
function validOrder()
{
global $cookie, $cart, $ppPayment;
if (!$cookie->isLogged(true))
{
header('location:../../../'); exit;
die('Not logged');
}
elseif (!$cart->getOrderTotal(true, Cart::BOTH))
die('Empty cart');
if (!$token = Tools::htmlentitiesUTF8(strval(Tools::getValue('token'))))
{
global $smarty;
$smarty->assign('paypalError', 'Invalid token');
displayConfirm();
die('Invalid token');
}
if ($token != strval($cookie->paypal_token))
die('Invalid cookie token');
if (!$payerID = Tools::htmlentitiesUTF8(strval(Tools::getValue('PayerID'))))
die('Invalid payerID');
$ppPayment->makePayPalAPIValidation($cookie, $cart, $cart->id_currency, $payerID, 'payment');
}
// #####
// Process !!
if (!$cookie->isLogged(true))
die('Not logged');
elseif (!$cart->getOrderTotal(true, Cart::BOTH))
die('Empty cart');
// No submit, confirmation page
if (!Tools::isSubmit('submitPayment') AND !Tools::getValue('fromPayPal'))
displayConfirm();
else
{
if (!isset($cookie->paypal_token) OR !$cookie->paypal_token)
submitConfirm();
validOrder();
}