Index: uc_eway.module
===================================================================
--- uc_eway.module	(revision 2459)
+++ uc_eway.module	(revision 2460)
@@ -14,28 +14,111 @@
 
 require_once('uc_eway.ca.inc');
 
-/*******************************************************************************
- * Hook Functions (Drupal)
- ******************************************************************************/
+// Define some variable_set defaults
+define('UC_EWAY_CUSTOMER_ID_DEFAULT', '87654321');
+define('UC_EWAY_MODE_DEFAULT', 'cvn_xml');
+define('UC_EWAY_LOGO_DEFAULT', 1);
+define('UC_EWAY_CHANGE_ORDER_STATUS_DEFAULT', 1);
+define('UC_EWAY_TEST_MODE_DEFAULT', 0);
+define('UC_EWAY_TEST_APPROVE_ANYWAY_DEFAULT', 0);
 
+// Define some variable_set defaults for block display
+define('UC_EWAY_BLOCK_POWERED_BY_SIZE_DEFAULT', 'large');
+define('UC_EWAY_BLOCK_POWERED_BY_COLOUR_DEFAULT', 'grey');
+
+/**
+ * Implementation of hook_form_alter().
+ */
 function uc_eway_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
     case 'uc_cart_checkout_form':
-	  $showLogo = variable_get('eway_logo', 'yes');
-	  if($showLogo == 'yes' && $form['panes']['payment']['payment_method']['#options']['credit'] != null) {
-	    $path = base_path() . drupal_get_path('module', 'uc_eway');
-	    $label = $form['panes']['payment']['payment_method']['#options']['credit'];
-	    $label .= '<br /><img src="'. $path .'/ewayLarge.gif" style="position: relative; top: 5px; left: 100px;">';
-	    $form['panes']['payment']['payment_method']['#options']['credit'] = $label;
-	  }
+      $show_logo = variable_get('uc_eway_logo', UC_EWAY_LOGO_DEFAULT);
+      if ($show_logo && $form['panes']['payment']['payment_method']['#options']['credit'] != null) {
+        $path = uc_eway_logo_path('small', 'white');
+        $label = $form['panes']['payment']['payment_method']['#options']['credit'];
+        $label .= '<br /><img src="'. $path .'" style="position: relative; top: 5px; left: 100px;" />';
+        $form['panes']['payment']['payment_method']['#options']['credit'] = $label;
+      }
       break;
+    case 'uc_payment_gateways_form':
+      $form['#validate'][] = 'uc_eway_settings_form_validate';
+      break;
   }
 }
 
-/*******************************************************************************
- * Hook Functions (Ubercart)
- ******************************************************************************/
+/**
+ * Generate a path to the logo image based on size and colour.
+ */
+function uc_eway_logo_path($size = UC_EWAY_BLOCK_POWERED_BY_SIZE_DEFAULT, $colour = UC_EWAY_BLOCK_POWERED_BY_COLOUR_DEFAULT) {
+  static $path = array();
+  if (!isset($path[$size . '-' . $colour])) {
+    if ($size == 'large') $size = 'medium';
+    $path[$size . '_' . $colour] = base_path() . drupal_get_path('module', 'uc_eway') . '/images/' . ucfirst($size) . ucfirst($colour) . '.gif';
+  }
+  return $path[$size . '_' . $colour];
+}
 
