* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7541 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class Secuvad_flux
{
public $encoding = 'utf-8';
public $flux_xml;
public $id_order;
public $imp_time;
public $idsecuvad;
function __construct($idsecuvad, $encoding)
{
$this->idsecuvad = $idsecuvad;
$this->encoding = $encoding;
}
public function get_flux_xml_fraud($id_order)
{
$this->id_order = (int)($id_order);
$this->imp_time = date("Y-m-d H:i:s");
$this->flux_xml = 'encoding.'" ?>' . "\n";
$this->flux_xml .= ''.$this->idsecuvad.''.(int)($this->id_order).''.$this->imp_time.'';
return ($this->flux_xml);
}
function get_flux_xml($id_order)
{
$this->id_order = (int)($id_order);
$this->flux_xml = '';
$this->flux_xml .= 'encoding.'" ?>' . "\n";
$this->flux_xml .= '' . "\n";
$this->flux_xml .= $this->get_flux_xml_order();
$this->flux_xml .= '' . "\n";
return $this->flux_xml;
}
private function get_flux_xml_order()
{
global $cookie;
$order = new Order((int)($this->id_order));
$address_delivery = new Address((int)($order->id_address_delivery));
$address_invoice = new Address((int)($order->id_address_invoice));
$customer = new Customer((int)($order->id_customer));
$currency = new Currency((int)($order->id_currency));
$carrier = new Carrier((int)($order->id_carrier));
$ip = Db::getInstance()->getValue('
SELECT `ip`
FROM `'._DB_PREFIX_.'secuvad_order`
WHERE `id_secuvad_order` = '.(int)($this->id_order));
if (!$ip)
return false;
$payment_cc = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'payment_cc`
WHERE `id_order` = '.(int)($this->id_order));
if ($payment_cc)
{
$card_number = $payment_cc['card_number'];
$card_expiration = $payment_cc['card_expiration'];
}
$carrier = Db::getInstance()->getRow('
SELECT at.`transport_id`, td.`transport_delay_name`
FROM `'._DB_PREFIX_.'secuvad_assoc_transport` at
JOIN `'._DB_PREFIX_.'secuvad_transport_delay` td ON (at.`transport_delay_id` = td.`transport_delay_id`)
JOIN `'._DB_PREFIX_.'lang` l ON (l.`id_lang` = td.`id_lang`)
WHERE l.`id_lang` = '.((isset($cookie->id_lang) AND (int)($cookie->id_lang)) ? (int)($cookie->id_lang) : (int)(Configuration::get('PS_LANG_DEFAULT'))).'
AND at.`id_carrier` = '.(int)($order->id_carrier));
$transptype = $carrier['transport_id'];
$rapidite = $carrier['transport_delay_name'];
$code_payment = Db::getInstance()->getValue('
SELECT sap.`code`
FROM `'._DB_PREFIX_.'module` m
JOIN `'._DB_PREFIX_.'secuvad_assoc_payment` sap ON (m.`id_module` = sap.`id_module`)
WHERE m.`name` = \''.pSQL($order->module).'\'');
$flux_xml = "\n";
switch ($customer->id_gender)
{
case 1:
$gender = 'M';
break;
case 2:
$gender = 'Mme';
break;
case 3:
$gender = 'Mlle';
break;
default:
$gender = 'M';
break;
}
if ($address_invoice->company == '')
$flux_xml .= ''."\n";
else
$flux_xml .= ''."\n";
$flux_xml .= ''.$address_invoice->lastname.''."\n";
$flux_xml .= ''.$address_invoice->firstname.''."\n";
if ($address_invoice->company != '')
$flux_xml .= ''.$address_invoice->company.''."\n";
$flux_xml .= ''.$address_invoice->phone.''."\n";
$flux_xml .= ''.$address_invoice->phone_mobile.''."\n";
$flux_xml .= ''.$customer->email.''."\n";
$flux_xml .= '';
$flux_xml .= ''."\n";
$flux_xml .= ''.$address_invoice->address1.''."\n";
$flux_xml .= ''.$address_invoice->address2.''."\n";
$flux_xml .= ''.$address_invoice->postcode.''."\n";
$flux_xml .= ''.$address_invoice->city.''."\n";
$flux_xml .= ''.$address_invoice->country.''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''.$address_delivery->address1.''."\n";
$flux_xml .= ''.$address_delivery->address2.''."\n";
$flux_xml .= ''.$address_delivery->postcode.''."\n";
$flux_xml .= ''.$address_delivery->city.''."\n";
$flux_xml .= ''.$address_delivery->country.''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''.$this->idsecuvad.''."\n";
$flux_xml .= ''.(int)($this->id_order).''."\n";
$flux_xml .= ''.$order->date_add.''."\n";
$flux_xml .= ''.$order->total_paid_real.''."\n";
$flux_xml .= ''.$order->total_shipping.''."\n";
$flux_xml .= ''.$ip.''."\n";
$flux_xml .= ''."\n";
$flux_xml .= $this->get_flux_xml_products();
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
if ($code_payment == 'cheque')
$flux_xml .= ''."\n";
elseif ($code_payment == 'virement')
$flux_xml .= ''."\n";
elseif ($code_payment == 'paypal')
$flux_xml .= ''."\n";
elseif ($code_payment == 'cb en n fois')
$flux_xml .= ''."\n";
elseif ($code_payment == 'contre-remboursement')
$flux_xml .= ''."\n";
elseif ($code_payment == "carte")
{
if (!empty($card_number))
{
$cc_array = preg_split('/([X0-9]{4})/Ui', strtoupper($card_number), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
if (sizeof($cc_array))
{
$bin_array = array();
foreach ($cc_array as $element)
$bin_array[] = str_replace('X', '', $element);
$card_number = str_replace('X', '', $card_number); // 16 char
$bin = $bin_array[0].'-'.$bin_array[1]; // 6 char
$bin4 = $bin_array[0]; // 4 char
$bin42 = $bin_array[0].'-'.$bin_array[3]; // 6 char
if (strlen($bin42) != 7 AND strlen($bin4) != 4 AND strlen($bin) != 7 AND strlen($card_number) != 16)
return false;
$flux_xml .= ''."\n";
}
else
return false;
}
else
return false;
}
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
$flux_xml .= ''."\n";
return $flux_xml;
}
private function get_flux_xml_products()
{
global $cookie;
$flux_xml = '';
$order = new Order((int)($this->id_order));
$products = $order->getProducts();
foreach($products as $product)
{
$data = Db::getInstance()->getRow('
SELECT sac.`category_id`, pl.`name`
FROM `'._DB_PREFIX_.'secuvad_assoc_category` sac
JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = sac.`id_category`)
JOIN `'._DB_PREFIX_.'category` c ON (c.`id_category` = cp.`id_category`)
JOIN `'._DB_PREFIX_.'product_lang` pl ON (cp.`id_product` = pl.`id_product`)
JOIN `'._DB_PREFIX_.'lang` l ON (l.`id_lang` = pl.`id_lang` AND l.`id_lang` = '.((isset($cookie->id_lang) AND (int)($cookie->id_lang)) ? (int)($cookie->id_lang) : (int)(Configuration::get('PS_LANG_DEFAULT'))).')
WHERE pl.`id_product` = '.(int)($product['product_id']).'
ORDER BY c.`level_depth` DESC
',true);
$flux_xml .= ''."\n";
}
$flux_xml = ''."\n".$flux_xml.''."\n";
return $flux_xml;
}
}