* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7233 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once 'fianetlib/includes/includes.inc.php'; class kwixo extends PaymentModule { private $_html = ''; private $_postErrors = array(); private $_postWarnings = array(); // category defined by Receive&Pay private $categories = array( 1 => 'Alimentation & gastronomie', 2 => 'Auto & moto', 3 => 'Culture & divertissements', 4 => 'Maison & jardin', 5 => 'Electroménager', 6 => 'Enchères et achats groupés', 7 => 'Fleurs & cadeaux', 8 => 'Informatique & logiciels', 9 => 'Santé & beauté', 10 => 'Services aux particuliers', 11 => 'Services aux professionnels', 12 => 'Sport', 13 => 'Vêtements & accessoires', 14 => 'Voyage & tourisme', 15 => 'Hifi, photo & vidéos', 16 => 'Téléphonie & communication', 17 => 'Bijoux et métaux précieux', 18 => 'Articles et accessoires pour bébé', 19 => 'Sonorisation & lumière' ); // return values defined by Receive&Pay private $tags = array( // Zone Paiement 0 => 'Commande avortée', 1 => 'OK Commande acceptée validée', 2 => 'KO Commande refusée (fraude)', 3 => 'SU Commande sous surveillance FIA-NET', // Zone Surveillance (si Tag vaut 3) 10 => 'Surveillance OK, la commande est "libérée"', 11 => 'Surveillance KO, la commande est annulée', // Zone Livraison 100 => 'OK Clôture de la transaction (livraison)', 101 => 'KO Annulation de la transaction' ); private $kw_os_statuses = array( 'KW_OS_WAITING' => 'Attente validation Kwixo', 'KW_OS_CREDIT' => "Crédit Kwixo à l'étude", 'KW_OS_CONTROL' => "Contrôle Kwixo en cours", ); private $kw_os_payment_statuses = array( 'KW_OS_PAYMENT_GREEN' => 'Paiement Kwixo accepté - score vert', 'KW_OS_PAYMENT_RED' => "Paiement Kwixo accepté - score rouge", ); private $_carrier_type = array( 1 => 'Retrait de la marchandise chez le marchand', 2 => 'Utilisation d\'un réseau de points-retrait tiers (type kiala, alveol, etc.)', 3 => 'Retrait dans un aéroport, une gare ou une agence de voyage', 4 => 'Transporteur (La Poste, Colissimo, UPS, DHL... ou tout transporteur privé)', 5 => 'Emission d’un billet électronique, téléchargements' ); public function __construct() { $this->name = 'kwixo'; $this->version = '4.1'; if (preg_match("/1\.4/", _PS_VERSION_)) $this->tab = 'payments_gateways'; else $this->tab = 'Payment'; $this->author = 'PrestaShop'; parent::__construct(); $this->displayName = $this->l('Kwixo'); $this->description = $this->l('Accepts payments by "Kwixo"'); if (intval(Configuration::get('RNP_MERCHID')) == 0 OR Configuration::get('RNP_CRYPTKEY') == NULL OR Configuration::get('RNP_DEFAULTCATEGORYID') == NULL) $this->warning = $this->l('MerchID, CryptKey and a Category must be configured in order to use this module correctly'); } public function install() { Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'kwixo_categories` ( `id_category` int(10) unsigned NOT NULL auto_increment, `type` int(10) NOT NULL, PRIMARY KEY (`id_category`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8'); Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'kwixo_carriers` ( `id_carrier` int(11) NOT NULL, `type` int(11) NOT NULL, PRIMARY KEY `id_carrier` (`id_carrier`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8'); if (!Configuration::get('RNP_NBDELIVERYDAYS')) Configuration::updateValue('RNP_NBDELIVERYDAYS', 7); if (!Configuration::get('RNP_TYPE_DISPLAY')) Configuration::updateValue('RNP_TYPE_DISPLAY', 1); //suppression et génération d'un fichier log vierge if (file_exists(KW_ROOT_DIR . '/logs/errorlog.xml')) { unlink(KW_ROOT_DIR . '/logs/errorlog.xml'); FiaKwixo::insertLog(__METHOD__ . ' : ' . __LINE__, 'Fichier de log généré.'); } //génération des statuts de paiement intermédiares foreach ($this->kw_os_statuses as $key => $value) { $kw_ow_status = Configuration::get($key); if ($kw_ow_status === false) { $orderState = new OrderState(); $orderState->id_order_state = pSQL($key); }else $orderState = new OrderState(intval($kw_ow_status)); $langs = Language::getLanguages(); foreach ($langs AS $lang) $orderState->name[$lang['id_lang']] = pSQL($value); $orderState->invoice = false; $orderState->send_email = false; $orderState->logable = false; $orderState->color = '#3333FF'; $orderState->save(); Configuration::updateValue($key, intval($orderState->id)); copy(dirname(__FILE__) . '/img/' . $key . '.gif', dirname(__FILE__) . '/../../img/os/' . (int) $orderState->id . '.gif'); } //génération des statuts de paiement validés foreach ($this->kw_os_payment_statuses as $key => $value) { $kw_ow_status = Configuration::get($key); if ($kw_ow_status === false) { $orderState = new OrderState(); $orderState->id_order_state = pSQL($key); }else $orderState = new OrderState(intval($kw_ow_status)); $langs = Language::getLanguages(); foreach ($langs AS $lang) $orderState->name[$lang['id_lang']] = pSQL($value); $orderState->invoice = true; $orderState->send_email = true; $orderState->logable = true; $orderState->color = '#DDEEFF'; $orderState->save(); Configuration::updateValue($key, intval($orderState->id)); copy(dirname(__FILE__) . '/img/' . $key . '.gif', dirname(__FILE__) . '/../../img/os/' . (int) $orderState->id . '.gif'); } if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn') OR !$this->registerHook('adminOrder') OR !$this->registerHook('rightColumn')) return false; return true; } public function uninstall() { Db::getInstance()->Execute('DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'kwixo_categories'); Db::getInstance()->Execute('DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'kwixo_carriers'); return parent::uninstall(); } private static function getCarrierType($id_carrier) { $carrier_type = $carrier[Db::getInstance()->GetValue('SELECT type FROM ' . _DB_PREFIX_ . 'kwixo_carriers WHERE id_carrier =' . (int) $id_carrier)]; return ($carrier_type ? $carrier_type : 4); } public function duplicateCart() { global $cart; if (method_exists('Cart', 'duplicate')) { $arr = $cart->duplicate(); return $arr['cart']->id; } else return self::_duplicateCart(intval($cart->id)); } private function _duplicateCart($id_cart) { $cart = new Cart(intval($id_cart)); if (!$cart->id OR $cart->id == 0) return false; $db = Db::getInstance(); $cart->id = 0; $cart->save(); if (!$cart->id OR $cart->id == 0 OR $cart->id == $id_cart) return false; /* Products */ $products = $db->ExecuteS(' SELECT id_product, id_product_attribute, quantity, date_add FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart=' . intval($id_cart)); $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'cart_product(id_cart, id_product, id_product_attribute, quantity, date_add) VALUES '; if ($products) { foreach ($products AS $product) $sql .= '(' . intval($cart->id) . ',' . intval($product['id_product']) . ', ' . intval($product['id_product_attribute']) . ', ' . intval($product['quantity']) . ', \'' . pSQL($product['date_add']) . '\'),'; $db->Execute(rtrim($sql, ',')); } /* Customization */ $customs = $db->ExecuteS(' SELECT c.id_customization, c.id_product_attribute, c.id_product, c.quantity, cd.type, cd.index, cd.value FROM ' . _DB_PREFIX_ . 'customization c JOIN ' . _DB_PREFIX_ . 'customized_data cd ON (cd.id_customization = c.id_customization) WHERE c.id_cart=' . intval($id_cart)); $custom_ids = array(); $sql_custom_data = 'INSERT INTO ' . _DB_PREFIX_ . 'customized_data (id_customization, type, index, value) VALUES '; if ($customs) { foreach ($customs AS $custom) { $db->Execute('INSERT INTO ' . _DB_PREFIX_ . 'customization (id_customization, id_cart, id_product_attribute, id_product, quantity) VALUES(\'\', ' . intval($cart->id) . ', ' . intval($custom['id_product_attribute']) . ', ' . intval($custom['id_product']) . ', ' . intval($custom['quantity']) . ')'); $custom_ids[$custom['id_customization']] = $db->Insert_ID(); } foreach ($customs AS $custom) $sql_custom_data .= '(' . intval($custom_ids[$custom['id_customization']]) . ', ' . intval($custom['type']) . ', ' . intval($custom['index']) . ', \'' . pSQL($custom['value']) . '\'),'; $db->Execute($sql_custom_data); } /* Discounts */ $discounts = $db->ExecuteS('SELECT id_discount FROM ' . _DB_PREFIX_ . 'cart_discount WHERE id_cart=' . intval($id_cart)); if ($discounts) { $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'cart_discount(id_cart, id_discount) VALUES '; foreach ($discounts AS $discount) $sql .= '(' . intval($cart->id) . ', ' . intval($discount['id_discount']) . '),'; $db->Execute(rtrim($sql, ',')); } return $cart->id; } public function getContent() { global $cookie; $this->_html = '

' . $this->l('Settings updated') . '