+/**
+ * Implementation of hook_block().
+ */
+function uc_eway_block($op = 'list', $delta = 0, $edit = array()) {
+  // The $op parameter determines what piece of information is being requested.
+  switch ($op) {
+    case 'list':
+      $blocks[0] = array(
+        'info'       => t('Powered by eWAY'),
+        'status'     => True,
+        'region'     => 'footer',
+      );
+      return $blocks;
+    case 'configure':
+      $form['uc_eway_logo_size'] = array(
+        '#type' => 'select',
+        '#title' => 'Logo size',
+        '#options' => array(
+          'large' => 'Large',
+          'small' => 'Small'
+        ),
+        '#default_value' => variable_get('uc_eway_block_powered_by_size', UC_EWAY_BLOCK_POWERED_BY_SIZE_DEFAULT)
+      );
+      $form['uc_eway_logo_colour'] = array(
+        '#type' => 'select',
+        '#title' => 'Logo colour',
+        '#options' => array(
+          'grey' => 'Grey',
+          'white' => 'White'
+        ),
+        '#default_value' => variable_get('uc_eway_block_powered_by_colour', UC_EWAY_BLOCK_POWERED_BY_COLOUR_DEFAULT)
+      );
+      return $form;
+    case 'save':
+      variable_set('uc_eway_block_powered_by_size', $edit['uc_eway_logo_size']);
+      variable_set('uc_eway_block_powered_by_colour', $edit['uc_eway_logo_colour']);
+      break;
+    case 'view':
+      switch ($delta) {
+        case 0:
+          $block['subject'] = NULL;
+          $block['content'] = uc_eway_block_powered_by_content();
+          break;
+      }
+      return $block;
+  }
+}
+
+/**
+ * Callback function for uc_eway_block().
+ */
+function uc_eway_block_powered_by_content() {
+  $size = variable_get('uc_eway_block_powered_by_size', UC_EWAY_BLOCK_POWERED_BY_SIZE_DEFAULT);
+  $colour = variable_get('uc_eway_block_powered_by_colour', UC_EWAY_BLOCK_POWERED_BY_COLOUR_DEFAULT);
+  $path = uc_eway_logo_path($size, $colour);
+  return '<a href="https://www.eway.com.au"><img src="' . $path . '" /></a>';
+}
+
+/**
+ * Implementation of hook_payment_gateway().
+ */
 function uc_eway_payment_gateway() {
   $gateways[] = array(
     'id' => 'eway',
@@ -60,66 +143,71 @@
     '#type' => 'fieldset',
     '#title' => t('eWAY Payment Gateway settings'),
   );
-  $form['eway_settings']['eway_customer_id'] = array(
+  $form['eway_settings']['uc_eway_customer_id'] = array(
     '#type' => 'textfield',
     '#title' => t('eWAY Customer ID'),
-    '#default_value' => variable_get('eway_customer_id', '87654321'),
+    '#default_value' => variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT),
     '#description' => t('Your eWAY customer ID. Provided to you by eWAY.'),
   );
-  $form['eway_settings']['eway_mode'] = array(
+  $form['eway_settings']['uc_eway_mode'] = array(
     '#type' => 'select',
-    '#title' => t('Transaction mode'),
-    '#description' => t('Transaction mode used for processing orders.'),
+    '#title' => t('eWAY mode'),
+    '#description' => t('eWAY mode used for processing orders. Options are detailed <a href="http://www.eway.com.au/Developer/LinkingtoeWAY/overview.aspx">here</a>.'),
     '#options' => array(
-      'production' => t('Production'),
-      'test' => t('Test'),
+      'merchant_xml' => t('Merchant Hosted (XML)'),
+      'cvn_xml' => t('CVN (XML)'),
+      'beagle' => t('Beagle Anti-Fraud'),
     ),
-    '#default_value' => variable_get('eway_mode', 'test'),
+    '#default_value' => variable_get('uc_eway_mode', UC_EWAY_MODE_DEFAULT),
   );
-  $form['eway_settings']['test_approve_anyway'] = array(
+  $form['eway_settings']['uc_eway_change_order_status'] = array(
     '#type' => 'select',
-    '#title' => t('When in test mode, approve "failed" transactions anyway?'),
-    '#description' => t('When in testing mode, a successful transaction will still return a fail. This overcomes that.'),
-    '#options' => array(
-      'true' => t('Yes'),
-      'false' => t('No'),
-    ),
-    '#default_value' => variable_get('test_approve_anyway', 'false'),
-  );
-  $form['eway_settings']['eway_cvn'] = array(
-    '#type' => 'select',
-    '#title' => t('Use CVN?'),
-    '#description' => t('Use CVN to verify Credit Cards?'),
-    '#options' => array(
-      'yes' => t('Yes'),
-      'no' => t('No'),
-    ),
-    '#default_value' => variable_get('eway_cvn', 'yes'),
-  );
-  $form['eway_settings']['change_order_status'] = array(
-    '#type' => 'select',
     '#title' => t('Change order status to "Payment Received" upon successful transaction?'),
     '#description' => t('Change the status of the order if the payment is successful?'),
     '#options' => array(
       1 => t('Yes'),
       0 => t('No'),
     ),
-    '#default_value' => variable_get('change_order_status', 'true'),
+    '#default_value' => variable_get('uc_eway_change_order_status', UC_EWAY_CHANGE_ORDER_STATUS_DEFAULT),
   );
-  $form['eway_settings']['eway_logo'] = array(
-    '#type' => 'select',
+  $form['eway_settings']['uc_eway_logo'] = array(
+    '#type' => 'checkbox',
     '#title' => t('Display eWay Logo?'),
     '#description' => t('Displays the eWay logo when processing credit cards. This may be required for some people depending on your terms with eWay.'),
-    '#options' => array(
-      'yes' => t('Yes'),
-      'no' => t('No'),
-    ),
-    '#default_value' => variable_get('eway_logo', 'yes'),
+    '#default_value' => variable_get('uc_eway_logo', UC_EWAY_LOGO_DEFAULT),
   );
 
+  $form['eway_testing'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('eWAY Testing settings'),
+    '#collapsible' => true,
+    '#collapsed' => true
+  );
+  $form['eway_testing']['uc_eway_test_mode'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Put the eWAY payment gateway into test mode?'),
+    '#description' => t('When in testing mode, eWAY testing servers will be used for the various eWAY modes. Please note there is currently no test service for the %beagle eWAY mode.', array('%beagle' => 'Beagle Anti-Fraud')),
+    '#default_value' => variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT),
+  );
+  $form['eway_testing']['uc_eway_test_approve_anyway'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('When in test mode, approve "failed" transactions anyway?'),
+    '#description' => t('When in testing mode, a successful transaction will still return a fail. This overcomes that.'),
+    '#default_value' => variable_get('uc_eway_test_approve_anyway', UC_EWAY_TEST_APPROVE_ANYWAY_DEFAULT),
+  );
+
   return $form;
 }
 
+function uc_eway_settings_form_validate($form_id, &$form_state) {
+  if ($form_state['values']['uc_eway_mode'] == 'beagle' && $form_state['values']['uc_eway_test_mode'] == 1) {
+    form_set_error('uc_eway_test_mode', t('The eWAY mode %beagle is currently incompatible with testing.', array('%beagle' => 'Beagle Anti-Fraud')));
+  }
+}
+
+/**
+ * Callback for payment gateway charge.
+ */
 function uc_eway_charge($order_id, $amount, $data) {
   if (!function_exists('curl_init')) {
     drupal_set_message(t('The eWAY service requires curl. Please arrange for its installation and then try again.'));
@@ -129,7 +217,7 @@
     drupal_set_message(t('The eWAY service requires SimpleXML. Please arrange for its installation and then try again.'));
     return array('success' => FALSE);
   }
-  
+
   global $user, $response;
   $order = uc_order_load($order_id);
 
@@ -148,7 +236,7 @@
       }
     }
   }
