diff --git uc_eway.install uc_eway.install
index 86ac7e3..eea7893 100644
--- uc_eway.install
+++ uc_eway.install
@@ -7,6 +7,36 @@
  */
 
 /**
+ * Implementation of hook_requirements().
+ */
+function uc_eway_requirements($phase) {
+  $t = get_t();
+
+  $has_curl = function_exists('curl_init');
+
+  $requirements['curl'] = array(
+    'title' => $t('cURL'),
+    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
+  );
+  if (!$has_curl) {
+    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
+    $requirements['curl']['description'] = $t("Eway requires the PHP <a href='!curl_url'>cURL</a> library.", array('!curl_url' => 'http://php.net/manual/en/curl.setup.php'));
+  }
+
+  $has_simplexml = function_exists('simplexml_load_string');
+  $requirements['simplexml'] = array(
+    'title' => $t('SimpleXML'),
+    'value' => $has_simplexml ? $t('Enabled') : $t('Not found'),
+  );
+  if (!$has_simplexml) {
+    $requirements['simplexml']['severity'] = REQUIREMENT_ERROR;
+    $requirements['simplexml']['description'] = $t("Eway requires the SimpleXML library.");
+  }
+
+  return $requirements;
+}
+
+/**
  * Implementation of hook_uninstall().
  */
 function uc_eway_uninstall() {
@@ -59,3 +89,16 @@ function uc_eway_update_6100() {
   $ret[] = array('success' => TRUE, 'query' => 'Updated variables to new variable definitions');
   return $ret;
 }
+
+/**
+ * Set the default recurring method to rebill for anyone upgrading
+ */
+function uc_eway_update_6200() {
+  $ret = array();
+  variable_set('uc_eway_recurring_method', 'eway_rebill');
+  $ret[] = update_sql("UPDATE {uc_recurring_users} SET fee_handler = 'eway_rebill' WHERE fee_handler = 'eway'");
+  $ret[] = array('success' => TRUE, 'query' => 'Set the default eway recurring method to rebill for anyone upgrading');
+
+  return $ret;
+}
+
diff --git uc_eway.module uc_eway.module
index 4555dba..58991f8 100755
--- uc_eway.module
+++ uc_eway.module
@@ -43,12 +43,14 @@ function uc_eway_init() {
 function uc_eway_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
     case 'uc_cart_checkout_form':
-      $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;
+      if (uc_credit_default_gateway() == 'eway') {
+        $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':
@@ -147,10 +149,10 @@ function uc_eway_payment_gateway() {
  */
 function uc_eway_order($op, &$arg1, $arg2) {
   switch($op) {
-    case 'update':
+    case 'submit':
       // In case an anonymous user purchases a recurring product, the eway rebill customer id must
       // be allocated to the user after the fact, when the user has an account.
-      if ($arg1->order_status == 'pending' && isset($arg1->data['eway_rebill_customer_id']) && $arg1->uid != 0) {
+      if (isset($arg1->data['eway_rebill_customer_id']) && $arg1->uid != 0) {
         $account = user_load(array('uid' => $arg1->uid));
         $account = user_save($account, array('eway_rebill_customer_id' => $arg1->data['eway_rebill_customer_id']));
 
@@ -199,7 +201,7 @@ function uc_eway_settings_form() {
       'cvn_xml' => t('CVN (XML)'),
       'beagle' => t('Beagle Anti-Fraud'),
     ),
-    '#default_value' => variable_get('uc_eway_mode', UC_EWAY_MODE_DEFAULT),
+    '#default_value' =>variable_get('uc_eway_mode', UC_EWAY_MODE_DEFAULT) ,
   );
   $form['eway_settings']['uc_eway_change_order_status'] = array(
     '#type' => 'select',
@@ -238,6 +240,15 @@ function uc_eway_settings_form() {
   );
   if (variable_get('uc_eway_recurring_enabled', UC_EWAY_RECURRING_ENABLED_DEFAULT)) {
     require_once('uc_eway.recurring.inc');
+    $form['eway_recurring']['uc_eway_recurring_method'] = array(
+      '#type' => 'select',
+      '#title' => t('Which method should be used for recurring payments'),
+      '#options' => array(
+        'eway_rebill' => t('Recurring payments/Rebill - recurring handled by eway.'), 
+        'eway_token' => t('Token payments - credit card details stored with eway and recurring managed by your site.'),
+      ),
+      '#default_value' => variable_get('uc_eway_recurring_method', 'eway_token'),
+    );
     $form['eway_recurring']['uc_eway_recurring_nusoap_path'] = array(
       '#type' => 'textfield',
       '#title' => t('NuSOAP path'),
@@ -285,16 +296,7 @@ function uc_eway_settings_form_validate($form_id, &$form_state) {
  * 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.'));
-    return array('success' => FALSE);
-  }
-  if (!function_exists('simplexml_load_string')) {
-    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;
+ global $user, $response;
   $order = uc_order_load($order_id);
 
   // Build a description to send to the payment gateway
@@ -325,8 +327,9 @@ function uc_eway_charge($order_id, $amount, $data) {
   $customer_address .= uc_get_zone_code($order->billing_zone) . ' ';
   $customer_address .= $customer_address_countrycode;
 
+  $cust_id = _uc_eway_get_data('customer_id');
   $xml_data = array(
-    'ewayCustomerID' => variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT),
+    'ewayCustomerID' => $cust_id,
     'ewayTotalAmount' => uc_currency_format($amount, FALSE, FALSE, ''),
     'ewayCustomerFirstName' => $order->billing_first_name,
     'ewayCustomerLastName' => $order->billing_last_name,
@@ -344,9 +347,9 @@ function uc_eway_charge($order_id, $amount, $data) {
     '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)) {
+   $eway_testing = variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT);
+  
+  switch (_uc_eway_get_data('uc_eway_mode')) {
     case 'merchant_xml':
       $url = ($eway_testing) ? 'https://www.eway.com.au/gateway/xmltest/testpage.asp' : 'https://www.eway.com.au/gateway/xmlpayment.asp';
       break;
@@ -362,7 +365,7 @@ function uc_eway_charge($order_id, $amount, $data) {
       $xml_data['ewayCustomerBillingCountry'] = $customer_address_countrycode;
       break;
   }
-
+  
   $xmlstring = '<ewaygateway>';
   foreach ($xml_data as $key => $value) {
     $xmlstring .= '<' . $key . '>' . htmlentities($value) . '</' . $key . '>';
@@ -370,7 +373,7 @@ function uc_eway_charge($order_id, $amount, $data) {
   $xmlstring .= '</ewaygateway>';
 
   $return_info = uc_eway_process_request($xmlstring, $url);
-
+    
   if (array_key_exists('txStatus',$return_info['eway_response'])) {
   switch ($return_info['eway_response']['txStatus']) {
     case 'false':
@@ -403,13 +406,13 @@ function uc_eway_charge($order_id, $amount, $data) {
       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);
+  
   }
-
   return $result;
 }
 
@@ -435,7 +438,6 @@ function uc_eway_process_request($xml, $url) {
   }
   else {
     curl_close($curl_connection);
-
     $xtr = simplexml_load_string($data);
     $response_details = explode(',', $xtr->ewayTrxnError);
 
@@ -459,4 +461,27 @@ function uc_eway_process_request($xml, $url) {
   }
 }
 
+/**
+ * Helper function to get data, do checking if it's in test mode
+ */
+function _uc_eway_get_data($key){
+  $eway_testing = variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT);
+  $return_val;
+  switch($key) {
+    case 'customer_id':
+      $return_val = $eway_testing ? UC_EWAY_CUSTOMER_ID_DEFAULT : variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT);
+      break;
+    case 'user_name':
+      $return_val = $eway_testing ? UC_EWAY_EMAIL_ADDRESS_DEFAULT : variable_get('uc_eway_email_address', UC_EWAY_EMAIL_ADDRESS_DEFAULT);
+      break;
+    case 'password':
+      $return_val = $eway_testing ? UC_EWAY_PASSWORD_DEFAULT : variable_get('uc_eway_password', UC_EWAY_PASSWORD_DEFAULT);
+      break;
+    case 'uc_eway_mode':
+      $return_val = $eway_testing ? UC_EWAY_MODE_DEFAULT : variable_get('uc_eway_mode', UC_EWAY_MODE_DEFAULT);
+      break;
+  }
+  return $return_val;
+}
+
 
diff --git uc_eway.pages.inc uc_eway.pages.inc
new file mode 100644
index 0000000..e158c7d
--- /dev/null
+++ uc_eway.pages.inc
@@ -0,0 +1,47 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Includes page callbacks for user specific recurring fee operation pages.
+ */
+
+// Displays a form for customers to update their CC info.
+function uc_eway_token_update_form($form_state, $rfid) {
+  $form['rfid'] = array(
+    '#type' => 'value',
+    '#value' => $rfid,
+  );
+  $form['cc_data'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Credit card details'),
+    '#theme' => 'uc_payment_method_credit_form',
+    '#tree' => TRUE,
+  );
+  $form['cc_data'] += uc_payment_method_credit_form(array(), $order);
+  unset($form['cc_data']['cc_policy']);
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update'),
+    '#suffix' => l(t('Cancel'), 'user/'. $user->uid),
+  );
+  return $form;
+}
+
+function uc_eway_token_update_form_submit($form, &$form_state) {
+  $fee = uc_recurring_fee_user_load($form_state['values']['rfid']);
+  $order = uc_order_load($fee->order_id);
+  $order->payment_details = $form_state['values']['cc_data'];
+
+  $result = uc_eway_token_update($order, $fee);
+
+  // If the update was successful...
+  if ($result) {
+    drupal_set_message(t('The payment details for that recurring fee have been updated.'));
+  }
+  else {
+    drupal_set_message(t('An error has occurred while updating your payment details. Please try again and contact us if you are unable to perform the update.'), 'error');
+  }
+}
+
diff --git uc_eway.recurring.inc uc_eway.recurring.inc
index e1f2c57..cc0f223 100644
--- uc_eway.recurring.inc
+++ uc_eway.recurring.inc
@@ -22,18 +22,42 @@ define('UC_EWAY_RECURRING_VAST_END_DATE', date_format(date_create('+5 years'), '
  * Implementation of hook_recurring_info().
  */
 function uc_eway_recurring_info() {
-  $items['eway'] = array(
+  // eway rebill feature.
+  $items['eway_rebill'] = array(
     'title' => t('Eway Payment Gateway'),
     'module' => 'uc_eway',
-    'fee handler' => 'eway',
+    'fee handler' => 'eway_rebill',
     'payment method' => 'credit',
     'process callback' => 'uc_eway_recurring_process',
-    'renew callback' => 'uc_recurring_eway_renew',
+    'renew callback' => 'uc_eway_recurring_renew',
     'cancel callback' => '_uc_eway_recurring_delete_rebill_event',
     'menu' => array(
       'cancel' => UC_RECURRING_MENU_DEFAULT,
     ),
   );
+  // eways token payments feature.
+  $items['eway_token'] = array(
+    'title' => t('Eway Payment Gateway'),
+    'module' => 'uc_eway',
+    'fee handler' => 'eway_token',
+    'payment method' => 'credit',
+    'process callback' => 'uc_eway_token_process',
+    'renew callback' => 'uc_eway_token_renew',
+    'cancel callback' => 'uc_eway_token_cancel',
+    'menu' => array(
+      'charge' => UC_RECURRING_MENU_DEFAULT,
+      'edit'   => UC_RECURRING_MENU_DEFAULT,
+      'update' => array(
+        'title' => 'Update Account Details', 
+        'page arguments' => array('uc_eway_token_update_form'),
+        'file' => 'uc_eway.pages.inc',
+      ),
+      'cancel' => UC_RECURRING_MENU_DEFAULT,
+
+    ),
+  );
+  // The recurring module will be looking for a eway item, so we redirect to the user select method.
+  $items['eway'] = $items[variable_get('uc_eway_recurring_method', 'eway_token')];
   return $items;
 }
 
@@ -41,32 +65,36 @@ function uc_eway_recurring_info() {
  * Implements callback uc_recurring_[payment_method]_fee()
  */
 function uc_eway_recurring_process($order, &$fee) {
+  $fee->fee_handler = 'eway_rebill';
   $account = user_load(array('uid' => $order->uid));
 
   // is this user already a rebill customer?
   if (!$account->eway_rebill_customer_id) {
     watchdog('uc_eway_recurring', 'Creating new Rebill CustomerID for user %uid.', array('%uid' => $account->uid));
-    $account = _uc_eway_recurring_create_rebill_customer($order);
+    $rebill_cust_id = _uc_eway_recurring_create_rebill_customer($order);
+    $order->data['eway_rebill_customer_id'] = $rebill_cust_id;
+    //$account = _uc_eway_recurring_create_rebill_customer($order);
   }
   else {
-    watchdog('uc_eway_recurring', 'Using existing Rebill CustomerID (%customer_id) for user %uid.', array('%customer_id', $account->eway_rebill_customer_id, '%uid' => $user->uid));
+    $rebill_cust_id = $account->eway_rebill_customer_id;
+    watchdog('uc_eway_recurring', 'Using existing Rebill CustomerID (%customer_id) for user %uid.', array('%customer_id' => $account->eway_rebill_customer_id, '%uid' => $user->uid));
   }
 
   // how about now?
-  if (!$account->eway_rebill_customer_id) {
+  if (!$rebill_cust_id) {
     watchdog('uc_eway', 'Failed to create Rebill Customer');
     return FALSE;
   }
 
   // create a rebill event
-  $result = _uc_eway_recurring_create_rebill_event($order, $fee, $account);
+  $result = _uc_eway_recurring_create_rebill_event($order, $fee, $rebill_cust_id);
 
   if ($result['error']) {
     watchdog('uc_eway_recurring', 'Failed to create Rebill Event: %error', array('%error' => $result['ErrorDetails']));
     return FALSE;
   }
   else {
-    watchdog('uc_eway_recurring', 'Created Rebill Event: %rid', array('%rid', $result['RebillID']));
+    watchdog('uc_eway_recurring', 'Created Rebill Event: %rid', array('%rid' => $result['RebillID']));
     $fee->data['rebill_id'] = $result['RebillID'];
     return TRUE;
   }
@@ -75,7 +103,7 @@ function uc_eway_recurring_process($order, &$fee) {
 /**
  * Implements callback uc_recurring_[fee_handler]_renew()
  */
-function uc_recurring_eway_renew($order, $fee) {
+function uc_eway_recurring_renew($order, $fee) {
   $account = user_load(array('uid' => $order->uid));
 
   $result = _uc_eway_recurring_query_rebill_transactions($fee, $account);
@@ -84,7 +112,18 @@ function uc_recurring_eway_renew($order, $fee) {
   // get all transactions, test if this fee went through
   if (count($result['Successful']['QueryTransactionsResult'])) {
     watchdog('uc_eway_recurring', 'Renew charged for fee: %fee, Transaction status is SUCCESSFUL: %result', array('%fee' => var_export($fee, TRUE), '%result' => var_export($result['Successful'], TRUE)));
-    return TRUE;
+    // create new rebill event for infinite interval (-1)
+    if($fee->remaining_intervals < 0){
+      $return = _uc_eway_recurring_create_rebill_event($order, $fee, $order->uid);
+      if($return['error'] == 0){
+        watchdog('uc_eway_recurring', 'CreateRebillEvent for infinite interval succeded, Response: %response', array('%response' => var_export($return, TRUE)));
+        return TRUE;
+      }else{
+        watchdog('uc_eway_recurring', 'CreateRebillEvent for infinite interval failed, Response : %response', array('%response' => var_export($return, TRUE)));
+        return FALSE;
+      }
+    }
+    else return TRUE;
   }
   else if (count($result['Failed']['QueryTransactionsResult'])) {
     watchdog('uc_eway_recurring', 'Renew failed for fee: %fee, Transaction status is FAILED: %result', array('%fee' => var_export($fee, TRUE), '%result' => var_export($result['Failed'], TRUE)));
@@ -139,18 +178,36 @@ function uc_eway_recurring_nusoap_path() {
 }
 
 /**
+ * Gets the soap url for Rebill API.
+ */
+function uc_eway_rebill_soap_url() {
+  return variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT) ? 'https://www.eway.com.au/gateway/rebill/test/manageRebill_test.asmx?WSDL' : 'https://www.eway.com.au/gateway/rebill/manageRebill.asmx?WSDL';
+}
+
+/**
+ * Gets the soap url for Token Payments API.
+ */
+function uc_eway_token_soap_url() {
+  return variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT) ? 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx?WSDL' : 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
+}
+
+/**
  * The actual SOAP call using the NuSOAP library
  */
-function _uc_eway_recurring_soap_call($operation, $params) {
-  $endpoint = variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT) ? 'https://www.eway.com.au/gateway/rebill/test/manageRebill_test.asmx?WSDL' : 'https://www.eway.com.au/gateway/rebill/manageRebill.asmx?WSDL';
-  $namespace = 'http://www.eway.com.au/gateway/rebill/manageRebill';
-  $header = '<eWAYHeader xmlns="http://www.eway.com.au/gateway/rebill/manageRebill"> 
-    <eWAYCustomerID>' . variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT) . '</eWAYCustomerID> 
-    <Username>' . variable_get('uc_eway_email_address', UC_EWAY_EMAIL_ADDRESS_DEFAULT)  . '</Username> 
-    <Password>' . variable_get('uc_eway_password', UC_EWAY_PASSWORD_DEFAULT)  . '</Password> 
+function _uc_eway_recurring_soap_call($operation, $params, $endpoint = NULL, $namespace = NULL) {
+  if (!isset($namespace)) {
+    $namespace = 'http://www.eway.com.au/gateway/rebill/manageRebill';
+  }
+  $header = '<eWAYHeader xmlns="'. $namespace .'"> 
+      <eWAYCustomerID>' . _uc_eway_get_data('customer_id') . '</eWAYCustomerID> 
+      <Username>' . _uc_eway_get_data('user_name')  . '</Username> 
+      <Password>' . _uc_eway_get_data('password')  . '</Password> 
     </eWAYHeader>'; // TODO: replace with soapval
 
   if (@include_once(realpath(uc_eway_recurring_nusoap_path()))) {
+    if (!isset($endpoint)) {
+      $endpoint = uc_eway_rebill_soap_url();
+    }
     $client = new nusoap_client($endpoint, TRUE);
     $client->response_timeout = 50;
     $result = $client->call($operation, $params, $namespace, '', $header);
@@ -159,10 +216,12 @@ function _uc_eway_recurring_soap_call($operation, $params) {
     $result = FALSE;
   }
 
-  //if (variable_get('uc_eway_test_mode', UC_EWAY_TEST_MODE_DEFAULT)) {
-    watchdog('uc_eway_recurring', 'SOAP Call (%operation) request: %request, response: %response', array('%operation' => $operation, '%request' => var_export($params, TRUE), '%response' => var_export($result, TRUE)));
-  //  watchdog('uc_eway_recurring', 'NuSOAP client: %client', array('%client' => var_export($client, TRUE)));
-  //}
+  foreach ($params as $id => $key) {
+    if (in_array($id, array('RebillCCNumber', 'CCNumber'))) {
+      $params[$id] = '**** **** **** ****'; // Don't log the CC number in plan text.
+    }
+  } 
+  watchdog('uc_eway_recurring', 'SOAP Call (%operation) request: %request, response: %response', array('%operation' => $operation, '%request' => var_export($params, TRUE), '%response' => var_export($result, TRUE)));
 
   return $result;
 }
@@ -199,12 +258,13 @@ function _time($type = 'none') {
  * Create Rebill Customer
  */
 function _uc_eway_recurring_create_rebill_customer($order) {
-  $account = user_load(array('uid' => $order->uid));
+  //$account = user_load(array('uid' => $order->uid));
 
   $country = uc_get_country_data(array('country_id' => $order->billing_country));
-
+  
+  $cust_id = _uc_eway_get_data('customer_id');
   $data = array(
-    'ewayCustomerID' => variable_get('uc_eway_customer_id', UC_EWAY_CUSTOMER_ID_DEFAULT),
+    'ewayCustomerID' => $cust_id,
     'customerTitle' => '',
     'customerFirstName' => (string) $order->billing_first_name,
     'customerLastName' => (string) $order->billing_last_name,
@@ -226,12 +286,10 @@ function _uc_eway_recurring_create_rebill_customer($order) {
 
   $response = _uc_eway_recurring_soap_call('CreateRebillCustomer', $data);
   if ($response['CreateRebillCustomerResult']['Result'] == 'Success') {
-    $account = user_save($account, array(
-      'eway_rebill_customer_id' => $response['CreateRebillCustomerResult']['RebillCustomerID'],
-    ));
+    return $response['CreateRebillCustomerResult']['RebillCustomerID'];
   }
 
-  return $account;
+  return FALSE;
 }
 
 /**
@@ -255,7 +313,7 @@ function _uc_eway_recurring_delete_rebill_customer() {
 /**
  * Create Rebill Event
  */
-function _uc_eway_recurring_create_rebill_event($order, $fee, $account) {
+function _uc_eway_recurring_create_rebill_event($order, $fee, $rebill_cust_id) {
   // create invoice description
   $description = '';
   if (is_array($order->products)) {
@@ -283,17 +341,20 @@ function _uc_eway_recurring_create_rebill_event($order, $fee, $account) {
     case 'months': $interval_type = 3; break;
     case 'years': $interval_type = 4; break;
   }
-  if ($fee->remaining_intervals) {
+  
+  if ($fee->remaining_intervals > 0) {
     // End date has to be calculated from the start date, not the date of purchase, so:
     // +1 regular interval to get to the start date then + (regular interval * remaining intervals to get the number rebills)
     $end_date = date('d/m/Y', strtotime('+' . ($regular_interval[0] + ($regular_interval[0] * $fee->remaining_intervals)) . ' ' . $regular_interval[1]));
   }
   else {
-    $end_date = UC_EWAY_RECURRING_VAST_END_DATE;
+    // If remaining intervals is -1 (infinite)
+    $end_date = date('d/m/Y', strtotime('+' . ($regular_interval[0] * 2). ' ' . $regular_interval[1]));
+    //$end_date = UC_EWAY_RECURRING_VAST_END_DATE;
   }
-
+  
   $data = array(
-    'RebillCustomerID' => $account->eway_rebill_customer_id,
+    'RebillCustomerID' => $rebill_cust_id,
     'RebillInvRef' => $order->order_id,
     'RebillInvDes' => substr($description, 0, 10000),
     'RebillCCName' => $cc_name,
@@ -389,3 +450,212 @@ function _uc_eway_recurring_query_rebill_transactions($fee, $account) {
 
   return $response;
 }
+
+/**
+ * Implemenation of hook_recurring_renew()
+ *
+ * Use a triggered reference in securepay to charge to an account.
+ */
+function uc_eway_token_renew($order, $fee) {
+
+  $data = array(
+    'managedCustomerID' => $fee->data['ManagedCustomerID'], // Test ID: 9876543211000
+    'amount' => $fee->fee_amount*100,
+    'invoiceReference' => $order->order_id,
+    'invoiceDescription' => 'Renewal',
+  );
+
+  $response = _uc_eway_recurring_soap_call('ProcessPayment', $data, uc_eway_token_soap_url(), 'https://www.eway.com.au/gateway/managedpayment');
+
+  if ($response['ewayResponse']['ewayTrxnStatus'] != 'True') { 
+    $result = array(
+      'success' => FALSE,
+      'message' => t('Credit card payment declined: @message', 
+                      array('@message' => $response['ewayTrxnError'])),
+      'uid' => $user->uid,
+    );
+
+    return FALSE;
+  }
+  // Transaction succeeded.
+  else {
+    // Build a message for display and comments in the payments table.
+    $message = t('!amount recurring fee collected for @model. (ID: <a href="!url">!fee</a>)', 
+                  array('!url' => url('admin/store/orders/recurring/view/fee/'. $fee->rfid), 
+                        '!fee' => $fee->rfid, 
+                        '!amount' => uc_currency_format($fee->fee_amount), 
+                        '@model' => $fee->data['ManagedCustomerID']));
+    $result = array(
+      'success' => TRUE,
+      'comment' => $message,
+      'message' => $message,
+      'data' => array('module' => 'uc_eway', 
+                      'txn_type' => $response['RequestType'], 
+                      'action' => $response['actionType'],
+                      'subscription_id' => $response['clientID']),
+      'uid' => $user->uid,
+    );
+
+    // enter the payment.
+    uc_payment_enter($order->order_id, 'credit', $response['amount']/100, 0, $result['data'], $message);
+
+    uc_order_comment_save($order->order_id, 0, $message);
+  }
+
+  // Build an admin order comment.
+  $comment = t('<b>@type</b><br /><b>@status:</b> @message<br />Amount: @amount<br/>Transaction #: @tranaction',
+    array('@type' => $response['RequestType'] .' '. $response['actionType'] .' '. $response['clientID'], 
+          '@status' => $result['success'] ? t('ACCEPTED') : t('REJECTED'), 
+          '@message' => $response['ewayTrxnError'], 
+          '@amount' => uc_currency_format($response['amount']/100),
+          '@transaction' => $response['ewayTrxnNumber'],
+         ));
+
+  // Save the comment to the order.
+  uc_order_comment_save($order->order_id, $user->uid, $comment, 'admin');
+
+  return TRUE;
+}
+
+/**
+ * Callback for setting up a recurring fee.
+ *
+ * Create a triggered payment in securepay using an order's data.
+ *
+ * This is where we will send a message to setup the user CC details in securepay
+ *
+ * @param $order
+ *   The order object containing billing and shipping information.
+ * @param $fee
+ *   An array of data describing the recurring fee.
+ * @return
+ *   TRUE or FALSE indicating the success of the request.
+ */
+function uc_eway_token_process($order, &$fee) {
+  $fee->fee_handler = 'eway_token';
+
+  $country = uc_get_country_data(array('country_id' => $order->billing_country));
+  $data = array(
+    'Title' => 'Mr.',
+    'FirstName' => (string) $order->billing_first_name,
+    'LastName' => (string) $order->billing_last_name,
+    'Address' => (string) $order->billing_street1 . ' ' . $order->billing_street2,
+    'Suburb' => (string) $order->billing_city,
+    'State' => (string) uc_get_zone_code($order->billing_zone),
+    'Company' => (string) $order->billing_company,
+    'PostCode' => (string) $order->billing_postal_code,
+    'Country' => 'au', // (string) $country[0]['country_name'], // This needs to be a 2 digit country code
+    'Email' => (string) $order->primary_email,
+    'Fax' => '',
+    'Phone' => '',
+    'Mobile' => '',
+    'CustomerRef' => $order->uid,
+    'JobDesc' => '',
+    'Comments' => '',
+    'URL' => '',
+    'CCNumber' => $order->payment_details['cc_number'],
+    'CCNameOnCard' => $order->billing_first_name . ' '. $order->billing_last_name,
+    'CCExpiryMonth' => sprintf('%02d', $order->payment_details['cc_exp_month']),
+    'CCExpiryYear' => substr($order->payment_details['cc_exp_year'], -2),
+  );
+
+  $response = _uc_eway_recurring_soap_call('CreateCustomer', $data, uc_eway_token_soap_url(), 'https://www.eway.com.au/gateway/managedpayment');
+
+  if (empty($response['CreateCustomerResult'])) {
+    uc_order_comment_save($order->order_id, 0, 
+      t('Eway: Recurring fee setup for @model failed.<br />@error - @text', 
+         array('@model' => $fee->model, 
+               '@error' => $response['responseCode'], 
+               '@text' => $response['responseText'])
+      ), 
+      'admin'
+    );
+    return FALSE;
+
+  }
+  $fee->data['ManagedCustomerID'] = $response['CreateCustomerResult'];
+  uc_order_comment_save($order->order_id, 0, 
+    t('Eway: Recurring fee setup.<br />ManagedCustomerID: @subscription_id', 
+       array('@model' => $fee->model, 
+             '@subscription_id' => $response['CreateCustomerResult'])
+    ), 
+    'admin'
+  );
+
+  return TRUE;
+}
+
+/**
+ * Updates a subscription 
+ *
+ * @param $order
+ *   An ubercart order object
+ * @param $fee
+ *   Recurring fee object
+ * @return
+ *   TRUE or FALSE indicating the success of the cancellation.
+ */
+function uc_eway_token_update($order, $fee) {
+  $data = array(
+    'managedCustomerID' => $fee->data['ManagedCustomerID'], // Test ID: 9876543211000
+    'Title' => 'Mr.',
+    'FirstName' => (string) $order->billing_first_name,
+    'LastName' => (string) $order->billing_last_name,
+    'Address' => (string) $order->billing_street1 . ' ' . $order->billing_street2,
+    'Suburb' => (string) $order->billing_city,
+    'State' => (string) uc_get_zone_code($order->billing_zone),
+    'Company' => (string) $order->billing_company,
+    'PostCode' => (string) $order->billing_postal_code,
+    'Country' => 'au', // (string) $country[0]['country_name'], // This needs to be a 2 digit country code
+    'Email' => (string) $order->primary_email,
+    'Fax' => '',
+    'Phone' => '',
+    'Mobile' => '',
+    'CustomerRef' => $order->uid,
+    'JobDesc' => '',
+    'Comments' => '',
+    'URL' => '',
+    'CCNumber' => $order->payment_details['cc_number'],
+    'CCNameOnCard' => $order->billing_first_name . ' '. $order->billing_last_name,
+    'CCExpiryMonth' => sprintf('%02d', $order->payment_details['cc_exp_month']),
+    'CCExpiryYear' => substr($order->payment_details['cc_exp_year'], -2),
+  );
+
+  $response = _uc_eway_recurring_soap_call('UpdateCustomer', $data, uc_eway_token_soap_url(), 'https://www.eway.com.au/gateway/managedpayment');
+
+  if ($response['UpdateCustomerResult'] != 'true') {
+    if (!empty($fee->order_id)) {
+      uc_order_comment_save($fee->order_id, 0, 
+        t('eway: Subscription @subscription_id updated failed.', 
+           array('@subscription_id' => $fee->data['ManagedCustomerID'])
+        ), 
+        'admin'
+      );
+    }
+    return FALSE;
+  }
+
+  uc_order_comment_save($fee->order_id, 0, 
+    t('eway: Subscription @subscription_id updated.', 
+       array('@subscription_id' => $fee->data['ManagedCustomerID'])
+    ),
+    'admin'
+  );
+
+  return TRUE;
+}
+
+/**
+ * Cancels an recurring subscription.
+ *
+ * @param $order_id
+ *   The ID of the order the recurring fee was attached to.
+ * @param $fee
+ *   The data array for the recurring fee being canceled.
+ * @return
+ *   TRUE or FALSE indicating the success of the cancellation.
+ */
+function uc_eway_token_cancel($fee) {
+  return TRUE;
+}
+
