Code:
<?php
//
// +----------------------------------------------------------------------+
// | Copyright (c) 2005 Jason LeBaron - [email protected] |
// | |
// | Portions Copyright (c) 2005 Zen-Cart - http://www.zen-cart.com |
// | Portions Copyright (c) 2004 osCommerce - http://www.oscommerce.com |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/licenses/gpl.txt. |
// +----------------------------------------------------------------------+
// | Module created by Jason LeBaron |
// | Released under GPL |
// +----------------------------------------------------------------------+
// $Id: psigate_xml.php 1 2005-07-12 17:00:00Z networkdad $
class psigate_xml {
var $code, $title, $description, $enabled;
// class constructor
function psigate_xml() {
global $order;
$this->code = 'psigate_xml';
if ($_GET['main_page'] != '') {
$this->title = MODULE_PAYMENT_PSIGATE_XML_TEXT_CATALOG_TITLE; // Payment module title in Catalog
} else {
$this->title = MODULE_PAYMENT_PSIGATE_XML_TEXT_ADMIN_TITLE; // Payment module title in Admin
}
$this->description = MODULE_PAYMENT_PSIGATE_XML_TEXT_DESCRIPTION; // Descriptive Info about module in Admin
$this->enabled = ((MODULE_PAYMENT_PSIGATE_XML_STATUS == 'True') ? true : false); // Whether the module is installed or not
$this->sort_order = MODULE_PAYMENT_PSIGATE_XML_SORT_ORDER; // Sort Order of this payment option on the customer payment page
$this->form_action_url = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false); // Page to go to upon submitting page info
if ((int)MODULE_PAYMENT_PSIGATE_XML_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_PSIGATE_XML_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
}
// class methods
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PSIGATE_XML_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PSIGATE_XML_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;
}
}
}
// Validate the credit card information via javascript (Number, Owner, and CVV Lengths)
function javascript_validation() {
$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .
' var cc_owner = document.checkout_payment.psigate_xml_cc_owner.value;' . "\n" .
' var cc_number = document.checkout_payment.psigate_xml_cc_number.value;' . "\n";
$js .= ' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PSIGATE_XML_TEXT_JS_CC_OWNER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PSIGATE_XML_TEXT_JS_CC_NUMBER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" ;
return $js;
}
// Display Credit Card Information Submission Fields on the Checkout Payment Page
function selection() {
global $order;
for ($i=1; $i<13; $i++) {
$expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
}
$today = getdate();
for ($i=$today['year']; $i < $today['year']+10; $i++) {
$expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
}
$selection = array('id' => $this->code,
'module' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CATALOG_TITLE,
'fields' => array(array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_OWNER,
'field' => zen_draw_input_field('psigate_xml_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_NUMBER,
'field' => zen_draw_input_field('psigate_xml_cc_number')),
array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_EXPIRES,
'field' => zen_draw_pull_down_menu('psigate_xml_cc_expires_month', $expires_month) . ' ' . zen_draw_pull_down_menu('psigate_xml_cc_expires_year', $expires_year)),
array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CVV . ' ' .'<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_CVV_HELP) . '\')">' . MODULE_PAYMENT_PSIGATE_XML_TEXT_POPUP_CVV_LINK . '</a>',
'field' => zen_draw_input_field('psigate_xml_cc_cvv', '', "size=4, maxlength=4"))));
return $selection;
}
// Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date
function pre_confirmation_check() {
global $_POST;
include(DIR_WS_CLASSES . 'cc_validation.php');
$cc_validation = new cc_validation();
$result = $cc_validation->validate($_POST['psigate_xml_cc_number'], $_POST['psigate_xml_cc_expires_month'], $_POST['psigate_xml_cc_expires_year'], $_POST['psigate_xml_cc_cvv']);
$error = '';
switch ($result) {
case -1:
$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
break;
case -2:
case -3:
case -4:
$error = TEXT_CCVAL_ERROR_INVALID_DATE;
break;
case false:
$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
break;
}
if ( ($result == false) || ($result < 1) ) {
$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&psigate_xml_cc_owner=' . urlencode($_POST['psigate_xml_cc_owner']) . '&psigate_xml_cc_expires_month=' . $_POST['psigate_xml_cc_expires_month'] . '&psigate_xml_cc_expires_year=' . $_POST['psigate_xml_cc_expires_year'];
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
}
$this->cc_card_type = $cc_validation->cc_type;
$this->cc_card_number = $cc_validation->cc_number;
$this->cc_expiry_month = $cc_validation->cc_expiry_month;
$this->cc_expiry_year = $cc_validation->cc_expiry_year;
}
// Display Credit Card Information on the Checkout Confirmation Page
function confirmation() {
global $_POST;
$confirmation = array(//'title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CATALOG_TITLE, // Redundant
'fields' => array(array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_OWNER,
'field' => $_POST['psigate_xml_cc_owner']),
array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_NUMBER,
'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_CREDIT_CARD_EXPIRES,
'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['psigate_xml_cc_expires_month'], 1, '20' . $_POST['psigate_xml_cc_expires_year'])))));
return $confirmation;
}
function process_button() {
global $_POST;
// These are hidden fields on the checkout confirmation page
$process_button_string = zen_draw_hidden_field('cc_owner', $_POST['psigate_xml_cc_owner']) .
zen_draw_hidden_field('cc_expires', $this->cc_expiry_month . substr($this->cc_expiry_year, -2)) .
zen_draw_hidden_field('cc_expires_month', $this->cc_expiry_month) .
zen_draw_hidden_field('cc_expires_year', substr($this->cc_expiry_year, -2)) .
zen_draw_hidden_field('cc_type', $this->cc_card_type) .
zen_draw_hidden_field('cc_number', $this->cc_card_number) .
zen_draw_hidden_field('cc_cvv', $_POST['psigate_xml_cc_cvv']);
$process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
return $process_button_string;
}
function before_process() {
global $_POST, $_SERVER, $order, $db, $psi_response_array, $psi_order_id;
$order->info['cc_type'] = $_POST['cc_type'];
$order->info['cc_owner'] = $_POST['cc_owner'];
$order->info['cc_cvv'] = $_POST['cc_cvv'];
// Build Info to send to Gateway
require_once(DIR_WS_MODULES . 'payment/psigate_xml/class.psigate_xml.php');
$psi = new PsiGatePayment;
$psi->setGatewayURL(((MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_MODE == 'Production') ? 'https://secure.psigate.com:7934/Messenger/XMLMessenger' : 'https://dev.psigate.com:7989/Messenger/XMLMessenger'));
$psi->setStoreID((($_SESSION['currency'] == 'CAD') ? MODULE_PAYMENT_PSIGATE_XML_STORE_ID_CAD : MODULE_PAYMENT_PSIGATE_XML_STORE_ID_USD));
$psi->setPassPhrase((($_SESSION['currency'] == 'CAD') ? MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_CAD : MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_USD)); // Assures authenticity
$psi->setPaymentType('CC');
$psi->setCardAction(((MODULE_PAYMENT_PSIGATE_XML_AUTHORIZATION_MODE == 'Authorize') ? '1' : '0'));
$psi->setSubTotal($order->info['total']);
$psi->setCardNumber($_POST['cc_number']);
$psi->setCardExpMonth($_POST['cc_expires_month']);
$psi->setCardExpYear($_POST['cc_expires_year']);
$psi->setUserID($_SESSION['customer_id']);
$psi->setBname($order->billing['firstname'] . ' ' . $order->billing['lastname']);
$psi->setBcompany($order->billing['company']);
$psi->setBaddress1($order->billing['street_address']);
$psi->setBaddress2($order->billing['suburb']);
$psi->setBcity($order->billing['city']);
$psi->setBprovince($order->billing['state']);
$psi->setBpostalCode($order->billing['postcode']);
$psi->setBcountry($order->billing['country']['iso_code_2']);
$psi->setSname($order->delivery['firstname'] . ' ' . $order->delivery['lastname']);
$psi->setScompany($order->delivery['company']);
$psi->setSaddress1($order->delivery['street_address']);
$psi->setSaddress2($order->delivery['suburb']);
$psi->setScity($order->delivery['city']);
$psi->setSprovince($order->delivery['state']);
$psi->setSpostalCode($order->delivery['postcode']);
$psi->setScountry($order->delivery['country']['iso_code_2']);
$psi->setPhone($order->customer['telephone']);
$psi->setEmail($order->customer['email_address']);
$psi->setComments("Zen-Cart XML Interface 1.0");
$psi->setCustomerIP($_SERVER['REMOTE_ADDR']);
$psi->setCardIDCode('1');
$psi->setCardIDNumber($_POST['cc_cvv']);
if (MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_MODE == 'Test') {
switch (MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_TEST_RESULT) {
case "Approved": $psi->setTestResult('A'); break;
case "Declined": $psi->setTestResult('D'); break;
case "Random": $psi->setTestResult('R'); break;
case "Fraud": $psi->setTestResult('F'); break;
}
}
// Send transaction data to the gateway
$psi_xml_error = (!($psi->doPayment() == PSIGATE_TRANSACTION_OK));
// Create an array for database storage of gateway responses
$psi_response_array = array(
// $Psi_TransTime => $psi->getTrxnTransTime(),
psi_order_id => $psi->getTrxnOrderID(),
// $Psi_Approved => $psi->getTrxnApproved(),
// $Psi_ReturnCode => $psi->getTrxnReturnCode(),
// $Psi_ErrMsg => $psi->getTrxnErrMsg(),
// $Psi_TaxTotal => $psi->getTrxnTaxTotal(),
// $Psi_ShipTotal => $psi->getTrxnShipTotal(),
// $Psi_SubTotal => $psi->getTrxnSubTotal(),
// $Psi_FullTotal => $psi->getTrxnFullTotal(),
// $Psi_PaymentType => $psi->getTrxnPaymentType(),
// $Psi_CardNumber => $psi->getTrxnCardNumber(),
// $Psi_CardExpMonth => $psi->getTrxnCardExpMonth(),
// $Psi_CardExpYear => $psi->getTrxnCardExpYear(),
trans_ref => $psi->getTrxnTransRefNumber(),
cvv_result => $psi->getTrxnCardIDResult(),
avs_result => $psi->getTrxnAVSResult());
// $Psi_CardAuthNumber => $psi->getTrxnCardAuthNumber(),
// $Psi_CardRefNumber => $psi->getTrxnCardRefNumber(),
// $Psi_CardType => $psi->getTrxnCardType(),
// ip_result => $psi->getTrxnIPResult(),
// ip_country => $psi->getTrxnIPCountry(),
// ip_region => $psi->getTrxnIPRegion(),
// ip_city => $psi->getTrxnIPCity()
$psi_order_id = $psi->getTrxnOrderID();
// Transaction was not approved. Send to checkout_payment page again and display error to customer
if ($psi_xml_error) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . $Psi_ErrMsg . ' - ' . urlencode(MODULE_PAYMENT_PSIGATE_XML_TEXT_DECLINED_MESSAGE), 'SSL', true, false));
}
}
function after_process() {
return false;
}
function after_order_create($zf_order_id) {
global $db, $order, $psi_order_id, $psi_response_array;
// Save response in table
zen_db_perform(TABLE_PSIGATE_XML, $psi_response_array);
$db->execute("update " . TABLE_PSIGATE_XML . " set zen_order_id ='" . $zf_order_id . "' where psi_order_id = '" . $psi_order_id ."'");
}
function admin_notification($zf_order_id) {
global $db, $psi_response_array;
$sql = "select * from " . TABLE_PSIGATE_XML . " where zen_order_id = '" . $zf_order_id . "'";
$psigate_xml = $db->Execute($sql);
require(DIR_FS_CATALOG. DIR_WS_MODULES . 'payment/psigate_xml/psigate_xml_admin_notification.php');
return $output;
}
function get_error() {
global $_GET;
$error = array('title' => MODULE_PAYMENT_PSIGATE_XML_TEXT_ERROR,
'error' => stripslashes(urldecode($_GET['error'])));
return $error;
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PSIGATE_XML_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable PSiGate XML Payment Module', 'MODULE_PAYMENT_PSIGATE_XML_STATUS', 'True', 'Do you want to accept PSiGate credit card payments?', '6', '0', '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, date_added) values ('PSiGate Store ID - CAD', 'MODULE_PAYMENT_PSIGATE_XML_STORE_ID_CAD', 'teststore', 'Please enter your PSiGate Store ID for CAD currency', '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 ('PSiGate Passphrase - CAD', 'MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_CAD', 'psigate1234', 'Please enter your PSiGate Passphrase for CAD currency', '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 ('PSiGate Store ID - USD', 'MODULE_PAYMENT_PSIGATE_XML_STORE_ID_USD', 'teststore', 'Please enter your PSiGate Store ID for USD currency', '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 ('PSiGate Passphrase - USD', 'MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_USD', 'psigate1234', 'Please enter your PSiGate Passphrase for USD currency', '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 ('Transaction Mode', 'MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_MODE', 'Production', 'Transaction mode used for processing orders', '6', '0', 'zen_cfg_select_option(array(\'Test\', \'Production\'), ', 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 ('Test Mode Result', 'MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_TEST_RESULT', 'Production', 'Simulated responses when in test mode. Leave <strong>production</strong> selected if not testing', '6', '5', 'zen_cfg_select_option(array(\'Production\', \'Approved\', \'Declined\', \'Random\', \'Fraud\'), ', 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 ('Authorization Type', 'MODULE_PAYMENT_PSIGATE_XML_AUTHORIZATION_MODE', 'Authorize', 'Do you want submitted credit card transactions to be authorized only, or immediately charge?', '6', '0', 'zen_cfg_select_option(array(\'Authorize\', \'Immediate Charge\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PSIGATE_XML_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', 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 ('Payment Zone', 'MODULE_PAYMENT_PSIGATE_XML_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', '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 ('Set Order Status', 'MODULE_PAYMENT_PSIGATE_XML_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array(
'MODULE_PAYMENT_PSIGATE_XML_STATUS',
'MODULE_PAYMENT_PSIGATE_XML_STORE_ID_CAD',
'MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_CAD',
'MODULE_PAYMENT_PSIGATE_XML_STORE_ID_USD',
'MODULE_PAYMENT_PSIGATE_XML_PASSPHRASE_USD',
'MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_MODE',
'MODULE_PAYMENT_PSIGATE_XML_TRANSACTION_TEST_RESULT',
'MODULE_PAYMENT_PSIGATE_XML_AUTHORIZATION_MODE',
'MODULE_PAYMENT_PSIGATE_XML_SORT_ORDER',
'MODULE_PAYMENT_PSIGATE_XML_ZONE',
'MODULE_PAYMENT_PSIGATE_XML_ORDER_STATUS_ID');
}
}
?>
Bookmarks