-  
+
   // Trim the description to eWay's limit of 10000 characters - ridiculously long anyway
   $description = substr($description, 0, 10000);
 
@@ -157,134 +245,135 @@
   $customer_address .= $order->billing_city . ' ';
   $customer_address .= uc_get_zone_code($order->billing_zone) . ' ';
   $customer_address .= uc_get_country_data(array('country_id' => $order->billing_country));
-  
+
   $xml_data = array(
-        'ewayCustomerID' => htmlentities(variable_get('eway_customer_id', '87654321')),
-        'ewayTotalAmount' => htmlentities(uc_currency_format($amount, FALSE, FALSE, '')),
-        'ewayCustomerFirstName' => htmlentities($order->billing_first_name),
-        'ewayCustomerLastName' => htmlentities($order->billing_last_name),
-        'ewayCustomerEmail' => htmlentities($order->primary_email),
-        'ewayCustomerAddress' => htmlentities($customer_address),
-        'ewayCustomerPostcode' => htmlentities($order->billing_postal_code),
-        'ewayCustomerInvoiceDescription' => htmlentities($description),
-        'ewayCustomerInvoiceRef' => htmlentities($order_id),
-        'ewayCardHoldersName' => htmlentities($order->payment_details['cc_owner']),
-        'ewayCardNumber' => htmlentities($order->payment_details['cc_number']),
-        'ewayCardExpiryMonth' => htmlentities($order->payment_details['cc_exp_month']),
-        'ewayCardExpiryYear' => htmlentities($order->payment_details['cc_exp_year']),
-        'ewayCVN' => htmlentities($order->payment_details['cc_cvv']),
-        'ewayTrxnNumber' => '',
-        'ewayOption1' => '',
-        'ewayOption2' => '',
-        'ewayOption3' => ''
-         );
-  
+    'ewayCustomerID' => variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT),
+    'ewayTotalAmount' => uc_currency_format($amount, FALSE, FALSE, ''),
+    'ewayCustomerFirstName' => $order->billing_first_name,
+    'ewayCustomerLastName' => $order->billing_last_name,
+    'ewayCustomerEmail' => $order->primary_email,
+    'ewayCustomerAddress' => $customer_address,
+    'ewayCustomerPostcode' => $order->billing_postal_code,
+    'ewayCustomerInvoiceDescription' => $description,
+    'ewayCustomerInvoiceRef' => $order_id,
+    'ewayCardHoldersName' => $order->payment_details['cc_owner'],
+    'ewayCardNumber' => $order->payment_details['cc_number'],
+    'ewayCardExpiryMonth' => $order->payment_details['cc_exp_month'],
+    'ewayCardExpiryYear' => $order->payment_details['cc_exp_year'],
+    'ewayTrxnNumber' => '',
+    'ewayOption1' => '',
+    'ewayOption2' => '',
+    'ewayOption3' => '',
+  );
+
+  $eway_testing = variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT);
+  switch (variable_get('uc_eway_mode', UC_EWAY_MODE_DEFAULT)) {
+    case 'merchant_xml':
+      $url = ($eway_testing) ? 'https://www.eway.com.au/gateway/xmltest/testpage.asp' : 'https://www.eway.com.au/gateway/xmlpayment.asp';
+      break;
+    case 'cvn_xml':
+      $url = ($eway_testing) ? 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp' : 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp';
+      $xml_data['ewayCVN'] = $order->payment_details['cc_cvv'];
+      break;
+    case 'beagle':
+      // Currently a testing URL for the beagle mode does not exist. When one does, add the URL as per the options above
+      $url = 'https://www.eway.com.au/gateway_cvn/xmlbeagle.asp';
+      $xml_data['ewayCVN'] = $order->payment_details['cc_cvv'];
+      $xml_data['ewayCustomerIPAddress'] = $_SERVER['REMOTE_ADDR'];
+      $xml_data['ewayCustomerBillingCountry'] = $order->billing_country;
+      break;
+  }
+
   $xmlstring = '<ewaygateway>';
   foreach ($xml_data as $key => $value) {
-        $xmlstring .= '<' . $key . '>' . $value . '</' . $key . '>';
+    $xmlstring .= '<' . $key . '>' . htmlentities($value) . '</' . $key . '>';
   }
   $xmlstring .= '</ewaygateway>';
 
