PHP Code:
<?php
//
// +----------------------------------------------------------------------+
// | Moneybookers Payment Gateway for Zen Cart Open Source E-commerce |
// | By Dayo Akanji |
// | [url]www.dakanji.com[/url] |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license |
// | as bundled with this package. |
// | You can view a copy of the license in the |
// | '/includes/payments/moneybookers_gateway' folder of this package |
// +----------------------------------------------------------------------+
// $Id: moneybookers_gateway_ipn_handler.php, v1.1.0 2008/03/20 00:00:00Z dayo Exp $
//
//
// set admin flag
define('IS_ADMIN_FLAG', false);
// prime email vars
$order_status = '';
$order_status_detail = '';
$comments = '';
$notify_comments = '';
$message = '';
$html_msg = array();
$customer_notified = '0';
// load server parameters
require('includes/configure.php');
// load functions
require(DIR_WS_FUNCTIONS . 'functions_general.php');
require(DIR_WS_FUNCTIONS . 'html_output.php');
require(DIR_WS_FUNCTIONS . 'functions_email.php');
include(DIR_WS_MODULES . 'extra_functions.php');
// load classes
require(DIR_WS_CLASSES . 'class.base.php');
require(DIR_WS_CLASSES . 'class.phpmailer.php');
require(DIR_WS_CLASSES . 'class.smtp.php');
require(DIR_WS_CLASSES . 'class.notifier.php');
$zco_notifier = new notifier();
// load database table names
require(DIR_WS_INCLUDES . 'database_tables.php');
// connect to database
require('includes/classes/db/' . DB_TYPE . '/query_factory.php');
$db = new queryFactory();
if ( !$db->connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE, USE_PCONNECT, false) ) {
$db_connection = 'False';
} else {
$db_connection = 'True';
}
// load configuration constants
$configuration = $db->Execute('SELECT configuration_key AS cfgkey, configuration_value AS cfgvalue FROM ' . TABLE_CONFIGURATION);
while (!$configuration->EOF) {
define($configuration->fields['cfgkey'], $configuration->fields['cfgvalue']);
$configuration->MoveNext();
}
// set the request type
$request_type = (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == '1' || strstr(strtoupper($_SERVER['HTTP_X_FORWARDED_BY']),'SSL') || strstr(strtoupper($_SERVER['HTTP_X_FORWARDED_HOST']),'SSL')) ? 'SSL' : 'NONSSL';
// set php_self in the local scope
$PHP_SELF = $_SERVER['PHP_SELF'];
// load file names
require(DIR_WS_INCLUDES . 'filenames.php');
// load moneybookers module
require(DIR_WS_MODULES . 'payment/moneybookers_gateway.php');
$moneybookers_gateway = new moneybookers_gateway;
// set top level domains
$http_domain = zen_get_top_level_domain(HTTP_SERVER);
$https_domain = zen_get_top_level_domain(HTTPS_SERVER);
$current_domain = (($request_type == 'NONSSL') ? $http_domain : $https_domain);
if (SESSION_USE_FQDN == 'False') {
$current_domain = '.' . $current_domain;
}
// start session and set session parameters
require(DIR_WS_FUNCTIONS . 'sessions.php');
zen_session_name('zenid');
zen_session_save_path(SESSION_WRITE_DIRECTORY);
zen_session_start();
// set language
require(DIR_WS_CLASSES . 'language.php');
$lng = new language();
$lng->set_language(DEFAULT_LANGUAGE);
$_SESSION['language'] = $lng->language['directory'];
$_SESSION['languages_id'] = $lng->language['id'];
// load template directory
$sql = "select template_dir from " . TABLE_TEMPLATE_SELECT . " where template_id = '1'";
$template_query = $db->Execute($sql);
$template_dir = $template_query->fields['template_dir'];
// include email extras
if (file_exists(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir . '/' . FILENAME_EMAIL_EXTRAS)) {
$template_dir_select = $template_dir . '/';
} else {
$template_dir_select = '';
}
require_once(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir_select . FILENAME_EMAIL_EXTRAS);
// include the extra language translations
include(DIR_WS_MODULES . 'extra_definitions.php');
// set posted transaction id to variable
if (isset($_POST['transaction_id'])) {
$transaction_id = $_POST['transaction_id'];
}
// begin processing
if ($db_connection == 'True' && isset($transaction_id)) { // proceed if database connection made and transaction id is present.
// load hack to prevent multiple updates
require(DIR_WS_MODULES . 'payment/moneybookers_gateway/moneybookers_gateway_multiple_post_handler.php');
if ($transaction_found == 'True') {
// load order class
require(DIR_WS_CLASSES . 'order.php');
$order = new order($order_id);
$fp = fopen("moneybookers.txt","a");
fwrite($fp, "-----------------------------------------------\n");
fwrite($fp, "Order:" . $order_id . "\n");
fwrite($fp, "-----------------------------------------------\n");
fclose($fp);
if (is_object($order)) {
$md5_string = $_POST['merchant_id'] . $transaction_id . strtoupper(md5(MODULE_PAYMENT_MBOOKERS_GWAY_SECRET_WORD)) . $_POST['mb_amount'] . $_POST['mb_currency'] . $_POST['status'];
$result_of_md5 = strtoupper(md5($md5_string));
$md5_check_flag = 'Fail';
if (MODULE_PAYMENT_MBOOKERS_GWAY_MD5_CHECK == 'NO') {
$md5_check_flag = 'Pass';
$fp = fopen("moneybookers.txt","a");
fwrite($fp, "-----------------------------------------------\n");
fwrite($fp, $md5_check_flag . "\n");
fwrite($fp, "-----------------------------------------------\n");
fclose($fp);
} else {
if ($result_of_md5 == $_POST['md5sig']) {
$md5_check_flag = 'Pass';
}
}
// load order details
$order_details = $db->Execute("SELECT customers_name, customers_email_address, date_purchased FROM " . TABLE_ORDERS . " WHERE orders_id = '" . $order_id . "'");
// load email constants
require(DIR_WS_MODULES . 'payment/moneybookers_gateway/moneybookers_gateway_emails.php');
// prep emails
if ($md5_check_flag == 'Pass') {
$fp = fopen("moneybookers.txt","a");
foreach ($_POST as $key => $value) {
fwrite($fp, $key . '=>' . $value . "\n");
}
fwrite($fp, "-----------------------------------------------\n");
fclose($fp);
// set order status & comments
switch($_POST['status']) {
case '2': //processed
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_PROCESSED_KEY;
$order_status_detail = MBOOKERS_PROCESSED_VALUE;
$comments = MBOOKERS_EMAIL_PROCESSED;
break;
case '1': //scheduled
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_SCHEDULED_KEY;
$order_status_detail = MBOOKERS_SCHEDULED_VALUE;
$comments = MBOOKERS_EMAIL_SCHEDULED;
break;
case '0': //pending
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_PENDING_KEY;
$order_status_detail = MBOOKERS_PENDING_VALUE;
$comments = MBOOKERS_EMAIL_PENDING;
break;
case '-1': //cancelled
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_CANCELLED_KEY;
$order_status_detail = MBOOKERS_CANCELLED_VALUE;
$comments = MBOOKERS_EMAIL_CANCELLED;
break;
case '-2': //Declined
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_DECLINED_KEY;
$order_status_detail = MBOOKERS_DECLINED_VALUE;
$comments = MBOOKERS_EMAIL_DECLINED;
break;
case '-3': //chargeback
$order_status = MODULE_PAYMENT_MBOOKERS_GWAY_CHARGEDBACK_KEY;
$order_status_detail = MBOOKERS_CHARGEDBACK_VALUE;
$comments = MBOOKERS_EMAIL_CHARGEDBACK;
break;
default: //default
$order_status = DEFAULT_ORDERS_STATUS_ID;
$comments = MBOOKERS_EMAIL_ORD_FAIL;
zen_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_NOTIFY_SUBJECT, $comments, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
exit;
}
// update order status
$last_modified = 'now()';
$db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status = '" . $order_status . "', last_modified = '" . $last_modified . "' WHERE orders_id = '" . (int)$order_id . "'");
// construct emails
$notify_comments = MBOOKERS_EMAIL_COMMENTS_UPDATE . $comments . "\n\n";
$message = STORE_NAME . "\n" . MBOOKERS_EMAIL_SEPARATOR . "\n";
$message .= MBOOKERS_EMAIL_ORDER_NUMBER . ' ' . $order_id . "\n\n";
$message .= MBOOKERS_EMAIL_INVOICE_URL . ' ' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL') . "\n\n";
$message .= MBOOKERS_EMAIL_DATE_ORDERED . ' ' . zen_date_long($order_details->fields['date_purchased']) . "\n\n" . strip_tags($notify_comments);
$message .= MBOOKERS_EMAIL_STATUS_UPDATED . sprintf(MBOOKERS_EMAIL_STATUS_LABEL, $order_status_detail) . MBOOKERS_EMAIL_STATUS_PLEASE_REPLY;
$html_msg['EMAIL_CUSTOMERS_NAME'] = $order_details->fields['customers_name'];
$html_msg['EMAIL_TEXT_ORDER_NUMBER'] = MBOOKERS_EMAIL_ORDER_NUMBER . ' ' . $order_id;
$html_msg['EMAIL_TEXT_INVOICE_URL'] = '<a href="' . zen_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL') .'">'.str_replace(':','',MBOOKERS_EMAIL_INVOICE_URL).'</a>';
$html_msg['EMAIL_TEXT_DATE_ORDERED'] = MBOOKERS_EMAIL_DATE_ORDERED . ' ' . zen_date_long($order_details->fields['date_purchased']);
$html_msg['EMAIL_TEXT_STATUS_COMMENTS'] = nl2br($notify_comments);
$html_msg['EMAIL_TEXT_STATUS_UPDATED'] = str_replace('\n','', MBOOKERS_EMAIL_STATUS_UPDATED);
$html_msg['EMAIL_TEXT_STATUS_LABEL'] = str_replace('\n','', sprintf(MBOOKERS_EMAIL_STATUS_LABEL, $order_status_detail));
$html_msg['EMAIL_TEXT_NEW_STATUS'] = $order_status_detail;
$html_msg['EMAIL_TEXT_STATUS_PLEASE_REPLY'] = str_replace('\n','', MBOOKERS_EMAIL_STATUS_PLEASE_REPLY);
// update customer
if (MODULE_PAYMENT_MBOOKERS_GWAY_CUST_EMAIL == 'YES') {
zen_mail($order_details->fields['customers_name'], $order_details->fields['customers_email_address'], MBOOKERS_EMAIL_SUBJECT, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status');
$customer_notified = '1';
}
// update admin
if (MODULE_PAYMENT_MBOOKERS_GWAY_ADMIN_EMAIL == 'YES') {
zen_mail('', STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_SUBJECT, MBOOKERS_EMAIL_EXTRA_NOTE . $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status');
}
// update order status history table
$db->Execute("INSERT INTO " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
VALUES ('" . (int)$order_id . "',
'" . zen_db_input($order_status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
'" . zen_db_input($comments) . "')");
// adjust download_maxdays based on current date
if ($order_status == MODULE_PAYMENT_MBOOKERS_GWAY_PROCESSED_KEY) {
$zc_max_days = date_diff($order_details->fields['date_purchased'], date('Y-m-d H:i:s', time())) + DOWNLOAD_MAX_DAYS;
$db->Execute("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_maxdays='" . $zc_max_days . "', download_count='" . DOWNLOAD_MAX_COUNT . "' where orders_id='" . (int)$order_id . "'");
}
} else {
// Notify Admin of failed checks
$message = MBOOKERS_EMAIL_MD5_FAIL . "\n\n" .
MBOOKERS_EMAIL_ORDER_NUMBER . ' ' . $order_id . "\n" .
MBOOKERS_EMAIL_DATE_ORDERED . ' ' . $order_details->fields['date_purchased'] . "\n\n" .
MBOOKERS_EMAIL_NOTIFY_MD5;
$html_msg['EMAIL_SUBJECT'] = MBOOKERS_EMAIL_NOTIFY_SUBJECT . '<br>';
$html_msg['EMAIL_MESSAGE_HTML'] = nl2br($message);
$html_msg['EMAIL_TEMPLATE_FILENAME'] = 'email_template_default';
zen_mail('', STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_NOTIFY_SUBJECT, $message, STORE_NAME, EMAIL_FROM, $html_msg);
}
} else {
// load email constants
require_once(DIR_WS_MODULES . 'payment/moneybookers_gateway/moneybookers_gateway_emails.php');
// Notify Admin of failed checks
$message = MBOOKERS_EMAIL_OID_FAIL . "\n\n" . MBOOKERS_EMAIL_NOTIFY_TID;
$html_msg['EMAIL_SUBJECT'] = MBOOKERS_EMAIL_NOTIFY_SUBJECT . '<br>';
$html_msg['EMAIL_MESSAGE_HTML'] = nl2br($message);
$html_msg['EMAIL_TEMPLATE_FILENAME'] = 'email_template_default';
zen_mail('', STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_NOTIFY_SUBJECT, $message, STORE_NAME, EMAIL_FROM, $html_msg);
}
} else {
// load email constants
require_once(DIR_WS_MODULES . 'payment/moneybookers_gateway/moneybookers_gateway_emails.php');
// Notify Admin of failed checks
$message = MBOOKERS_EMAIL_TID_FAIL . "\n\n" . MBOOKERS_EMAIL_NOTIFY_TID;
$html_msg['EMAIL_SUBJECT'] = MBOOKERS_EMAIL_NOTIFY_SUBJECT . '<br>';
$html_msg['EMAIL_MESSAGE_HTML'] = nl2br($message);
$html_msg['EMAIL_TEMPLATE_FILENAME'] = 'email_template_default';
zen_mail('', STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_NOTIFY_SUBJECT, $message, STORE_NAME, EMAIL_FROM, $html_msg);
//zen_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, MBOOKERS_EMAIL_NOTIFY_SUBJECT, $message, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}
}
echo 'end';
// close session
session_write_close();
?>
Please copy the script to test it. No information received after "if ($md5_check_flag == 'Pass')" line.
Bookmarks