PHP Code:
<?php
class zipcash extends base{
var $code, $title, $description, $enabled;
// class constructor
function zipcash() {
$this->code = 'zipcash';
$this->title = MODULE_PAYMENT_ZIPCASH_TEXT_TITLE;
$this->description = MODULE_PAYMENT_ZIPCASH_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_ZIPCASH_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_ZIPCASH_STATUS == 'True') ? true : false);
if ((int)MODULE_PAYMENT_ZIPCASH_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_ZIPCASH_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
$this->form_action_url = 'http://www.zipcash.in/PG2Test/PayByZipcash.aspx';
}
// class methods
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_ZIPCASH_ZONE > 0) ) {
$check_flag = false;
$check_query = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_ZIPCASH_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while ($check = mysql_fetch_array($check_query)) {
if ($check['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
}
}
if ($check_flag == false) {
$this->enabled = false;
}
}
// disable the module if the order only contains virtual products
if ($this->enabled == true) {
if ($order->content_type == 'virtual') {
$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() {
return false;
}
function process_button() {
global $order, $customer_id, $MerchantId, $Amount, $OrderId, $Url, $Checksum
;
$MerchantId = MODULE_PAYMENT_ZIPCASH_MERCHANT_ID;
$Amount = $order->info['total'];
$OrderId = $customer_id . '-' . date('Ymdhis');
$Url = zen_href_link(FILENAME_CHECKOUT_PROCESS,'','SSL',true,false);
$pattern='http://www\.';
if(!(Eregi($pattern,$Url,$reg)))
eregi_replace('http://', $pattern, $Url);
$str = "$MerchantId|$OrderId|$Amount|$Url";
//Variables to be passed to ZIPCASH as a POST
$process_button_string = zen_draw_hidden_field('mercode', $MerchantId) .
zen_draw_hidden_field('txcode', $OrderId) .
zen_draw_hidden_field('amount', $Amount) .
zen_draw_hidden_field('details', 'Books') .
zen_draw_hidden_field('RU',$Url);
return $process_button_string;
}
function before_process() {
global $messageStack, $order;
if (!isset($_POST['txcode']) || $_POST['txcode'] == '') {
$messageStack->add_session('checkout_payment', MODULE_PAYMENT_ZIPCASH_ERROR, 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
$_SESSION['txcode'] = $_POST['txcode'];
$order->info['details'] .= sprintf(MODULE_PAYMENT_ZIPCASH_RECEIPT_NUMBER_TEXT, $_SESSION['txcode']);
return $_SESSION['txcode'];
}
function after_process() {
return false;
}
function output_error() {
global $HTTP_GET_VARS;
$output_error_string = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n" .
' <tr>' . "\n" .
' <td class="main"> <font color="#FF0000"><b>' . MODULE_PAYMENT_ZIPCASH_TEXT_ERROR . '</b></font><br> ' . MODULE_PAYMENT_ZIPCASH_TEXT_ERROR_MESSAGE . ' </td>' . "\n" .
' </tr>' . "\n" .
'</table>' . "\n";
return $output_error_string;
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_ZIPCASH_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 ZIPCASH Module', 'MODULE_PAYMENT_ZIPCASH_STATUS', 'True', 'Do you want to accept ZIPCASH payments?', '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, date_added) values ('Merchant Id', 'MODULE_PAYMENT_ZIPCASH_MERCHANT_ID', 'mercode', 'The Merchant Code to use for the ZIPCASH service', '6', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('WorkingKey', 'MODULE_PAYMENT_ZIPCASH_WORKING_KEY', '', 'put in the 32 bit alphanumeric key.Please note that get this key ,login to your ZIPCASH merchant account and visit the \"Generate Working Key\" section at the \"Settings & Options\" page.', '6', '2', 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 ('ZIPCASH Payment Zone', 'MODULE_PAYMENT_ZIPCASH_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) values ('ZIPCASH Sort order of display.', 'MODULE_PAYMENT_ZIPCASH_SORT_ORDER', '0', 'Sort order of ZIPCASH 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, set_function, use_function, date_added) values ('ZIPCASH Set Order Status', 'MODULE_PAYMENT_ZIPCASH_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() {
$keys = '';
$keys_array = $this->keys();
for ($i=0; $i<sizeof($keys_array); $i++) {
$keys .= "'" . $keys_array[$i] . "',";
}
$keys = substr($keys, 0, -1);
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
}
function keys() {
return array('MODULE_PAYMENT_ZIPCASH_STATUS', 'MODULE_PAYMENT_ZIPCASH_MERCHANT_ID','MODULE_PAYMENT_ZIPCASH_WORKING_KEY', 'MODULE_PAYMENT_ZIPCASH_ZONE','MODULE_PAYMENT_ZIPCASH_SORT_ORDER', 'MODULE_PAYMENT_ZIPCASH_ORDER_STATUS_ID' );
}
}
?>