+  $return_info = uc_eway_process_request($xmlstring, $url);
 
-  if (variable_get('eway_mode', 'test') == 'test') {
-	  $normal_url = 'https://www.eway.com.au/gateway/xmltest/TestPage.asp';
-	  $cvn_url = 'https://www.eway.com.au/gateway_cvn/xmltest/TestPage.asp';
+  if (array_key_exists('txStatus',$return_info['eway_response'])) {
+  switch ($return_info['eway_response']['txStatus']) {
+    case 'false':
+      $message = t('Credit card declined: !amount', array('!amount' => uc_currency_format($amount)));
+      $result = array(
+        'success' => FALSE,
+        'comment' => t('Credit card payment declined') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
+        'message' => t('Credit card payment declined') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
+        'uid' => $user->uid,
+        'data' => $return_info['eway_response']
+      );
+      if (variable_get('uc_eway_test_approve_anyway', UC_EWAY_TEST_APPROVE_ANYWAY) && variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE)) {
+        $result['success'] = TRUE;
+      }
+      drupal_set_message($result['message'],'error');
+      uc_order_comment_save($order_id,null,$result['comment'],'admin');
+      break;
+    case 'true':
+      $message = t('Credit card charged: !amount', array('!amount' => uc_currency_format($amount)));
+      $result = array(
+        'success' => TRUE,
+        'comment' => t('Credit card payment processed successfully') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
+        'message' => t('Credit card payment processed successfully') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
+        'uid' => $user->uid,
+        'data' => $return_info['eway_response']
+      );
+      // Leave a comment for the admin
+      uc_order_comment_save($order_id,null,$result['comment'],'admin');
+      // Leave a comment for the customer
+      uc_order_comment_save($order_id,null,$result['comment'],'order',null,true);
+
+      break;
   }
-  else {
-	  $normal_url = 'https://www.eway.com.au/gateway/xmlpayment.asp';
-	  $cvn_url = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp';
+  // Invoke a ca trigger to notify that the payment has been processed
+  ca_pull_trigger('uc_eway_payment_processed', $order);
   }
-  
-  switch (variable_get('eway_cvn','yes')) {
-	case 'yes':
-		$url = $cvn_url;
-		break;
-	case 'no':
-		$url = $normal_url;
-		break;
-  }
 
-  $return_info = process_request($xmlstring,$url);
+  return $result;
+}
 
