Code:
<?php
require_once(__DIR__.'/greenmoney/lib/Green.php');
class greenmoney extends base {
var $code;
var $moduleVersion = '1.02';
var $title;
var $description;
var $enabled;
protected $reportable_submit_data;
var $transaction_id;
var $order_nstatus;
/**
* Constructor
*/
function __construct() {
global $order;
$this->code = 'greenmoney';
$this->title = MODULE_PAYMENT_GREENMONEY_TEXT_CATALOG_TITLE;
if (IS_ADMIN_FLAG === true) {
$this->description = MODULE_PAYMENT_GREENMONEY_TEXT_DESCRIPTION;
$this->title = MODULE_PAYMENT_GREENMONEY_TEXT_ADMIN_TITLE;
}
$this->enabled = (defined('MODULE_PAYMENT_GREENMONEY_STATUS') && MODULE_PAYMENT_GREENMONEY_STATUS == 'True');
$this->sort_order = defined('MODULE_PAYMENT_GREENMONEY_SORT_ORDER') ? MODULE_PAYMENT_GREENMONEY_SORT_ORDER : null;
if (null === $this->sort_order) return false;
if (MODULE_PAYMENT_GREENMONEY_STATUS == 'True' && (MODULE_PAYMENT_GREENMONEY_APIPW == '')) {
$this->title .= '<span class="alert"> (Not Configured)</span>';
} elseif (MODULE_PAYMENT_GREENMONEY_TESTMODE == 'Test') {
$this->title .= '<span class="alert"> (in Testing mode)</span>';
}
$this->gateway_currency = MODULE_PAYMENT_GREENMONEY_CURRENCY;
if (defined('MODULE_PAYMENT_GREENMONEY_ORDER_STATUS_ID') && (int)MODULE_PAYMENT_GREENMONEY_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_GREENMONEY_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
}
function update_status() {
global $order, $db;
if ($this->enabled && (int)MODULE_PAYMENT_GREENMONEY_ZONE > 0 && isset($order->billing['country']['id'])) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_GREENMONEY_ZONE . "' and zone_country_id = '" . (int)$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;
}
}
// other status checks?
if ($this->enabled) {
// other checks here
}
}
function javascript_validation() {
$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .
' var routing_number = document.checkout_payment.greenmoney_routing_number.value;' . "\n" .
' var account_number = document.checkout_payment.greenmoney_account_number.value;' . "\n";
$js .= ' if (routing_number == "" || routing_number.length < 9) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_GREENMONEY_TEXT_JS_RO_NO . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (account_number == "" || account_number < 8) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_GREENMONEY_TEXT_JS_ACC_NO . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n";
$js .= ' }' . "\n";
return $js;
}
function selection() {
$onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
return array('id' => $this->code,
'module' => $this->title,
'fields' => array(array('title' => MODULE_PAYMENT_GREENMONEY_TEXT_ROUTING_NO,
'field' => zen_draw_input_field('greenmoney_routing_number', '', 'id="'.$this->code.'-routing-number"' . $onFocus . ' autocomplete="off"'),
'tag' => $this->code.'-routing-number'),
array('title' => MODULE_PAYMENT_GREENMONEY_TEXT_ACCOUNT_NO,
'field' => zen_draw_input_field('greenmoney_account_number', '', 'id="'.$this->code.'-account-number"' . $onFocus . ' autocomplete="off"'),
'tag' => $this->code.'-account-number'),
));
}
function pre_confirmation_check() {
return true;
}
function confirmation() {
return array();
}
function process_button() {
$process_button_string = zen_draw_hidden_field('greenmoney_routing_number', $_POST['greenmoney_routing_number']) .
zen_draw_hidden_field('greenmoney_account_number', $_POST['greenmoney_account_number']) ;
$process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
return $process_button_string;
}
/**
* Store the CC info to the order and process any results that come back from the payment gateway
*
*/
function before_process() {
global $response, $db, $order, $messageStack;
$routing_number = $_POST['greenmoney_routing_number'];
$account_number = $_POST['greenmoney_account_number'];
$last_order_id = $db->Execute("select orders_id from " . TABLE_ORDERS . " order by orders_id desc limit 1");
$new_order_id = $last_order_id->fields['orders_id'];
$new_order_id = ($new_order_id + 1);
$gateway = new CheckGateway(MODULE_PAYMENT_GREENMONEY_CLIENTID, MODULE_PAYMENT_GREENMONEY_APIPW);
$name = $order->billing['firstname']. ' '. $order->billing['lastname'];
$email = $order->customer['email_address'];
$phone = $order->customer['telephone'];
$phone_ext = '';
$address1 = $order->billing['street_address'];
$address2 = '';
$city = $order->billing['city'];
$zip = $order->billing['postcode'];
$country = $order->billing['country']['iso_code_2'];
$routing = $routing_number;
$account = $account_number;
$bank_name = '';
$memo = 'Order No : '.$new_order_id;
$amount = round($order->info['total'], 2);
$date = date("m/d/Y");
$state = zen_get_zone_code($order->billing['country']['id'], $order->billing['zone_id']);
$result = $gateway->singleCheck($name, $email, $phone, $phone_ext, $address1, $address2, $city, $state, $zip, $country, $routing, $account, $bank_name, $memo, $amount, $date);
if($result) {
if($result['Result'] == '0'){
}
else {
$messageStack->add_session('checkout_payment', 'Payment Fail - '.$result['ResultDescription'], 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
}
else {
$messageStack->add_session('checkout_payment', 'Payment Fail - '.$gateway->getLastError(), 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
}
function after_process() {
return false;
}
/**
* Check to see whether module is installed
*
* @return boolean
*/
function check() {
global $db;
// install newer switches, if relevant
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_GREENMONEY_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
/**
* Install the payment module and its configuration settings
*
*/
function install() {
global $db, $messageStack;
if (defined('MODULE_PAYMENT_GREENMONEY_STATUS')) {
$messageStack->add_session('GreenMoney Payment Pages module already installed.', 'error');
zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=firstdata'));
return 'failed';
}
$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 GreenMoney Payment Module', 'MODULE_PAYMENT_GREENMONEY_STATUS', 'True', 'Do you want to accept payments via GreenMoney?', '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 ('Sort order of display.', 'MODULE_PAYMENT_GREENMONEY_SORT_ORDER', '0', 'Sort order of displaying payment options to the customer. 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, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_GREENMONEY_ORDER_STATUS_ID', '1', 'Set the status of new orders ', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', 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_GREENMONEY_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, date_added, use_function) values ('Client ID', 'MODULE_PAYMENT_GREENMONEY_CLIENTID', '', 'Client ID assigned in your GreenMoney', '6', '0', now(), 'zen_cfg_password_display')");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('API Password', 'MODULE_PAYMENT_GREENMONEY_APIPW', '', 'API Password in your GreenMoney', '6', '0', now(), 'zen_cfg_password_display')");
}
/**
* Remove the module and all its settings
*
*/
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
/**
* Internal list of configuration keys used for configuration of the module
*
* @return array
*/
function keys() {
return array('MODULE_PAYMENT_GREENMONEY_STATUS',
'MODULE_PAYMENT_GREENMONEY_SORT_ORDER',
'MODULE_PAYMENT_GREENMONEY_ORDER_STATUS_ID',
'MODULE_PAYMENT_GREENMONEY_ZONE',
'MODULE_PAYMENT_GREENMONEY_CLIENTID',
'MODULE_PAYMENT_GREENMONEY_APIPW'
);
}
}
Bookmarks