Index: uc_realex.module
===================================================================
--- uc_realex.module	(revision 778)
+++ uc_realex.module	(working copy)
@@ -56,67 +56,81 @@
   if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
     $order = uc_order_load($order_id);
     if ($order->payment_method == 'uc_realex') {
-      $country = uc_get_country_data(array('country_id' => $order->billing_country));
-      if ($country === FALSE) {
-        $country = array(0 => array('country_iso_code_3' => 'USA'));
-      }
+      unset($form['submit']);
+      $form['#prefix'] = '<table style="display: inline; padding-top: 1em;"><tr><td>';
+      $form['#suffix'] = '</td><td>' . drupal_get_form('uc_realex_form', $order) . '</td></tr></table>';
+    }
+  }
+}
 
-      //Replace these with the values you receive from Realex Payments
-      // This is done at the configuration page.
-      $merchantid = variable_get('uc_realex_merchant_id', '');
-      $secret = variable_get('uc_realex_shared_secret', '');
+/**
+ * Prepare and return the form to POST to Realex.
+ */
+function uc_realex_form($form_state, $order) {
+  $form = array();
 
-      //The code below is used to create the timestamp format required by Realex Payments
-      $timestamp = strftime("%Y%m%d%H%M%S");
-      mt_srand((double)microtime() * 1000000);
+  $country = uc_get_country_data(array('country_id' => $order->billing_country));
+  if ($country === FALSE) {
+    $country = array(0 => array('country_iso_code_3' => 'USA'));
+  }
 
-      // 	orderid: Replace this with the order id you want to use.The order id must be	unique.
-      $orderid = $order->order_id;
-      $curr = "EUR";
-      // Realex takes the value in cent.
-      $amount = ($order->order_total * 100);
+  // Replace these with the values you receive from Realex Payments
+  // This is done at the configuration page.
+  $merchantid = variable_get('uc_realex_merchant_id', '');
+  $secret = variable_get('uc_realex_shared_secret', '');
 
-      /*-----------------------------------------------
-	Below is the code for creating the digital signature using the MD5 algorithm
-	provided by PHP. you can use the SHA1 algorithm alternatively.
-	*/
+  // The code below is used to create the timestamp format required by Realex Payments
+  $timestamp = strftime("%Y%m%d%H%M%S");
+  mt_srand((double)microtime() * 1000000);
 
-      $tmp      = "$timestamp.$merchantid.$orderid.$amount.$curr";
-      $sha1hash = sha1($tmp);
-      $tmp      = "$sha1hash.$secret";
-      $sha1hash = sha1($tmp);
+  // orderid: Replace this with the order id you want to use.The order id must be  unique.
+  $orderid = $order->order_id;
+  $curr = "EUR";
+  // Realex takes the value in cent.
+  $amount = ($order->order_total * 100);
 
+  /*-----------------------------------------------
+  Below is the code for creating the digital signature using the MD5 algorithm
+  provided by PHP. you can use the SHA1 algorithm alternatively.
+  */
 
-      foreach ($order->products as $product) {
-        $items[] = $product->nid;
-      }
-      $products = implode(',', $items);
+  $tmp      = "$timestamp.$merchantid.$orderid.$amount.$curr";
+  $sha1hash = sha1($tmp);
+  $tmp      = "$sha1hash.$secret";
+  $sha1hash = sha1($tmp);
 
-      $data = array(
-        'MERCHANT_ID' => $merchantid,
-        'ORDER_ID' => $order->order_id,
-        'CURRENCY' => $curr,
-        'AMOUNT' => $amount,
-        'TIMESTAMP' => $timestamp,
-        'SHA1HASH' => $sha1hash,
-        'AUTO_SETTLE_FLAG' => 1,
-        'CUST_NUM' => $order->uid,
-        'PROD_ID' => $products,
-        'VAR_REF' => check_plain($order->primary_email),
-        'uc_cart_id' => uc_cart_get_id(),
-      );
 
-      foreach ($data as $name => $value) {
-        $form[$name] = array('#type' => 'hidden', '#value' => $value);
-      }
-      $form['submit'] = array(
-        '#type' => 'submit',
-        '#name' => '',
-        '#value' => variable_get('uc_worldpay_checkout_button', t('Submit Order')),
-      );
-    }
-    $form['#action'] = variable_get('uc_realex_url', 'https://epage.payandshop.com/epage.cgi');
+  foreach ($order->products as $product) {
+    $items[] = $product->nid;
   }
+  $products = implode(',', $items);
+
+  $data = array(
+    'MERCHANT_ID' => $merchantid,
+    'ORDER_ID' => $order->order_id,
+    'CURRENCY' => $curr,
+    'AMOUNT' => $amount,
+    'TIMESTAMP' => $timestamp,
+    'SHA1HASH' => $sha1hash,
+    'AUTO_SETTLE_FLAG' => 1,
+    'CUST_NUM' => $order->uid,
+    'PROD_ID' => $products,
+    'VAR_REF' => check_plain($order->primary_email),
+    'uc_cart_id' => uc_cart_get_id(),
+  );
+
+  foreach ($data as $name => $value) {
+    $form[$name] = array('#type' => 'hidden', '#value' => $value);
+  }
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#name' => '',
+    '#value' => variable_get('uc_worldpay_checkout_button', t('Submit Order')),
+  );
+
+  $form['#action'] = variable_get('uc_realex_url', 'https://epage.payandshop.com/epage.cgi');
+
+  return $form;
 }
 
 /**