-  if (array_key_exists('txStatus',$return_info['eway_response'])) {
-	switch ($return_info['eway_response']['txStatus']) {
-		case 'false':
-			$message = t('Credit card declined: !amount', array('!amount' => uc_currency_format($amount)));
-			$result = array(
-				'success' => FALSE,
-				'comment' => t('Credit card payment declined') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
-				'message' => t('Credit card payment declined') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
-				'uid' => $user->uid,
-				'data' => $return_info['eway_response']
-			);
-			if (variable_get('test_approve_anyway', 'false') == 'true' && variable_get('eway_mode', 'test') == 'test') {
-				$result['success'] = TRUE;  	
-			}
-			drupal_set_message($result['message'],'error');
-			uc_order_comment_save($order_id,null,$result['comment'],'admin');
-			break;
-		case 'true':
-			$message = t('Credit card charged: !amount', array('!amount' => uc_currency_format($amount)));
-			$result = array(
-				'success' => TRUE,
-				'comment' => t('Credit card payment processed successfully') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
-				'message' => t('Credit card payment processed successfully') . ': ' . $return_info['eway_response']['txReturnNo'] . ': ' . $return_info['eway_response']['txReturnDescription'],
-				'uid' => $user->uid,
-				'data' => $return_info['eway_response']
-			);
-			// Leave a comment for the admin
-			uc_order_comment_save($order_id,null,$result['comment'],'admin');
-			// Leave a comment for the customer
-			uc_order_comment_save($order_id,null,$result['comment'],'order',null,true);
-			
-			break;
-	}
-	// Invoke a ca trigger to notify that the payment has been processed
-	ca_pull_trigger('uc_eway_payment_processed', $order);
+/**
+ * Actually send the request to eway.
+ */
+function uc_eway_process_request($xml, $url) {
+  $curl_connection = curl_init();
+  curl_setopt($curl_connection, CURLOPT_URL, $url);
+  curl_setopt($curl_connection, CURLOPT_VERBOSE, 1);
+  curl_setopt($curl_connection, CURLOPT_POST, 1);
+  curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $xml);
+  curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
+  curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, 0);
+  curl_setopt($curl_connection, CURLOPT_NOPROGRESS, 1);
+  curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION,0);
+
+  // Send the data out over the wire
+  $data = curl_exec($curl_connection);
+  if (curl_errno($curl_connection)) {
+    drupal_set_message(t('CURL Error') . ': ' . curl_errno($curl_connection) . '<br />' . curl_error($curl_connection));
+    return false;
+  } else {
+    curl_close($curl_connection);
+
+    $xtr = simplexml_load_string($data);
+    $response_details = explode(',',$xtr->ewayTrxnError);
+
+    $eway_response['txReturnNo'] = $response_details[0];
+    $eway_response['txReturnDescription'] = $response_details[1];
+    $eway_response['txStatus'] = strtolower($xtr->ewayTrxnStatus);
+    $eway_response['txTransactionNumber'] = $xtr->ewayTrxnNumber;
+    $eway_response['txOption1'] = $xtr->ewayTrxnOption1;
+    $eway_response['txOption2'] = $xtr->ewayTrxnOption2;
+    $eway_response['txOption3'] = $xtr->ewayTrxnOption3;
+    $eway_response['txAmount'] = $xtr->ewayReturnAmount;
+    $eway_response['txAuthCode'] = $xtr->ewayAuthCode;
+    $eway_response['txInvoiceReference'] = $xtr->ewayTrxnReference;
+
+    $return_array = array(
+      'curl_worked' => 'true',
+      'eway_response' => $eway_response
+    );
+
+    return $return_array;
   }
