<?php
/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
  class cs {
    var $code, $title, $description, $enabled;

// class constructor
	function CS() {
		global $order,$HTTP_GET_VARS;		
		$this->code = 'cs';
		$name = "Cybersource";
		$image = "";
		if(MODULE_PAYMENT_CS_DISPLAY_NAME != "MODULE_PAYMENT_CS_DISPLAY_NAME")$name = MODULE_PAYMENT_CS_DISPLAY_NAME;
		if(MODULE_PAYMENT_CS_IMAGE != "MODULE_PAYMENT_CS_IMAGE")$image = MODULE_PAYMENT_CS_IMAGE;
		if($image != "" && file_exists("../" . DIR_WS_IMAGES . $image)){
			$image = '<img src="'. HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $image . '" width="103" height="33">';
		}else{
			$image_array = array('.gif','.jpg','.jpeg','.png');
			$image_check = true;
			for($i=0;$i<sizeof($image_array);$i++){
				if($image_check && $image != "" && file_exists($path . DIR_WS_IMAGES . $image . $image_array[$i])){
					$image = '<img src="'. HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . $image . $image_array[$i] . '" width="103" height="33">';
					$image_check = false;
				}
			}
		}
		define('MODULE_PAYMENT_CS_TEXT_TITLE', $name . '&nbsp;&nbsp;' . $image);
		$this->title = MODULE_PAYMENT_CS_TEXT_TITLE;
		$this->description = MODULE_PAYMENT_CS_TEXT_DESCRIPTION;
		$this->enabled = ((MODULE_PAYMENT_CS_STATUS == 'True') ? true : false);
		$this->sort_order = MODULE_PAYMENT_CS_SORT_ORDER;
		
		if ((int)MODULE_PAYMENT_CS_ORDER_STATUS_ID > 0) {
			$this->order_status = MODULE_PAYMENT_CS_ORDER_STATUS_ID;
		}
		
		if (is_object($order)) $this->update_status();
		
		$url = explode('/',$HTTP_SERVER_VARS['PHP_SELF']);
		if( strcmp($url[2],'admin') != 0 ) {
			// Make sure that your HOP.php file is located in your store's root
			// directory, i.e., /store/ or /catalog/ etc.
			//include_once("HOP.php");
			include_once(DIR_FS_CATALOG. DIR_WS_MODULES . 'payment/cybersource/HOP.php');
		}
		// The line below is the production line.
		//$this->form_action_url = 'https://orderpage.ic3.com/hop/ProcessOrder.do';
		$this->form_action_url = ((MODULE_PAYMENT_CS_TESTMODE == 'Test') ? "https://orderpagetest.ic3.com/hop/CheckOrderData.do" : "https://orderpage.ic3.com/hop/ProcessOrder.do");
		//$this->form_action_url = tep_href_link(FILENAME_CHECKOUT_CS_RESULT,'oID='.$HTTP_GET_VARS['oID'],'SSL');
		//echo $this->form_action_url ;
		// The line below is for debugging and doesn't process the order or
		// return a status. It halts on CyberSource's checker script to show you
		// the data being received and if it's valid.
		//$this->form_action_url = 'https://orderpage.ic3.com/hop/CheckOrderData.do';
	}


// class methods
    function update_status() {
      global $order;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CS_ZONE > 0) ) {
        $check_flag = false;
        $check = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CS_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;
        }
      }
    }

    function javascript_validation() {
      $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
            '    var cc_owner = document.checkout_payment.CS_cc_owner.value;' . "\n" .
            '    var cc_number = document.checkout_payment.CS_cc_number.value;' . "\n" .
			'	var cc_cvv = document.checkout_payment.CS_cc_cvv.value;' . "\n" .
            '    if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
            '      error_message = error_message + "' . MODULE_PAYMENT_CS_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_CS_TEXT_JS_CC_NUMBER . '";' . "\n" .
            '      error = 1;' . "\n" .
            '    }' . "\n";
	if (MODULE_PAYMENT_CS_COLLECT_CVV == 'True')  {
        $js .= '    if (cc_cvv == "" || cc_cvv.length < ' . CC_CVV_MIN_LENGTH . ') {' . "\n" .
               '      error_message = error_message + "' . MODULE_PAYMENT_CS_TEXT_JS_CC_CVV . '";' . "\n" .
               '      error = 1;' . "\n" .
               '    }' . "\n";
      }
		$js .= '  }' . "\n";

      return $js;
    }

    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' => $this->title,
                         'fields' => 	array(array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_OWNER_FIRST,
						 							'field' => tep_draw_input_field('first_name', $order->billing['firstname'])),
						 				  	  array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_OWNER_LAST,
						 							'field' => tep_draw_input_field('last_name', $order->billing['lastname'])),
						 				   	  array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_NUMBER,
                                                    'field' => tep_draw_input_field('card_accountNumber')),
                                              array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_EXPIRES,
                                                    'field' => tep_draw_pull_down_menu('card_expirationMonth', $expires_month) . '&nbsp;' . tep_draw_pull_down_menu('card_expirationYear', $expires_year))));

      if (MODULE_PAYMENT_CS_COLLECT_CVV == 'True')  {
       $selection['fields'][] = array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_CVV,
                                                 'field' => tep_draw_input_field('card_cvNumber'));
      }
	  
	 // $selection['fields'][] = array('title' => "<hr>", 'field' => "<hr>");
	  
	  return $selection;
    }

    function pre_confirmation_check() {
      global $HTTP_POST_VARS;

      include(DIR_WS_CLASSES . 'cc_validation.php');

      $cc_validation = new cc_validation();
      $result = $cc_validation->validate($HTTP_POST_VARS['card_accountNumber'], $HTTP_POST_VARS['card_expirationMonth'], $HTTP_POST_VARS['card_expirationYear']);
      $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) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&card_expirationMonth=' . $HTTP_POST_VARS['card_expirationMonth'] . '&card_expirationYear=' . $HTTP_POST_VARS['card_expirationYear'];
        tep_redirect(tep_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_card_first_name = $HTTP_POST_VARS['first_name'];
	  $this->cc_card_last_name = $HTTP_POST_VARS['last_name'];
	  if (MODULE_PAYMENT_CS_COLLECT_CVV == 'True')  {
		  $this->cc_card_cvNumber = $HTTP_POST_VARS['card_cvNumber'];//Needed for CVV submissions.
	  }
      $this->cc_expiry_month = $cc_validation->cc_expiry_month;
      $this->cc_expiry_year = $cc_validation->cc_expiry_year;
    }

    function confirmation() {
      global $HTTP_POST_VARS;

      $confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
                            'fields' => array(array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_OWNER_FIRST,
                                                    'field' => $HTTP_POST_VARS['first_name']),
                                              array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_OWNER_LAST,
                                                    'field' => $HTTP_POST_VARS['last_name']),
                                              array('title' => MODULE_PAYMENT_CS_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_CS_TEXT_CREDIT_CARD_EXPIRES,
                                                    'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['card_expirationMonth'], 1, '20' . $HTTP_POST_VARS['card_expirationYear'])))));

      if (MODULE_PAYMENT_CS_COLLECT_CVV == 'True')  {
       $confirmation['fields'][] = array('title' => MODULE_PAYMENT_CS_TEXT_CREDIT_CARD_CVV,
                                                 'field' => $HTTP_POST_VARS['card_cvNumber']);
      }
	  return $confirmation;
    }

    function process_button() {
      //global $HTTP_SERVER_VARS, $db, $order;
	  global $HTTP_SERVER_VARS,$HTTP_POST_VARS, $order ;
	  
	//  print_r($HTTP_SERVER_VARS);
	// echo '<br>';
	 // print_r($HTTP_POST_VARS);	  	 
	  
		  // Calculate the next expected order id
	  $last_order_id = tep_db_query("select * 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);
  
      $process_button_string = tep_draw_hidden_field('card_accountNumber', $this->cc_card_number) ."\n".
                               tep_draw_hidden_field('card_expirationMonth', $this->cc_expiry_month) ."\n".
							   tep_draw_hidden_field('card_expirationYear', $this->cc_expiry_year)."\n";
							   
	  if (MODULE_PAYMENT_CS_COLLECT_CVV == 'True')  {
		  $process_button_string .= tep_draw_hidden_field('card_cvNumber',$this->cc_card_cvNumber) . "\n";//Needed for CVV submissions.
	  }
	  
	  
	  
	  
	  $states = array(
            'ARMED FORCES AMERICA' => 'AA',
            'ARMED FORCES EUROPE' => 'AE',
            'ALASKA' => 'AK',
            'ALABAMA' => 'AL',
            'ARMED FORCES PACIFIC' => 'AP',
            'ARKANSAS' => 'AR',
            'ARIZONA' => 'AZ',
            'CALIFORNIA' => 'CA',
            'COLORADO' => 'CO',
            'CONNECTICUT' => 'CT',
            'DISTRICT OF COLUMBIA' => 'DC',
            'DELAWARE' => 'DE',
            'FLORIDA' => 'FL',
            'GEORGIA' => 'GA',
            'HAWAII' => 'HI',
            'IOWA' => 'IA',
            'IDAHO' => 'ID',
            'ILLINOIS' => 'IL',
            'INDIANA' => 'IN',
            'KANSAS' => 'KS',
            'KENTUCKY' => 'KY',
            'LOUISIANA' => 'LA',
            'MASSACHUSETTS' => 'MA',
            'MARYLAND' => 'MD',
            'MAINE' => 'ME',
            'MICHIGAN' => 'MI',
            'MINNESOTA' => 'MN',
            'MISSOURI' => 'MO',
            'MISSISSIPPI' => 'MS',
            'MONTANA' => 'MT',
            'NORTH CAROLINA' => 'NC',
            'NORTH DAKOTA' => 'ND',
            'NEBRASKA' => 'NE',
            'NEW HAMPSHIRE' => 'NH',
            'NEW JERSEY' => 'NJ',
            'NEW MEXICO' => 'NM',
            'NEVADA' => 'NV',
            'NEW YORK' => 'NY',
            'OHIO' => 'OH',
            'OKLAHOMA' => 'OK',
            'OREGON' => 'OR',
            'PENNSYLVANIA' => 'PA',
            'RHODE ISLAND' => 'RI',
            'SOUTH CAROLINA' => 'SC',
            'SOUTH DAKOTA' => 'SD',
            'TENNESSEE' => 'TN',
            'TEXAS' => 'TX',
            'UTAH' => 'UT',
            'VIRGINIA' => 'VA',
            'VERMONT' => 'VT',
            'WASHINGTON' => 'WA',
            'WISCONSIN' => 'WI',
            'WEST VIRGINIA' => 'WV',
            'WYOMING' => 'WY',
        );
	  
	  	$return_link=tep_href_link(FILENAME_CHECKOUT_CS_RESULT, '', 'SSL');
		$return_link="http://test2.oscommres.com/";			
		$process_button_string .=  tep_draw_hidden_field('orderNumber',MODULE_PAYMENT_CS_ORDER_PREFIX.$new_order_id) . "\n" .
							   tep_draw_hidden_field('orderPage_transactionType','authorization') . "\n" .
							   tep_draw_hidden_field('card_cardType',$card_type) ."\n" .
							   //tep_draw_hidden_field('taxAmount', number_format($order->info['tax'], 2)) ."\n".                              							  
							   // Sending Customer Information 
                               tep_draw_hidden_field('billTo_street1', $order->billing['street_address']) ."\n".
                               tep_draw_hidden_field('billTo_street2', $order->billing['suburb']) ."\n".
							   tep_draw_hidden_field('billTo_city', $order->billing['city']) ."\n".
							   //tep_draw_hidden_field('billTo_country', $order->billing['country']['iso_code_2']) ."\n".							   
							   tep_draw_hidden_field('billTo_country', 'US') ."\n".
							   tep_draw_hidden_field('billTo_email', $order->customer['email_address']) ."\n".
							   tep_draw_hidden_field('billTo_firstName', $this->cc_card_first_name) . "\n" . //$order->billing['firstname']) ."\n".
                               tep_draw_hidden_field('billTo_lastName', $this->cc_card_last_name) . "\n" . //$order->billing['lastname']) ."\n".
							   tep_draw_hidden_field('billTo_phoneNumber', $order->customer['telephone']) ."\n".
                               tep_draw_hidden_field('billTo_state', strtoupper($order->billing['state'])) ."\n".
                               tep_draw_hidden_field('billTo_postalCode', $order->delivery['postcode']) ."\n".
                               tep_draw_hidden_field('shipTo_city', $order->delivery['city']) ."\n".
                               //tep_draw_hidden_field('shipTo_country', $order->delivery['country']['iso_code_2']) . "\n" .                               
                               tep_draw_hidden_field('shipTo_country', 'US') . "\n" .
                               tep_draw_hidden_field('shipTo_firstName', $order->customer['firstname']) ."\n".
                               tep_draw_hidden_field('shipTo_lastName', $order->customer['lastname']) ."\n".
                               tep_draw_hidden_field('shipTo_street1', $order->delivery['street_address']) ."\n".
                               tep_draw_hidden_field('shipTo_street2', $order->delivery['suburb']) ."\n".
                               tep_draw_hidden_field('shipTo_state', strtoupper($order->delivery['state'])) ."\n".
                               tep_draw_hidden_field('shipTo_postalCode', $order->delivery['postcode']) ."\n".                                                              							   
                               //tep_draw_hidden_field('orderPage_sendMerchantURLPost', $return_link) ."\n".
                               tep_draw_hidden_field('orderPage_receiptResponseURL', $return_link) ."\n".                               
                               //tep_draw_hidden_field('currency',$order->info['currency']) ."\n".                                                              
                               tep_draw_hidden_field('currency','usd') ."\n".
							  //Sending Payment Information Fields
							   tep_draw_hidden_field('paymentOption', 'card') ."\n" .
							   InsertSignature(number_format($order->info['total'], 2,'.',''));//No ,'s allowed anymore between thousands.
								// InsertSignature is part of the HOP.php library.															   
			                 //"<input type='hidden' name='returnurl' value='" . $return_link . "'>";
			
	  

		
	//ORIGINAL, Just mastercard and Visa.  Copied in next section from cc_validation.php
	/*if( strpos($this->cc_card_number,'4') == 0 ) {//Visa
		$card_type = "001";
	}
	else if( strpos($this->cc_card_number,'5') == 0 ) {//Mastercard
		$card_type = "002";
	}*/
	
	//NEW section for identifying credit cards, does all the cc_validation handles.
	if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_card_number) and CC_ENABLED_VISA=='1') {
		$card_type="001";
    } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_card_number) and CC_ENABLED_MC=='1') {
        $card_type="002";
    } elseif (ereg('^3[47][0-9]{13}$', $this->cc_card_number) and CC_ENABLED_AMEX=='1') {
        $card_type="003";
    } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_card_number) and CC_ENABLED_DINERS_CLUB=='1') {
        $card_type="005";
    } elseif (ereg('^6011[0-9]{12}$', $this->cc_card_number) and CC_ENABLED_DISCOVER=='1') {
        $card_type="004";
    } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_card_number) and CC_ENABLED_JCB=='1') {
        $card_type="007";
    } //otherwise anything is possible.
	
	
	
	// The line below may be a duplicate, but the first instance above was
	// already included_once, so this shouldn't be an issue and can be left
	// alone.
	//include_once("HOP.php");
	include_once(DIR_FS_CATALOG. DIR_WS_MODULES . 'payment/cybersource/HOP.php');
	
	// Set this to whatever your want your prefix to be...it'll help you to
	// eyeball what orders are from your Zen-Cart when using your CycleSource
	// back-end. Set to '' to make it empty, so just the order number shows.
	
			
			echo '<br>';
			//echo $return_link;
			echo '<br>';	
			
			
		//	break;		
				  
		return $process_button_string;
    }

    function before_process() {
	    global $HTTP_GET_VARS;
		if ( strcmp($HTTP_GET_VARS['result'],'true') == 0 ){
			$order->info['cc_owner'] = $HTTP_POST_VARS['first_name'] . ' ' . $HTTP_POST_VARS['last_name'];
			$order->info['cc_type'] = $this->cc_card_type;
			$order->info['cc_number'] = $this->cc_card_number; //STORE number.  
			return; //accepted
		}
       /* else { // These are the real reason codes that I thought were most descriptive.
			// Feel free to add/remove the codes you want, but these should
			// be all you'll need.
			if( strcmp($HTTP_POST_VARS['reasonCode'],'150') == 0 || strcmp($HTTP_POST_VARS['reasonCode'],'207') == 0 || strcmp($HTTP_POST_VARS['reasonCode'],'236') == 0 ) {
				$error = "There was a general error. Please try again in a few minutes.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'151') == 0 || strcmp($HTTP_POST_VARS['reasonCode'],'152') == 0 || strcmp($HTTP_POST_VARS['reasonCode'],'250') == 0 ) {
				$error = "There was a general error. Please contact us to avoid any duplication of your order.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'202') == 0 ) {
				$error = "Your credit card has expired. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'204') == 0 ) {
				$error = "There are insufficient funds in that card. Please try another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'205') == 0 ) {
				$error = "This card has been reported lost or stolen. Please destroy it and use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'208') == 0 || strcmp($HTTP_POST_VARS['reasonCode'],'220') == 0 ) {
				$error = "This card is not authorized for card-not-present transactions. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'210') == 0 ) {
				$error = "This card is maxed out. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'211') == 0 ) {
				$error = "Invalid card verification number. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'222') == 0 ) {
				$error = "Your account is frozen. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'231') == 0 ) {
				$error = "The card number you entered is invalid. Please use another card.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'520') == 0 ) {
				$error = "Your billing address, name, or CVV number does not match the card number provided. Please correct the information and try again.";
			}
			elseif( strcmp($HTTP_POST_VARS['reasonCode'],'') == 0 ) {
				//$error = "There was a general error. Please double-check your information and try again.";
			//}
			//else {
				$error = "There was a general error. Please contact us to avoid order duplication. Error #".$HTTP_POST_VARS['reasonCode'];
			}
			tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode($error), 'SSL', true, false));
		}*/
	 }

    function after_process() {
      return false;
    }

    function get_error() {
      global $HTTP_GET_VARS;

      $error = array('title' => MODULE_PAYMENT_CS_TEXT_ERROR,
                     'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));

      return $error;
    }

    function check() {
      global $db;
      if (!isset($this->_check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CS_STATUS'");
        $this->_check = tep_db_num_rows($check_query);
      }
      return $this->_check;
    }

    function install() {
      global $db;
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable CyberSource HOP Module', 'MODULE_PAYMENT_CS_STATUS', 'True', 'Do you want to accept VISA or MC 
			through CyberSource?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Login Username', 'MODULE_PAYMENT_CS_LOGIN', 'testing', 'The login username used for CyberSource', '6', '0', now())");
      tep_db_query("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_CS_TESTMODE', 'Test', 'Transaction mode used for processing orders', '6', '0', 'tep_cfg_select_option(array(\'Test\', \'Production\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Method', 'MODULE_PAYMENT_CS_METHOD', 'Credit Card', 'Transaction method used for processing orders', '6', '0', 'tep_cfg_select_option(array(\'Credit Card\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Collect & store the CVV number', 'MODULE_PAYMENT_CS_COLLECT_CVV', 'True', 'Do you want to collect the CVV number. Note: If you do the CVV number will be stored in the database in an encoded format.', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("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_CS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
      tep_db_query("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_CS_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
      tep_db_query("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_CS_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
	  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Display Name', 'MODULE_PAYMENT_CS_DISPLAY_NAME', 'Cybersource', 'Set the Display name to payment module', '6', '9', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Image', 'MODULE_PAYMENT_CS_IMAGE', 'cybersource', 'Set the Image of payment module', '6', '10', 'tep_cfg_file_field(', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant Number', 'MODULE_PAYMENT_CS_MERCHANT_NUMBER', 'sec0001', 'The merchant number used for the Cybersource', '6', '0', now())");
    }

    function remove() {
      global $db;
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_PAYMENT_CS_STATUS', 'MODULE_PAYMENT_CS_LOGIN', 'MODULE_PAYMENT_CS_TESTMODE', 'MODULE_PAYMENT_CS_METHOD', 'MODULE_PAYMENT_CS_COLLECT_CVV', 'MODULE_PAYMENT_CS_ZONE', 'MODULE_PAYMENT_CS_ORDER_STATUS_ID', 'MODULE_PAYMENT_CS_SORT_ORDER','MODULE_PAYMENT_CS_DISPLAY_NAME','MODULE_PAYMENT_CS_IMAGE');
    }
  }
?>