bebeboutik/modules/atos_cyberplus/atos_cyberplus.php

104 lines
4.7 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
class Atos_cyberplus extends PaymentModule
{
public function __construct()
{
$this->name = 'atos_cyberplus';
$this->tab = 'payments_gateways';
$this->version = 1.0;
/* The parent construct is required for translations */
parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Atos');
$this->description = $this->l('This payment module for banks using ATOS allows your customers to pay by Credit Card');
}
public function install()
{
Configuration::updateValue('ATOS_MERCHANT_ID', '038862749811111');
parent::install();
$this->registerHook('payment');
}
public function uninstall()
{
Configuration::deleteByName('ATOS_MERCHANT_ID');
parent::uninstall();
}
public function _displayForm()
{
if (!isset($_POST['submit']))
$_POST['merchant_id'] = Configuration::get('ATOS_MERCHANT_ID');
$this->_html .=
'<fieldset>
<legend>Settings</legend>
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
<label>'.$this->l('Merchant ID').'&nbsp;</label><input type="text" name="merchant_id" value="'.(isset($_POST['merchant_id']) ? $_POST['merchant_id'] : '').'" /><br /><br />
<input type="submit" name="submit" value="'.$this->l('Update settings').'" class="button" />
</form>
</fieldset>';
}
private function _postProcess()
{
Configuration::updateValue('ATOS_MERCHANT_ID', $_POST['merchant_id']);
}
private function _postValidation()
{
if(!isset($_POST['merchant_id']) OR empty($_POST['merchant_id']))
$this->_postErrors[] = 'You must enter a merchant ID.';
elseif (!is_numeric($_POST['merchant_id']))
$this->_postErrors[] = 'Your merchant ID is not valid.';
}
function getContent()
{
$this->_html .= '<h2>'.$this->displayName.'</h2>';
if (!empty($_POST))
{
$this->_postValidation();
if (!count($this->_postErrors))
$this->_postProcess();
else
foreach ($this->_postErrors AS $err)
$this->_html .= '<div class="errmsg">'. $err .'</div><br />';
}
$this->_displayForm();
return $this->_html;
}
public function hookPayment($params)
{
global $cart, $cookie;
$c = new Customer((int) $cookie->id_customer);
$ot=round($cart->getOrderTotal(),2);
$t=(int)sprintf('%f', $ot * 100);
if($_SERVER['REMOTE_ADDR'] == '78.226.56.137' || $_SERVER['REMOTE_ADDR'] == '86.199.86.234' || $_SERVER['REMOTE_ADDR'] == '88.163.22.223') {
$parm = 'merchant_id=075028916700025'./*082584341411111*/' merchant_country=fr customer_ip_address="'.Tools::getRemoteAddr().'" templatefile=bbb_tpl amount='.$t.' currency_code=978 transaction_id='.intval($params['cart']->id).' pathfile='.dirname(__FILE__).'/pathfile normal_return_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'order-confirmation.php?key='.$c->secure_key.'&id_cart='.$params['cart']->id.'&id_module='.intval($this->id).'" cancel_return_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'" automatic_response_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/atos_cyberplus/validation.php" customer_id='.intval($params['cart']->id_customer).' ';
} else {
$parm = 'merchant_id='.Configuration::get('ATOS_MERCHANT_ID').' merchant_country=fr customer_ip_address="'.Tools::getRemoteAddr().'" templatefile=bbb_tpl amount='.$t.' currency_code=978 transaction_id='.intval($params['cart']->id).' pathfile='.dirname(__FILE__).'/pathfile normal_return_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'order-confirmation.php?key='.$c->secure_key.'&id_cart='.$params['cart']->id.'&id_module='.intval($this->id).'" cancel_return_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'" automatic_response_url="http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'modules/atos_cyberplus/validation.php" customer_id='.intval($params['cart']->id_customer).' ';
}
$result = exec('/home/www/bebeboutik.com/cgi/www/request '.$parm);
$resultArray = explode('!', $result);
if (!isset($resultArray[3]))
return '<div class="payment_module">error in atos payment module : can\'t execute request</div>';
elseif ($resultArray[1] == -1)
return '<div class="payment_module">error in atos payment module : '.$resultArray[2].'</div>';
return '
<div class="payment_module" style="padding: 20px; color: #0099CC;"><p>'.$this->l('Pay with Atos Cyberplus').' '.$this->l('Choose you card type:').'</p>'.str_replace(array('<IMG BORDER=0 SRC="/modules/atos_cyberplus/logos/CLEF.gif">', '<DIV ALIGN=center>Vous utilisez le formulaire s&#233;curis&#233; standard SSL, choisissez une carte ci-dessous :<br><br></DIV>'), '', $resultArray[3]).'</div>';
}
}
?>