-
-  return $result;
 }
 
-  function process_request($xml,$url) {
-	$curl_connection = curl_init();
-	curl_setopt($curl_connection, CURLOPT_URL, $url);
-	curl_setopt($curl_connection, CURLOPT_VERBOSE, 1);
-	curl_setopt($curl_connection, CURLOPT_POST, 1);
-	curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $xml);
-	curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
-	curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, 0);
-	curl_setopt($curl_connection, CURLOPT_NOPROGRESS, 1);
-	curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION,0);
-		
-	// Send the data out over the wire
-	$data = curl_exec($curl_connection);        
-	if (curl_errno($curl_connection)) {
-		drupal_set_message(t('CURL Error') . ': ' . curl_errno($curl_connection) . '<br />' . curl_error($curl_connection));
-		return false;
-	} else {
-		curl_close($curl_connection);
-				
-		$xtr = simplexml_load_string($data);
-		$response_details = explode(',',$xtr->ewayTrxnError);
-		
-		$eway_response['txReturnNo'] = $response_details[0];
-		$eway_response['txReturnDescription'] = $response_details[1];
-		$eway_response['txStatus'] = strtolower($xtr->ewayTrxnStatus);
-		$eway_response['txTransactionNumber'] = $xtr->ewayTrxnNumber;
-		$eway_response['txOption1'] = $xtr->ewayTrxnOption1;
-		$eway_response['txOption2'] = $xtr->ewayTrxnOption2;
-		$eway_response['txOption3'] = $xtr->ewayTrxnOption3;
-        $eway_response['txAmount'] = $xtr->ewayReturnAmount; 
-        $eway_response['txAuthCode'] = $xtr->ewayAuthCode;
-        $eway_response['txInvoiceReference'] = $xtr->ewayTrxnReference;
-				
-		$return_array = array(
-			'curl_worked' => 'true',
-			'eway_response' => $eway_response
-		);
-		
-		return $return_array;
-	}
-  }
-	
Index: uc_eway.install
===================================================================
--- uc_eway.install	(revision 2459)
+++ uc_eway.install	(revision 2460)
@@ -2,17 +2,46 @@
 // $Id: uc_eway.install,v 1.2.2.1 2009/01/03 07:53:32 ssherriff Exp $
 
 /**
- * Implementation of hook_install().
+ * Implementation of hook_uninstall().
  */
