diff --git uc_realex/uc_realex_remote.module uc_realex/uc_realex_remote.module
index 1bb1e54..bdc3035 100644
--- uc_realex/uc_realex_remote.module
+++ uc_realex/uc_realex_remote.module
@@ -24,49 +24,110 @@ function uc_realex_remote_payment_gateway() {
  * Callback for Realex  payment method settings.
  */
 function uc_realex_remote_settings_form() {
-  $form['uc_realex_remote_merchant_id'] = array(
+  $form['uc_realex_remote_cctype_subaccounts'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use separate accounts for each card type'),
+    '#description' => t('Some configurations require different accounts to be used for different card types.'),
+    '#default_value' => variable_get('uc_realex_remote_cctype_subaccounts', FALSE),
+  );
+  if (module_exists('uc_multiprice')) {
+    $form['uc_realex_remote_multicurrency'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Use separate gateways for each language'),
+      '#description' => t('Some configurations require different currencies to be processed through separate Realex Remote gateways.'),
+      '#default_value' => variable_get('uc_realex_remote_multicurrency', FALSE),
+    );
+
+    // Default settings.
+    $form['uc_realex_remote_credentials'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Default settings'),
+      '#collapsible' => TRUE,
+    );
+    uc_realex_remote_credentials_form($form['uc_realex_remote_credentials']);
+
+    // Per currency settings.
+    $result = db_query("SELECT * FROM {uc_multiprice_currencies}");
+    while ($row = db_fetch_object($result)) {
+      $fieldset = 'uc_realex_remote_credentials_' . $row->country_id;
+      $form[$fieldset] = array(
+        '#type' => 'fieldset',
+        '#title' => t('@label settings', array('@label' => $row->currency_code)),
+        '#collapsible' => TRUE,
+        '#collapsed' => !variable_get('uc_realex_remote_multicurrency', FALSE),
+      );
+      uc_realex_remote_credentials_form($form[$fieldset], $row->country_id);
+    }
+  }
+  else {
+    uc_realex_remote_credentials_form($form);
+  }
+
+  //  Option to include Directy Currency Comversion [DCC]
+  $form['uc_realex_remote_dcc'] = array(
+    '#type' => 'select',
+    '#title' => t('Direct Currency Conversion [DCC]'),
+    '#options' => array(
+      'none' => 'None',
+      //'fintrax' => 'Fintrax', Not available yet
+      'fexco' => 'Fexco',
+      'euroConex' => 'Elavon'
+     ),
+    '#description' => t('Should DCC be available to the user - You must have this preconfigured on your Realex sub-account in advance.'),
+    '#default_value' => variable_get('uc_realex_remote_dcc', 'none'),
+  );
+
+  return $form;
+}
+
+function uc_realex_remote_credentials_form(&$form, $key = '') {
+  $key = empty($key) ? $key : '_' . $key;
+  $form['uc_realex_remote_merchant_id' . $key] = array(
     '#type' => 'textfield',
     '#title' => t('Realex Merchant ID'),
     '#description' => t('Your Realex merchant ID number.'),
-    '#default_value' => variable_get('uc_realex_remote_merchant_id', ''),
+    '#default_value' => variable_get('uc_realex_remote_merchant_id' . $key, ''),
     '#size' => 16,
   );
-  $form['uc_realex_remote_account'] = array(
+  $form['uc_realex_remote_account' . $key] = array(
     '#type' => 'textfield',
     '#title' => t('Realex Account'),
     '#description' => t('Your Realex account.'),
-    '#default_value' => variable_get('uc_realex_remote_account', 'internet'),
+    '#default_value' => variable_get('uc_realex_remote_account' . $key, 'internet'),
     '#size' => 16,
   );
-  $form['uc_realex_remote_shared_secret'] = array(
+  $form['uc_realex_remote_shared_secret' . $key] = array(
     '#type' => 'textfield',
     '#title' => t('Shared secret for order verification'),
     '#description' => t('Your Shared Secret as supplied by Realex.'),
-    '#default_value' => variable_get('uc_realex_remote_shared_secret', ''),
+    '#default_value' => variable_get('uc_realex_remote_shared_secret' . $key, ''),
     '#size' => 16,
   );
-  $form['uc_realex_remote_url'] = array(
+  $form['uc_realex_remote_url' . $key] = array(
     '#type' => 'textfield',
     '#title' => t('Realex Remote XML URL'),
     '#description' => t('The Realex URL to submit the order to.'),
-    '#default_value' => variable_get('uc_realex_remote_url', 'https://epage.payandshop.com/epage-remote.cgi'),
+    '#default_value' => variable_get('uc_realex_remote_url' . $key, 'https://epage.payandshop.com/epage-remote.cgi'),
     '#size' => 50,
   );
-  //  Option to include Directy Currency Comversion [DCC]
-  $form['uc_realex_remote_dcc'] = array(
-    '#type' => 'select',
-    '#title' => t('Direct Currency Conversion [DCC]'),
-    '#options' => array(
-      'none' => 'None',
-      //'fintrax' => 'Fintrax', Not available yet
-      'fexco' => 'Fexco',
-      'euroConex' => 'Elavon'
-     ),
-    '#description' => t('Should DCC be available to the user - You must have this preconfigured on your Realex sub-account in advance.'),
-    '#default_value' => variable_get('uc_realex_remote_dcc', 'none'),
+  $form['uc_realex_remote_cctype_accounts' . $key] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Realex Card Type Account Settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#attributes' => array('class' => 'realex-cctype-subaccounts'),
   );
-
-  return $form;
+  $cctypes = uc_credit_card_types();
+  $cctype_settings = variable_get("uc_realex_remote_cctype_accounts$key", array());
+  foreach ($cctypes as $cctype => $label) {
+    $form['uc_realex_remote_cctype_accounts' . $key][$cctype] = array(
+      '#type' => 'textfield',
+      '#title' => t('@cctype account', array('@cctype' => $label)),
+      '#default_value' => $cctype_settings[$cctype],
+      '#required' => FALSE,
+      '#parents' => array('uc_realex_remote_cctype_accounts' . $key, $cctype),
+    );
+  }
 }
 
 /* Code below is based on sample code provided by Realex
@@ -168,13 +229,12 @@ function uc_realex_remote_charge($order_id, $amount, $data) {
 
   // Realex takes the value in cent.
   $amount = ($order->order_total*100);
-  $currency = variable_get('uc_currency_code', 'EUR');
+  $currency = variable_get('uc_currency_code', 'EUR'); // Override later if using uc_multiprice module.
   $cardnumber = $order->payment_details['cc_number'];
   $cardname = $order->payment_details['cc_owner'];
   $cardtype = $order->payment_details['cc_type'];
-  // Change for Realex
-  $cardtype = (strtolower($cardtype) == 'mastercard' ? 'MC' : (strtolower($cardtype) == 'solo' || strtolower($cardtype) == 'maestro' ? 'SWITCH' : $cardtype));
-  //$expdate = "0104" 
+  $cctype = strtolower($cardtype);
+  $cardtype = ($cctype == 'mastercard' ? 'MC' : ($cctype == 'solo' || $cctype == 'maestro' ? 'SWITCH' : $cctype));
   $expdate =   str_pad($order->payment_details['cc_exp_month'], 2, '0', STR_PAD_LEFT) .
                        substr($order->payment_details['cc_exp_year'], 2, 2);
   $cvn = $order->payment_details['cc_cvv'];
@@ -185,23 +245,46 @@ function uc_realex_remote_charge($order_id, $amount, $data) {
   }
   $products = implode(',',$items);
 
-  // These values will be provided to you by realex Payments,
-  // Add them at the configuration screen
-
+  // Standard installation with no multicurrency settings, but these are also
+  // the defaults for unconfigured currencies.
+  // These values will be provided to you by realex Payments, if you have not already received them please contact us
   $merchantid = variable_get('uc_realex_remote_merchant_id', '');
   $secret = variable_get('uc_realex_remote_shared_secret', '');
   $account = variable_get('uc_realex_remote_account', 'internet');
+  if (variable_get('uc_realex_remote_cctype_subaccounts', FALSE)) {
+    $cardtype_accounts = variable_get('uc_realex_remote_cctype_accounts', array());
+    $account = (!empty($cardtype_accounts[$cctype]) ?  $cardtype_accounts[$cctype] : $account);
+  }
   $url =  variable_get('uc_realex_remote_url', 'https://epage.payandshop.com/epage-remote.cgi');
 
-  // Creates timestamp that is needed for XML request
 
+  // Override by currency if using the uc_multiprice module.
+  if (module_exists('uc_multiprice') && variable_get('uc_realex_remote_multicurrency', FALSE)) {
+    $country_id = uc_multiprice_country_id();
+    $currency = db_result(db_query("SELECT currency_code FROM {uc_multiprice_currencies} WHERE country_id = %d", $country_id));
+    $currency_merchantid = variable_get('uc_realex_remote_merchant_id_' .  $country_id, '');
+    // If this is empty, we use the defaults instead. Otherwise overwrite the settings.
+    if (!empty($currency_merchantid)) {
+      $merchantid = $currency_merchantid;
+      $secret = variable_get('uc_realex_remote_shared_secret_' . $country_id, '');
+      $account = variable_get('uc_realex_remote_account_' . $country_id, 'internet');
+      $url =  variable_get('uc_realex_remote_url_' . $country_id, 'https://epage.payandshop.com/epage-remote.cgi');
+      // Check if we have subaccounts configured by card type.
+      if (variable_get('uc_realex_remote_cctype_subaccounts', FALSE)) {
+        $cardtype_accounts = variable_get('uc_realex_remote_cctype_accounts_' . $country_id, array());
+        $account = (!empty($cardtype_accounts[$cctype]) ?  $cardtype_accounts[$cctype] : $account);
+      }
+    }
+  }
+
+  // Creates timestamp that is needed to make up orderid
   $timestamp = strftime("%Y%m%d%H%M%S");
   mt_srand((double)microtime()*1000000);
 
-  // You can use any alphanumeric combination for the orderid.
-  // Although each transaction must have a unique orderid.
+  // You can use any alphanumeric combination for the orderid.Although each transaction must have a unique orderid.
+  $orderid = $order->order_id .'-'.$timestamp."-".mt_rand(1, 999);
 
-   $orderid = $order->order_id;
+  //$orderid = $order->order_id;
   if($_SESSION['realex_failures']){
     $orderid = $orderid . '-' . $_SESSION['realex_failures'];
   }
@@ -248,14 +331,14 @@ function uc_realex_remote_charge($order_id, $amount, $data) {
     <chname>$cardname</chname> 
     <issueno>$issueno</issueno>
   </card>";
-  if($cvn){
+  if ($cvn) {
     $xml .="
      <cvn>
       <number>$cvn</number>
       <presind>1</presind>
     </cvn>";
   }
-  if($dcc_info){
+  if ($dcc_info) {
     $xml .="
       <dccinfo>
       <ccp>$dcc_provider</ccp>
@@ -288,7 +371,7 @@ function uc_realex_remote_charge($order_id, $amount, $data) {
   $response = curl_exec ($ch);     
   curl_close ($ch); 
 
-  //Tidy it up
+  // Tidy it up
   $response = eregi_replace ( "[[:space:]]+", " ", $response );
   $response = eregi_replace ( "[\n\r]", "", $response );
 
@@ -297,11 +380,6 @@ function uc_realex_remote_charge($order_id, $amount, $data) {
   $result = $my_response->record;
   $result['ubercart_order_id'] = substr($result['orderid'], 0, strpos($result['orderid'], '-'));
 
-  // -------------------------------------------------------------
-  //Replace these with the values you receive from Realex Payments.If you have not yet received these values please contact us.
-  $merchantid = variable_get('uc_realex_remote_merchant_id', '');
-  $secret = variable_get('uc_realex_remote_shared_secret', '');
-
   //---------------------------------------------------------------
   //Below is the code for creating the digital signature using the md5 algorithm. 
   //This digital siganture should correspond to the 
