<?php
/*
$Id: paysitecash.php $
osCommerce, Open Source E-Commerce Solutions
OSC 2.2 MS1 or later.
This module may also be compatible with OSC snapshots
released Dec. 1 2002.
This module has been adapted by Adrian Antohi
<
[email protected]> to fit in the OSC 2.2 MS1.
Released under the GNU General Public License
*/
define('TABLE_PAYSITECASH_PAYMENT_CONFIRMATION', 'paysitecash_payment_confirmation');
class paysitecash {
var $code, $title, $description, $enabled;
// class constructor
function paysitecash() {
global $order;
$this->code = 'paysitecash';
$this->title = MODULE_PAYMENT_PAYSITECASH_TEXT_TITLE;
$this->description = MODULE_PAYMENT_PAYSITECASH_TEXT_DESCRIPTION;
$this->enabled = MODULE_PAYMENT_PAYSITECASH_STATUS;
$this->sort_order = MODULE_PAYMENT_PAYSITECASH_SORT_ORDER;
if ((int)MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_ID;
}
if (is_object($order))
$this->update_status();
}
// class methods
// class methods
function update_status() {
global $order;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYSITECASH_ZONE > 0) ) {
$check_flag = false;
$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYSITECASH_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while ($check = tep_db_fetch_array($check_query)) {
if ($check['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
function javascript_validation() {
return false;
}
function selection() {
return array('id' => $this->code,
'module' => $this->title);
}
function pre_confirmation_check() {
return false;
}
function confirmation() {
if(MODULE_PAYMENT_PAYSITECASH_WEBSITE == 'Paysite-Cash')
$this->form_action_url = 'https://billing.paysite-cash.biz/';
elseif(MODULE_PAYMENT_PAYSITECASH_WEBSITE == 'Easy-Pay')
$this->form_action_url = 'https://secure.easy-pay.net/';
return array('title' => MODULE_PAYMENT_PAYSITECASH_INFO_TEXT_DESCRIPTION);
}
// modifier ce paragraphe pour l'envoi des donnees à PAYSITECASH
function process_button() {
global $order, $currency, $languages_id, $customer_id;
// Fetch the customer email address from the db
$query = tep_db_query('SELECT customers_email_address FROM ' . TABLE_CUSTOMERS . ' WHERE customers_id = "' . $customer_id . '"');
$customer_info = tep_db_fetch_array($query);
// Fetch the language code from the db
$query = tep_db_query('SELECT code FROM ' . TABLE_LANGUAGES . ' WHERE languages_id = "' . $languages_id . '"');
$language_info = tep_db_fetch_array($query);
if(MODULE_PAYMENT_PAYSITECASH_MODE_TEST =="True")
$test_mode = 1;
if($test_mode == 1)
$add_tets_mode = tep_draw_hidden_field('test', $test_mode);
else
$add_tets_mode = "";
// $divers = base64_encode(tep_href_link(FILENAME_CHECKOUT_PROCESS,tep_session_name() . '=' . tep_session_id(), 'SSL'));
$divers = base64_encode(tep_href_link(FILENAME_ACCOUNT,tep_session_name() . '=' . tep_session_id(), 'SSL'));
if(MODULE_PAYMENT_PAYSITECASH_MANUELLE_CONFIRMATION == "True")
$manuelle_confirmation = tep_draw_hidden_field('wait', 1);
if(MODULE_PAYMENT_PAYSITECASH_DEBUG_MODE == "True")
$add_debug_mode = tep_draw_hidden_field('debug', 1);
return tep_draw_hidden_field('site', MODULE_PAYMENT_PAYSITECASH_SHOP_ID) .
tep_draw_hidden_field('montant', $order->info['total']) . // FIXME!!! total order is in the DEFAULT CURRENCY
tep_draw_hidden_field('devise', DEFAULT_CURRENCY) .
$add_tets_mode .
tep_draw_hidden_field('id_client', $customer_id) .
tep_draw_hidden_field('lang', $language_info['code']) .
tep_draw_hidden_field('divers',$divers) .
$manuelle_confirmation.
$add_debug_mode.
tep_draw_hidden_field('email', $customer_info['customers_email_address']);
}
function before_process() {
global $order, $currency, $customer_id;
global $HTTP_GET_VARS;
$order->info['payment_transaction_id'] = $HTTP_GET_VARS['id_trans'];
return false;
}
function after_process() {
paysitecash::OnPaysitecashConfirmation();
return false;
}
function output_error() {
return false;
}
function check() {
if (!isset($this->check)) {
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYSITECASH_STATUS'");
$this->check = tep_db_num_rows($check_query);
}
return $this->check;
}
// Modifiez ces lignes pour l'administration du site et les paramètres du paiement Blue Paid
function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Module PaysiteCash', 'MODULE_PAYMENT_PAYSITECASH_STATUS', 'True', 'Proposer le paiement par PaysiteCash', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Use Website : ', 'MODULE_PAYMENT_PAYSITECASH_WEBSITE', 'Paysite-Cash', 'Use Website : ', '6', '2', 'tep_cfg_select_option(array(\'Paysite-Cash\', \'Easy-Pay\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Test Mode', 'MODULE_PAYMENT_PAYSITECASH_MODE_TEST', 'True', 'PaysiteCash module en Test Mode', '6', '3', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Confirmation manuelle des transactions', 'MODULE_PAYMENT_PAYSITECASH_MANUELLE_CONFIRMATION', 'False', '', '6', '4', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Payment debug mode', 'MODULE_PAYMENT_PAYSITECASH_DEBUG_MODE', 'False', '', '6', '5', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Payment confirmation debug mode', 'MODULE_PAYMENT_PAYSITECASH_DEBUG_TRANS', 'False', 'If true you`ll find with ftp in root dir debug.txt file', '6', '6', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('ID compte', 'MODULE_PAYMENT_PAYSITECASH_SHOP_ID', '0', 'Votre compte PaysiteCash', '6', '7', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Ordre de tri', 'MODULE_PAYMENT_PAYSITECASH_SORT_ORDER', '1', 'Ordre de tri pour l\'affichage (trier par nombres croissants).', '6', '8', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Zone de Paiement', 'MODULE_PAYMENT_PAYSITECASH_ZONE', '0', 'Si une zone est sélectionnée, ce mode de paiement ne sera disponible QUE pour cette zone.', '6', '9', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Etat initial de la commande', 'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_ID', '0', 'Positionnez l\'état initial de la commande, lorsque le client utilise ce mode de paiement', '6', '10', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Utilisez la confirmation automatique ', 'MODULE_PAYMENT_PAYSITECASH_USE_AUTO_CONFIRMATION', 'Enable', 'Utiliser la confirmation automatique de paysitecash. Si ce champ est \'Enable\', les champs dessous ne seront pas pris en compte', '6', '11', 'tep_cfg_select_option(array(\'Enable\', \'Disable\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('<u>IMPORTANT</u> IP autorisée à confirmer l\'achat:', 'MODULE_PAYMENT_PAYSITECASH_IP', '', 'Entrez l\'IP ( 70.87.106.58/67.18.9.98 ) qui fera appel à votre serveur pour confirmer ou infirmer l\'achat. Seulle cette IP sera autorisée. Si ce champ est vide, il n\'y aura pas de vérification de l\'IP de l\'appelant.', '6', '12', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Etat de la commande après accord par paysitecash', 'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_OK_ID', '0', 'Positionnez l\'état de la commande, lorsque la commande a été confirmée par paysitecash. <i>Utilisez lorsque la confirmation par paysitecash est activée</i>', '6', '13', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Etat de la commande après rejet par paysitecash', 'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_KO_ID', '0', 'Positionnez l\'état de la commande, lorsque la commande a été rejetée par paysitecash. <i>Utilisez lorsque la confirmation par paysitecash est activé</i>', '6', '14', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array(
'MODULE_PAYMENT_PAYSITECASH_STATUS',
'MODULE_PAYMENT_PAYSITECASH_WEBSITE',
'MODULE_PAYMENT_PAYSITECASH_MODE_TEST',
'MODULE_PAYMENT_PAYSITECASH_MANUELLE_CONFIRMATION',
'MODULE_PAYMENT_PAYSITECASH_DEBUG_MODE',
'MODULE_PAYMENT_PAYSITECASH_DEBUG_TRANS',
'MODULE_PAYMENT_PAYSITECASH_SHOP_ID',
'MODULE_PAYMENT_PAYSITECASH_SORT_ORDER',
'MODULE_PAYMENT_PAYSITECASH_ZONE',
'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_ID',
'MODULE_PAYMENT_PAYSITECASH_USE_AUTO_CONFIRMATION',
'MODULE_PAYMENT_PAYSITECASH_IP',
'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_OK_ID',
'MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_KO_ID',
);
}
function LogErrors($msg)
{
$file = "debug.txt";
$time=time();
$day=date("d",$time);
$month=date("m",$time);
$year=date("Y",$time);
$hour=date("H",$time);
$min=date("i",$time);
$sec=date("s",$time);
if(file_exists($file))
{
$mode="a+";
}
else
{
$mode="w+";
}
if($fd=@fopen($file,$mode))
{
@fwrite($fd,$day."/".$month."/".$year." ".$hour.":".$min.":".$sec." -> ".$msg."\n");
@fclose($fd);
}
}
function OnPaysitecashConfirmation() {
// Paysitecash confirmation support disable
if (MODULE_PAYMENT_PAYSITECASH_USE_AUTO_CONFIRMATION == 'Disable')
{
if(MODULE_PAYMENT_PAYSITECASH_DEBUG_TRANS == True)
paysitecash::LogErrors("payment confirmation support is dissabed");
return;
}
// Get all transactions that are in the paysitecash_autoconf table and update orders_id
// accordingly
tep_db_query('LOCK TABLE ' . TABLE_PAYSITECASH_PAYMENT_CONFIRMATION . ' write, ' . TABLE_ORDERS . ' write, ' . TABLE_ORDERS_STATUS_HISTORY . ' write');
$query = tep_db_query('SELECT id, id_trans, id_client, etat, mode FROM ' . TABLE_PAYSITECASH_PAYMENT_CONFIRMATION);
while ($payment_status = tep_db_fetch_array($query)) {
$order_query = tep_db_query('SELECT orders_id FROM ' . TABLE_ORDERS . ' WHERE payment_transaction_id = \'' . $payment_status['id_trans'] . '\' AND customers_id = ' . (int)($payment_status['id_client']) . ' ORDER BY orders_id DESC LIMIT 1');
$order_id = tep_db_fetch_array($order_query);
$order_id = (int)($order_id['orders_id']);
if ($order_id == 0)
continue;
// Found the order to update
// Count the number of status that already exists for this order
$order_status_count_query = tep_db_query('SELECT count(*) as total FROM ' . TABLE_ORDERS_STATUS_HISTORY . ' WHERE orders_id = ' . $order_id);
$order_status_count = tep_db_fetch_array($order_status_count_query);
$order_status_count = $order_status_count['total'];
$debug_msg = "Order id : ".$order_id;
if ($order_status_count == 1) {
// Only one => add a new status to the table
$new_order_status = 0;
$comment = null;
switch ($payment_status['etat']) {
case 'ok':
$new_order_status = (int)MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_OK_ID;
$comment = MODULE_PAYMENT_PAYSITECASH_PAYMENT_ACCEPTED;
break;
case 'ko':
$new_order_status = (int)MODULE_PAYMENT_PAYSITECASH_ORDER_STATUS_KO_ID;
$comment = MODULE_PAYMENT_PAYSITECASH_PAYMENT_REJECTED;
break;
}
$debug_msg .= ", New order status : ".$new_order_status;
if ($new_order_status) {
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY,
array('orders_id' => $order_id,
'orders_status_id' => $new_order_status,
'date_added' => 'now()',
'customer_notified' => 0,
'comments' => $comment . ($payment_status['mode'] ? ' (' . $payment_status['mode'] . ')' : '')));
tep_db_perform(TABLE_ORDERS,
array('orders_status' => $new_order_status),
'update',
'orders_id = ' . $order_id);
}
}
if(MODULE_PAYMENT_PAYSITECASH_DEBUG_TRANS == True)
paysitecash::LogErrors($debug_msg);
// Now remove this confirmation from the paysitecash_autoconf table
tep_db_query('DELETE FROM ' . TABLE_PAYSITECASH_PAYMENT_CONFIRMATION . ' WHERE id = ' . (int)($payment_status['id']));
}
tep_db_query('UNLOCK TABLES');
}
function AddPaysitecashConfirmation($id_trans, $id_client, $etat, $mode) {
// Paysitecash confirmation support disable
if (MODULE_PAYMENT_PAYSITECASH_USE_AUTO_CONFIRMATION == 'Disable')
return;
tep_db_query('LOCK TABLE ' . TABLE_PAYSITECASH_PAYMENT_CONFIRMATION . ' write');
tep_db_perform(TABLE_PAYSITECASH_PAYMENT_CONFIRMATION,
array('id_trans' => $id_trans,
'id_client' => $id_client,
'etat' => $etat,
'mode' => $mode,
'date_added' => 'now()'));
tep_db_query('UNLOCK TABLES');
}
}
?>
Bookmarks