PHP Code:
<?
define('DIR_FS_ATOS', DIR_FS_CATALOG . 'atos/');
class atos {
// ----------------------------------------------------------------
// MEMBERS
// ----------------------------------------------------------------
// List of supported currencies by the ATOS system.
var $currencies = array(
'EUR' => '978',
'USD' => '840',
'CHF' => '756',
'GBP' => '826',
'CAD' => '124',
'JPY' => '392',
'MXP' => '484',
'TRL' => '792',
'AUD' => '036',
'NZD' => '554',
'NOK' => '578',
'BRC' => '986',
'ARP' => '032',
'KHR' => '116',
'TWD' => '901',
'SEK' => '752',
'DKK' => '208',
'KRW' => '410',
'SGD' => '702',
);
// List of supported languages by the ATOS system
var $languages = array(
'english' => 'en',
'german' => 'de',
'espanol' => 'es',
'french' => 'fr',
);
// ATOS Payment module code used by the OSC core
// to identified this module.
var $code = 'atos';
// Title : this title is displayed in the checkout_payment.php
// page.
var $title;
// Short description
var $description;
// Flag to know whether the module is installed and available
// as a selectable payment method or not
var $enabled;
// Any text to display when sending the confirmation mail order
// to the customer.
var $email_footer;
// Flag to know whether the module has to be used in its production
// or not. At this level, production means that any order using
// this payment method and has been confirmed by ATOS will be
// registered in the shop orders.
var $production;
// Operating System specific information (like name, command
// line parameter delimiter, path separator).
var $os_info;
// ----------------------------------------------------------------
// PUBLIC METHODS
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// atos()
//
// Initialize the ATOS payment module using the configuration
// variables.
function atos() {
global $order;
$this->description = MODULE_PAYMENT_ATOS_TEXT_DESCRIPTION;
$this->title = MODULE_PAYMENT_ATOS_TEXT_TITLE;
$this->email_footer = MODULE_PAYMENT_ATOS_TEXT_EMAIL_FOOTER;
$this->production = MODULE_PAYMENT_ATOS_PRODUCTION_MODE == 'production' ? true : false;
$this->sort_order = MODULE_PAYMENT_ATOS_SORT_ORDER;
$this->os_info = $this->_getOperatingSystemInfo();
$this->enabled = ((MODULE_PAYMENT_ATOS_STATUS == 'True') ? true : false);
if ((int)MODULE_PAYMENT_ATOS_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_ATOS_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
}
// ----------------------------------------------------------------
// update_status()
//
// Update whether the module is enabled or not. If the a specific
// zone has been configured, the module will be only available
// iff the billing address is in the zone.
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_ATOS_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_ATOS_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
// ----------------------------------------------------------------
// javascript_validation()
//
// Any javascript code to be used with this payment method.
// Required by the OSC core.
function javascript_validation() {
return false;
}
// ----------------------------------------------------------------
// selection()
//
// Information to display in the checkout_payment.php when this
// module is enabled.
// Required by the OSC core.
function selection() {
return array('id' => $this->code,
'module' => $this->title);
}
// ----------------------------------------------------------------
// pre_confirmation_check()
//
// Called in the checkout_confirmation.php page to do any
// processes at this level.
// Required by the OSC core.
// Permet de calculer form_action_url
// Cette valeur est assign閑 ?la variable $form_action_url dans le module header_php.php
// de la page checkout_confirmation_default
function pre_confirmation_check() {
global $order;
$currency = $_SESSION['currency'];
$sips = $this->makeRequest($order->info['total'], $currency);
if ($sips['error']) {
$this->error = 1;
$this->message = MODULE_PAYMENT_ATOS_CALL_REQUEST_ERROR . ': ' . $sips['command'] . '<br>' . $sips['error'];
} else {
$regs = array();
$this->error = 0;
$this->message = $sips['message'];
if (eregi('<form [^>]*action="([^"]*)"[^>]*>(.*)</form>', $sips['message'], $regs)) {
$this->message = $regs[2];
$this->form_action_url = $regs[1];
} else {
$this->error = 1;
$this->message = MODULE_PAYMENT_ATOS_CALL_REQUEST_ERROR;
}
}
return false;
}
// ----------------------------------------------------------------
// confirmation()
//
// Called in the checkout_confirmation.php page to validate the
// order payment : prepare the data to be sent to the ATOS
// server (encoding data).
// Required by the OSC core.
function confirmation() {
return false;
}
// ----------------------------------------------------------------
// process_button()
//
// Text to display in the checkout_confirmation.php page at the
// bottom of the order summary.
// It display the list of available payment methods (credit card
// type, ...).
// Required by the OSC core.
//
// Permet de pr閜arer le message ?envoyer au serveur mon閠ique avec le bon montant incluant les taxes
// et prenant en compte les bons de r閐uction.
// Permet aussi de pr閜arer le code HTML d'affichage des icones des moyens de paiement
function process_button() {
global $order;
$currency = $_SESSION['currency'];
$sips = $this->makeRequest($order->info['total'], $currency);
if (!$this->production) $this->sendNotification("ATOS Request Made", $sips);
if ($sips['error']) {
$this->error = 1;
$this->message = MODULE_PAYMENT_ATOS_CALL_REQUEST_ERROR . ': ' . $sips['command'] . '<br>' . $sips['error'];
} else {
$regs = array();
$this->error = 0;
$this->message = $sips['message'];
if (eregi('<form [^>]*action="([^"]*)"[^>]*>(.*)</form>', $sips['message'], $regs)) {
$this->message = $regs[2];
$this->form_action_url = $regs[1];
} else {
$this->error = 1;
$this->message = MODULE_PAYMENT_ATOS_CALL_REQUEST_ERROR;
}
}
if ($this->error) {
/* An internal error occurs: inform the customer and invite him to contact
our service and team */
$this->sendNotification('ATOS Request Error', $sips, "The following error occurs while encoding the request\n" . $sips['error']);
$this->form_action_url = zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'NONSSL', false);
return '<table border="0" width="100%" cellspacing="0" cellpadding="2"><tr><td class="highlight" align="center">'
. $this->message . '</td></tr></table><br>';
}
return $this->message;
}
// ----------------------------------------------------------------
// before_process()
//
// Call by the checkout_process.php before accepting the order.
// This method decodes incoming data and analyse result.
// Return true if the data can be decoded and the payment has
// been accepted by ATOS. Return false and send a notification
// to the notification email otherwise.
// Required by the OSC core.
function before_process() {
global $order, $_SERVER, $_POST;
// Verify remote ip
if (MODULE_PAYMENT_ATOS_IP) {
$deny_access = true;
foreach (preg_split('/[,\s]+/', MODULE_PAYMENT_ATOS_IP) as $authorized_ip) {
if ($_SERVER['REMOTE_ADDR'] == $authorized_ip) {
$deny_access = false;
break;
}
}
if ($deny_access) {
/* Ignore not allowed ip */
$this->sendNotification('ATOS AutoResponse Status', '',
$_SERVER['REMOTE_ADDR'] . " tries to connect to " . $GLOBALS['PHP_SELF']
. "\nAllowed ip is : " . MODULE_PAYMENT_ATOS_IP);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
/* check response data and code and update session information */
$response = $this->decodeResponse($_POST['DATA']);
if ($response['code'] != 0) {
/* An internal error occurs: inform the customer and invite him to contact
our service and team */
// FIXME
$this->sendNotification('ATOS AutoResponse Error', $response);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
if ($response['merchant_id'] != MODULE_PAYMENT_ATOS_ID) {
$this->sendNotification('ATOS AutoResponse Error',
$response,
"merchant_id differ:\nMerchant id expected = " . MODULE_PAYMENT_ATOS_ID);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
// Check whether response code is ok
if ($response['response_code'] != '00') {
if ($response['response_code'] != '17') {
// Send a notification if the customer has not cancelled its transaction
$this->sendNotification('ATOS Notification - Response Code ' . $response['response_code'],
$response,
MODULE_PAYMENT_ATOS_NOT_APPROVED_TEXT1
. $response['response_code']. ' ('
. atos_getMessageResponseCode($response['response_code'])
. ').'
. "\n" . MODULE_PAYMENT_ATOS_NOT_APPROVED_TEXT2 );
}
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
// Check whether the production mode is on or off
if (!$this->production) {
$this->sendNotification('ATOS checkout_process', $response, 'demo mode');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT,
'info_message=' . urlencode(MODULE_PAYMENT_ATOS_TEXT_CHECKOUT_DEMO), 'SSL', false));
}
// Update credit card info and transaction id
$order->info['transaction_id'] = $response['transaction_id'];
//$constant = 'MODULE_PAYMENT_ATOS_PAYMENT_MEANS_' . $response['payment_means'];
//define($constant, $response['payment_means']);
//$order->info['cc_type'] = constant($constant);
$order->info['cc_type'] = $response['payment_means'];
$cc = split('\.', $response['card_number']);
$order->info['cc_number'] = $cc[0] . ' #### #### ##' . $cc[1];
return false;
}
function after_order_create($zf_order_id) {
global $db, $order;
// Mise ?jour du statut de la commande
//if (MODULE_PAYMENT_CC_COLLECT_CVV == 'True') {
//$db->execute("update " . TABLE_ORDERS . " set cc_cvv ='" . $order->info['cc_cvv'] . "' where orders_id = '" . $zf_order_id ."'");
//}
}
// ----------------------------------------------------------------
// after_process()
//
// Called in checkout_process.php to make any processes after
// the order has been registered in the shop database.
// Required by the OSC core.
function after_process() {
return false;
}
// ----------------------------------------------------------------
// check()
//
// Check whether the ATOS module is installed or not.
// Required by the OSC core.
function check() {
// V閞ifier si le module est install?
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_ATOS_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
// ----------------------------------------------------------------
// install()
//
// Install the module by registered ATOS configuration variables
// into the database.
// Required by the OSC core.
function install() {
global $db;
$install_atos_email = STORE_OWNER_EMAIL_ADDRESS;
$certificate = atos::FindACertificate();
$install_merchant_id = $certificate['id'];
$install_parmcom_file = $certificate['parmcom'];
if (!$install_parmcom_file || !file_exists($this->_getExternalFileName($install_parmcom_file))) {
$install_parmcom_file = atos::FindAParmcomFile();
}
$atos_bin_request = str_replace('\\', '/', $this->_getExternalFileName("request" . $this->os_info['bin_suffix']));
$atos_bin_response = str_replace('\\', '/', $this->_getExternalFileName("response" . $this->os_info['bin_suffix']));
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('ACCEPTER le PAIEMENT ATOS-SIPS:', 'MODULE_PAYMENT_ATOS_STATUS', 'True', 'Voulez vous accepter les paiements ATOS?', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Identifiant de Commer鏰nt:', 'MODULE_PAYMENT_ATOS_ID', '" . zen_db_input($install_merchant_id) . "', 'Votre ID marchand provenant d\'ATOS. A demander a votre banque. Pour plus d\'information http://www.sips-atos.com.', '6', '2', 'atos::ConfigPullDownCertificates(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Nom du fichier de param鑤res g閚閞als:', 'MODULE_PAYMENT_ATOS_PARMCOM_FILE', '" . zen_db_input($install_parmcom_file) . "', 'Choisissez le nom du fichier pour les param鑤res g閚閞ales.', '6', '4','atos::ConfigPullDownParmcomFiles(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('<u>IMPORTANT</u> L\'IP autoris??donner la confirmation d\'achat. Laissez vide pour ne pas faire de v閞ification sur l\'IP (d閒aut). Vous pouvez entrer plusieurs IPs en les s閜arant par des virgules ou des espaces. Les IPs connus pour les serveurs de paiement ATOS sont: 193.56.46.96,193.56.46.97 et 193.56.46.18', 'MODULE_PAYMENT_ATOS_IP', '193.56.46.96,193.56.46.97,193.56.46.18', 'Entrer le No IP du serveur h閎ergeant le CGI qui fera l\'appel ?votre serveur pour confirmer/infirmer l\'achat. Seul ce serveur est autoris??contacter votre serveur une fois la transaction effectu閑 ou annul閑', '6', '4', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Nom de l\'application pour construire la requ阾e', 'MODULE_PAYMENT_ATOS_BIN_REQUEST', '" . zen_db_input($atos_bin_request) . "', 'Chemin complet de l\'executable permettant de formatter la requ阾e.', '6', '5', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Nom de l\'application pour lire la r閜onse', 'MODULE_PAYMENT_ATOS_BIN_RESPONSE', '" . zen_db_input($atos_bin_response) . "', 'Chemin complet de l\'executable pour d閏oder la r閜onse envoy閑 sur le script de r閜onse normale ou sur le script d\'auto-r閜onse', '6', '6', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Nom du fichier pathfile', 'MODULE_PAYMENT_ATOS_PATHFILE', '', 'Pour laissez le module g閞er lui-m阭e le fichier pathfile, laissez ce champ vide (recommand?dans la majorit?des utilisations). Si vous voulez utiliser un fichier sp閏ifique, alors saisissez le chemin complet pour ce fichier.', '6', '6', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Mise en production du module de paiement', 'MODULE_PAYMENT_ATOS_PRODUCTION_MODE', 'production', 'Si la valeur de ce champ vaut <tt>demo</tt>, les commandes client ne seront pas enregistr閑s dans la base de donn閑s. Conserver cette valeur uniquement pour un mode d閙onstration. Pour la mise en production, mettez ce champ ?<tt>production</tt>', '6', '7', 'zen_cfg_select_option(array(\'demo\', \'production\'),', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Adresse e-mail o?envoyer les notifications (erreurs)', 'MODULE_PAYMENT_ATOS_EMAIL_FOR_NOTIFICATION', '" . zen_db_input($install_atos_email) . "', 'Renseigner ce champ pour recevoir par email les erreurs survenues lors du traitement des transactions ATOS/SIPS', '6', '8', now())");
$db->Execute("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_ATOS_SORT_ORDER', '0', 'Ordre de tri pour l\'affichage (trier par nombres croissants).', '6', '9', now())");
$db->Execute("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_ATOS_ZONE', '0', 'Si une zone est s閘ectionn閑, ce mode de paiement ne sera disponible uniquement pour cette zone.', '6', '10', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('蓆at initial de la commande', 'MODULE_PAYMENT_ATOS_ORDER_STATUS_ID', '0', 'Positionnez l\'閠at initial de la commande, lorsque le client utilise ce mode de paiement', '6', '11', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
}
?>
Bookmarks