diff --git a/uc_epdq.info b/uc_epdq.info
old mode 100644
new mode 100755
index efd515a..888e591
--- a/uc_epdq.info
+++ b/uc_epdq.info
@@ -1,7 +1,4 @@
 name = BarclayCard EPDQ payment gateway
 description = Integrate BarclayCard EPDQ payment gateway.
 dependencies[] = uc_payment
-package = "Ubercart - payment"
-core = "6.x"
-
-
+package = "Ubercart - payment"core = "7.x"
diff --git a/uc_epdq.install b/uc_epdq.install
old mode 100644
new mode 100755
index 95afbb9..cbebc44
--- a/uc_epdq.install
+++ b/uc_epdq.install
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Implementation of hook_uninstall().
  */
@@ -11,29 +10,18 @@ function uc_epdq_schema() {
         'type' => 'int',
         'not null' => TRUE,
         'description' => 'Primary Key: Order ID.',
-      ),
-      'transactionstatus' => array(
+       ),
+      'transaction_status' => array(
         'type' => 'text',
         'not null' => TRUE,
         'description' => 'The transaction status message from EPDQ.',
-      ),      
-    
+      ),
     )
   );
- return $schema;
+  return $schema;
 }
 
-function uc_epdq_install() {
-  // Create tables.
-  drupal_install_schema('uc_epdq');
-  drupal_set_message(t('The Barlays EPDQ tables installed successfully'));
-  
-}
-
-
 function uc_epdq_uninstall() {
   // Remove tables.
   drupal_uninstall_schema('uc_epdq');
-  
 }
-  
\ No newline at end of file
diff --git a/uc_epdq.module b/uc_epdq.module
old mode 100644
new mode 100755
index 8d639e7..56ca1da
--- a/uc_epdq.module
+++ b/uc_epdq.module
@@ -1,10 +1,10 @@
 <?php
-
 /**
  * @file
  * Integrates the epdq redirected payment service.
  *
- * Developed by crooke 
+ * Developed by crooke
+ * ported to Drupal 7 by Joe Corall <joe.corall@gmail.com>
  * Under GNU license
  */
 