-function uc_eway_install() {
+function uc_eway_uninstall() {
+  variable_del('uc_eway_customer_id');
+  variable_del('uc_eway_mode');
+  variable_del('uc_eway_change_order_status');
+  variable_del('uc_eway_logo');
+  variable_del('uc_eway_test_mode');
+  variable_del('uc_eway_test_approve_anyway');
+  variable_del('uc_pg_eway_cc_txn_type');
 }
 
-function uc_eway_uninstall() {
+/**
+ * Implementation of hook_update_N().
+ */
+function uc_eway_update_6100() {
+  $ret = array();
+
+  // Migrate eway_customer_id variable
+  variable_set('uc_eway_customer_id', variable_get('eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT));
   variable_del('eway_customer_id');
+
+  // Convert the mode and the cvn variables to the new mode and testing variables
+  if (variable_get('eway_mode', UC_EWAY_MODE_DEFAULT) == 'test') variable_set('uc_eway_test_mode', 1);
+  variable_set('uc_eway_mode', (variable_get('eway_cvn', 'yes') == 'yes') ? 'cvn_xml' : 'merchant_xml');
   variable_del('eway_mode');
-  variable_del('test_approve_anyway');
   variable_del('eway_cvn');
+
+  // Migrate the change_order_status variable
+  variable_set('uc_eway_change_order_status', variable_get('change_order_status', UC_EWAY_CHANGE_ORDER_STATUS_DEFAULT));
   variable_del('change_order_status');
+
+  // Migrate the eway_logo variable
+  variable_set('uc_eway_logo', variable_get('eway_logo', UC_EWAY_LOGO_DEFAULT));
   variable_del('eway_logo');
-  variable_del('uc_pg_eway_cc_txn_type');
+
+  // Migrate the test_approve_anyway variable
+  variable_set('uc_eway_test_approve_anyway', variable_get('test_approve_anyway', UC_EWAY_TEST_APPROVE_ANYWAY_DEFAULT));
+  variable_del('test_approve_anyway');
+
+  $ret[] = array('success' => True, 'query' => 'Updated variables to new variable definitions');
+  return $ret;
 }
Index: uc_eway.ca.inc
===================================================================
--- uc_eway.ca.inc	(revision 2459)
+++ uc_eway.ca.inc	(revision 2460)
@@ -33,13 +33,15 @@
  * Implementation of hook_ca_predicate().
  */
 function uc_eway_ca_predicate() {
-	watchdog('uc_eway', 'Testing change_order_status: @message', array('@message' => variable_get('change_order_status', 'true')), WATCHDOG_DEBUG);
+  if (variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT)) {
+    watchdog('uc_eway', 'Testing uc_eway_change_order_status: @message', array('@message' => variable_get('uc_eway_change_order_status', UC_EWAY_CHANGE_ORDER_STATUS_DEFAULT)), WATCHDOG_DEBUG);
+  }
   $predicates['uc_eway_payment_processed'] = array(
     '#title' => t('Successful payment via eWay'),
     '#trigger' => 'uc_eway_payment_processed',
     '#class' => 'uc_eway',
-    '#status' => variable_get('change_order_status', 1),
-	'#actions' => array(
+    '#status' => variable_get('uc_eway_change_order_status', UC_EWAY_CHANGE_ORDER_STATUS_DEFAULT),
+    '#actions' => array(
       array(
         '#name' => 'uc_order_action_update_status',
         '#title' => t('Update status of order'),
@@ -48,7 +50,7 @@
         ),
       ),
     ),
-	'#conditions' => array(
+    '#conditions' => array(
       '#operator' => 'AND',
       '#conditions' => array(
         array(
@@ -75,10 +77,10 @@
         ),
       ),
     ),
-	'#settings' => array(
+    '#settings' => array(
       'order_status' => 'payment_received',
     ),
   );
-  
+
   return $predicates;
-}
\ No newline at end of file
+}
