* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7434 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class Ogone extends PaymentModule
{
private $_ignoreKeyList = array('secure_key');
public function __construct()
{
$this->name = 'ogone';
$this->tab = 'payments_gateways';
$this->version = '2.0';
parent::__construct();
$this->displayName = 'Ogone';
$this->description = '';
}
public function install()
{
return (parent::install() AND
$this->registerHook('payment') AND
$this->registerHook('orderConfirmation'));
}
public function getContent()
{
if (Tools::isSubmit('submitOgone'))
{
Configuration::updateValue('OGONE_PSPID', Tools::getValue('OGONE_PSPID'));
Configuration::updateValue('OGONE_SHA_IN', Tools::getValue('OGONE_SHA_IN'));
Configuration::updateValue('OGONE_SHA_OUT', Tools::getValue('OGONE_SHA_OUT'));
Configuration::updateValue('OGONE_MODE', (int)Tools::getValue('OGONE_MODE'));
$dataSync = (($pspid = Configuration::get('OGONE_PSPID'))
? ''
: ''
);
echo $this->displayConfirmation($this->l('Configuration updated').$dataSync);
}
return '
';
}
public function getIgnoreKeyList()
{
return $this->_ignoreKeyList;
}
public function hookPayment($params)
{
global $smarty;
$currency = new Currency((int)($params['cart']->id_currency));
$lang = new Language((int)($params['cart']->id_lang));
$customer = new Customer((int)($params['cart']->id_customer));
$address = new Address((int)($params['cart']->id_address_invoice));
$country = new Country((int)($address->id_country), (int)($params['cart']->id_lang));
$ogoneParams = array();
$ogoneParams['PSPID'] = Configuration::get('OGONE_PSPID');
$ogoneParams['OPERATION'] = 'SAL';
$ogoneParams['ORDERID'] = pSQL($params['cart']->id);
$ogoneParams['AMOUNT'] = number_format(Tools::convertPrice((float)(number_format($params['cart']->getOrderTotal(true, Cart::BOTH), 2, '.', '')), $currency), 2, '.', '') * 100;
$ogoneParams['CURRENCY'] = $currency->iso_code;
$ogoneParams['LANGUAGE'] = $lang->iso_code.'_'.strtoupper($lang->iso_code);
$ogoneParams['CN'] = $customer->lastname;
$ogoneParams['EMAIL'] = $customer->email;
$ogoneParams['OWNERZIP'] = $address->postcode;
$ogoneParams['OWNERADDRESS'] = ($address->address1);
$ogoneParams['OWNERCTY'] = $country->iso_code;
$ogoneParams['OWNERTOWN'] = $address->city;
$ogoneParams['PARAMPLUS'] = 'secure_key='.$params['cart']->secure_key;
if (!empty($address->phone))
$ogoneParams['OWNERTELNO'] = $address->phone;
ksort($ogoneParams);
$shasign = '';
foreach ($ogoneParams as $key => $value)
$shasign .= strtoupper($key).'='.$value.Configuration::get('OGONE_SHA_IN');
$ogoneParams['SHASign'] = strtoupper(sha1($shasign));
$smarty->assign('ogone_params', $ogoneParams);
$smarty->assign('OGONE_MODE', Configuration::get('OGONE_MODE'));
return $this->display(__FILE__, 'ogone.tpl');
}
public function hookOrderConfirmation($params)
{
global $smarty, $cookie;
if ($params['objOrder']->module != $this->name)
return;
if ($params['objOrder']->valid)
$smarty->assign(array('status' => 'ok', 'id_order' => $params['objOrder']->id));
else
$smarty->assign('status', 'failed');
$link = new Link();
$smarty->assign('ogone_link', (method_exists($link, 'getPageLink') ? $link->getPageLink('contact-form.php', true) : Tools::getHttpHost(true).'contact-form.php'));
return $this->display(__FILE__, 'hookorderconfirmation.tpl');
}
public function validate($id_cart, $id_order_state, $amount, $message = '', $secure_key)
{
$this->validateOrder((int)$id_cart, $id_order_state, $amount, $this->displayName, $message, NULL, NULL, true, pSQL($secure_key));
if ($amount > 0 AND class_exists('PaymentCC'))
{
$pcc = new PaymentCC();
$order = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.(int)$secure_cart[0]);
$pcc->id_order = (int)$order['id_order'];
$pcc->id_currency = (int)$order['id_currency'];
$pcc->amount = $amount;
$pcc->transaction_id = Tools::getValue('PAYID');
$pcc->card_number = Tools::getValue('CARDNO');
$pcc->card_brand = Tools::getValue('BRAND');
$pcc->card_expiration = Tools::getValue('ED');
$pcc->card_holder = Tools::getValue('CN');
$pcc->add();
}
}
}