@@ -65,7 +65,7 @@ function uc_epdq_form_alter(&$form, &$form_state, $form_id) {
  */
 function uc_epdq_payment_method() {
   $path = base_path() . drupal_get_path('module', 'uc_payment');
-  $title = t('Credit card on a secure server'); 
+  $title = variable_get('uc_epdq_method_title', '');
   $methods[] = array(
     'id' => 'epdq',
     'name' => t('Barclays EPDQ'),
@@ -92,7 +92,7 @@ function uc_epdq_payment_method() {
 function uc_payment_method_epdq($op, &$arg1) {
   switch ($op) {
     case 'cart-details':
-      $details = t('The transaction is totally secured on our bank server');
+      $details = variable_get('uc_epdq_method_description', '');
       return $details;
 
     case 'cart-process':
@@ -166,22 +166,20 @@ function uc_epdq_form($form_state,$order) {
   $country = uc_get_country_data(array('country_id' => $order->{$address .'_country'}));
   if ($country === FALSE) {
     $country = array(0 => array('country_iso_code_2' => 'UK'));
-	
   }
       
-  $data['epdqdata'] = str_replace('<INPUT name=epdqdata type=hidden value="', '' ,uc_epdq_encrypt($order));
-  $data['epdqdata'] = str_replace('">', '', $data['epdqdata']);
+  $data['epdqdata'] = str_replace('', '', $data['epdqdata']);
   $data['cpi_logo'] = 'secure_JPEG/GIF/PNG_URL';
   $data['returnurl'] = variable_get('uc_epdq_returnurl', '');
   $data['merchantdisplayname'] = variable_get('uc_epdq_merchantdisplayname', '');
-  $data['baddr1'] = $order->delivery_street1;
-  $data['baddr2'] = $order->delivery_street2;
-  $data['bfullname'] = $order->delivery_first_name .' '. $order->delivery_last_name;
-  $data['bcity'] = $order->delivery_city;
-  $data['bpostalcode'] = $order->delivery_postal_code;
-  $data['bcountry'] = $country[0]['country_iso_code_2'];
-  $data['btelephonenumber'] = $order->delivery_phone;
-  $data['email'] = $order->primary_email;     
+  $data['baddr1'] = $order->billing_street1;
+  $data['baddr2'] = $order->billing_street2;
+  $data['bfullname'] = $order->billing_first_name .' '. $order->billing_last_name;
+  $data['bcity'] = $order->billing_city;
+  $data['bpostalcode'] = $order->billing_postal_code;
+  $data['bcountry'] = $order->billing_country;
+  $data['btelephonenumber'] = $order->billing_phone;
+  $data['email'] = $order->primary_email;
   
   $form['#action'] = variable_get('uc_epdq_epdq_url', 'https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdq.e');
 
@@ -201,32 +199,31 @@ function uc_epdq_form($form_state,$order) {
 
 function uc_epdq_encrypt($order){
 
-  #define the remote cgi in readiness to call pullpage function 
+  //define the remote cgi in readiness to call pullpage function
   $server="secure2.epdq.co.uk";
   $url="/cgi-bin/CcxBarclaysEpdqEncTool.e";
 
-  #the following parameters have been obtained earlier in the merchant's webstore
-  #clientid, passphrase, oid, currencycode, total
-  $params='clientid='. variable_get('uc_epdq_mid', '');
-  $params.='&password='. variable_get('uc_epdq_passphrase', '') ;
-  $params.='&oid='. $order->order_id ;
-  $params.='&chargetype=Auth';
-  $params.='&currencycode=826';
-  $params.='&total='. $order->order_total;
+  //the following parameters have been obtained earlier in the merchant's webstore
+  //clientid, passphrase, oid, currencycode, total
+  $params  = 'clientid='. variable_get('uc_epdq_mid', '');
+  $params .= '&password='. variable_get('uc_epdq_passphrase', '') ;
+  $params .= '&oid='. $order->order_id ;
+  $params .= '&chargetype=Auth';
+  $params .= '&currencycode=826';
+  $params .= '&total='. $order->order_total;
 
-  #perform the HTTP Post
+  //perform the HTTP Post
   $response = uc_epdq_pullpage( $server,$url,$params );
    
-  #split the response into separate lines
+  //split the response into separate lines
   $response_lines=explode("\n",$response);
 
-  #for each line in the response check for the presence of the string 'epdqdata'
-  #this line contains the encrypted string
+  //for each line in the response check for the presence of the string 'epdqdata'
+  //this line contains the encrypted string
   $response_line_count=count($response_lines);
-  for ($i=0;$i<$response_line_count;$i++){
-    if (preg_match('/epdqdata/',$response_lines[$i])){
-        $strEPDQ=$response_lines[$i];
-	
+  for ($i = 0; $i < $response_line_count; $i++) {
+    if (preg_match('/epdqdata/',$response_lines[$i])) {
+        $strEPDQ = $response_lines[$i];
     }
   }
   
@@ -236,86 +233,79 @@ function uc_epdq_encrypt($order){
   // Sends a request to EPDQ and returns a response array.
   function uc_epdq_pullpage( $host, $usepath, $postdata = "" ) {
  
-  # open socket to filehandle(epdq encryption cgi)
+  //open socket to filehandle(epdq encryption cgi)
   $fp = fsockopen( $host, 80, &$errno, &$errstr, 60 );
 
-  #check that the socket has been opened successfully
+  //check that the socket has been opened successfully
   if( !$fp ) {
     print "$errstr ($errno)<br>\n";
   }
   else {
-
-    #write the data to the encryption cgi
+    //write the data to the encryption cgi
     fputs( $fp, "POST $usepath HTTP/1.0\n");
     $strlength = strlen( $postdata );
     fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
     fputs( $fp, "Content-length: ".$strlength."\n\n" );
     fputs( $fp, $postdata."\n\n" );
 
-    #clear the response data
-   $output = "";
- 
- 
-    #read the response from the remote cgi 
-    #while content exists, keep retrieving document in 1K chunks
+    //clear the response data
+    $output = "";
+
+    //read the response from the remote cgi
+    //while content exists, keep retrieving document in 1K chunks
     while( !feof( $fp ) ) {
         $output .= fgets( $fp, 1024);
     }
-
-    #close the socket connection
+    //close the socket connection
     fclose( $fp);
   }
-
-  #return the response
+  //return the response
   return $output;
 }
 
 function uc_epdq_complete($order_id = 0) {
   
-  $sql = db_query("SELECT * FROM uc_epdq WHERE oid = %d", $_GET['oid']);
-  while ($status = db_fetch_array($sql)){
-    $success = $status['transactionstatus'];
-
-    if ($success != 'Success'){	
-	
-    $file = file_directory_path().'/order-'.$status["oid"].'.txt';
-
-    drupal_set_message(t('We\'re sorry but there was a problem processing your payment. We\'ve created a !logfile
-				that you can download for your reference. We have not charged your card.', array('!logfile' => l(t('logfile'), $file) )));
-    drupal_goto('cart');
-    }  
-
-
-   else{
-   	
-    uc_cart_empty(uc_cart_get_id());
-
-    $_SESSION['do_complete'] = TRUE;
-
-    drupal_goto('cart/checkout/complete');
-  
-   }
+  $result = db_select('uc_epdq')
+    ->fields('uc_epdq')
+    ->condition('oid',$_GET['oid'],'oid')
+    ->execute();
+
+  foreach($result as $status) {
+    $success = $status['transaction_status'];
+    if ($success != 'Success') {
+      $file = variable_get('file_public_path', conf_path() . '/files') .'/order-'.$status["oid"].'.txt';
+      drupal_set_message(t('We\'re sorry but there was a problem processing your payment. We\'ve created a !logfile
+		that you can download for your reference. We have not charged your card.',
+        array('!logfile' => l(t('logfile'), $file) )));
+      drupal_goto('cart');
+    } else {
+      uc_cart_empty(uc_cart_get_id());
+      $_SESSION['do_complete'] = TRUE;
+      drupal_goto('cart/checkout/complete');
+    }
   } 
 }
 
 
 
-function uc_epdq_save_report(){
- 
- if ($_SERVER['REQUEST_METHOD'] == 'POST'){
+function uc_epdq_save_report() {
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 
     $log_dir = file_directory_path();
-    $timestamp=date("d-m-y--H-i-s");
-    $FILE=fopen("$log_dir/order-".$_POST["oid"].".txt","a");
-    fwrite($FILE,"Transaction Status - ".$_POST["transactionstatus"]."\n");
+    $timestamp = date("d-m-y--H-i-s");
+    $FILE = fopen("$log_dir/order-".$_POST["oid"].".txt","a");
+    fwrite($FILE,"Transaction Status - ".$_POST["transaction_status"]."\n");
     fwrite($FILE,"Total - ".$_POST["total"]."\n");
     fwrite($FILE,"OrderID - ".$_POST["oid"]."\n");
     fwrite($FILE,"Transaction Time Stamp - ".$_POST["datetime"]."\n");
     fclose($FILE);
-    }  
-  	
-    if (!empty($_POST['transactionstatus'])){ 
-    db_query("INSERT INTO uc_epdq VALUES(%d, '%s')", $_POST['oid'],$_POST['transactionstatus']);
-
+  }
+  if (!empty($_POST['transaction_status'])) {
+    db_insert('uc_epdq')
+      ->fields(array(
+        'oid' => $_POST['oid'],
+        'transaction_status' => $_POST['transaction_status'],
+      ))
+      ->execute();
     }
 }
