Index: uc_worldpay.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_worldpay/uc_worldpay.module,v
retrieving revision 1.5
diff -u -p -r1.5 uc_worldpay.module
--- uc_worldpay.module	28 Oct 2009 23:51:07 -0000	1.5
+++ uc_worldpay.module	2 Nov 2009 16:31:37 -0000
@@ -7,12 +7,12 @@
  *
  * Original development sponsored by www.catorg.co.uk.
  */
-
+DEFINE('UC_WORLDPAY_CALLBACK_URL', 'cart/worldpay/complete');
 /**
  * Implementation of hook_menu().
  */
 function uc_worldpay_menu() {
-  $items['cart/worldpay/complete'] = array(
+  $items[UC_WORLDPAY_CALLBACK_URL] = array(
     'title' => 'Order complete',
     'page callback' => 'uc_worldpay_complete',
     'access arguments' => array('access content'),
@@ -25,7 +25,7 @@ function uc_worldpay_menu() {
 /**
  * Implementation of hook_payment_method().
  */
-function uc_worldpay_payment_method() {  
+function uc_worldpay_payment_method() {
   $methods[] = array(
     'id' => 'worldpay',
     'name' => t('Worldpay'),
@@ -71,10 +71,10 @@ function uc_payment_method_worldpay($op,
         '#prefix' => '<div class="help">',
         '#value' => t('<h4><strong>Installation instructions</strong></h4>
           <p>For this module to work properly you must configure a few specific options in your Worldpay account under <em>Installation Administration</em> settings:</p>
-          <ul><li><strong>Payment Response URL</strong> should be set to: %response_url</li>
+          <ul><li><strong>Payment Response URL</strong> should be set to: %response_url <em>OR</em> should be set to &lt;wpdisplay item=MC_callback&gt; which allows multiple sites to use the same worldpay account</li>
           <li><strong>Payment Response enabled?</strong> should be <em>enabled</em></li>
           <li><strong>Enable the Shopper Response</strong> should be <em>enabled</em> to get the Ubercart response page (optional)',
-          array('%response_url' => url('cart/worldpay/complete', array()))),
+          array('%response_url' => url(UC_WORLDPAY_CALLBACK_URL, array()))),
         '#suffix' => '</div>',
       );
       $form['uc_worldpay_sid'] = array(
@@ -111,7 +111,8 @@ function uc_payment_method_worldpay($op,
           'electron' => t('Visa Electron'),
           'mastercard' => t('Mastercard'),
           'maestro' => t('Maestro'),
-          'switch' => t('Switch'), 
+          /* Switch no longer exsits
+           * 'switch' => t('Switch'), */
           'solo' => t('Solo'),
           'amex' => t('Amex'),
           'diners' => t('Diners'),
@@ -132,9 +133,9 @@ function uc_payment_method_worldpay($op,
         '#title' => t('Enable test mode'),
         '#default_value' => variable_get('uc_worldpay_test', TRUE),
       );
-      $disabled = (!variable_get('uc_worldpay_test', TRUE)) ? TRUE : FALSE;      
+      $disabled = (!variable_get('uc_worldpay_test', TRUE)) ? TRUE : FALSE;
       $form['payment_parameters']['uc_worldpay_test_result'] = array(
-        '#type' => 'select', 
+        '#type' => 'select',
         '#title' => t('Test mode result'),
         '#description' => t('Specify the required transaction result when working in test mode.'),
         '#default_value' => variable_get('uc_worldpay_test_result', 'AUTHORISED'),
@@ -184,7 +185,25 @@ function uc_payment_method_worldpay($op,
         '#description' => t('The Worldpay live environment URL.'),
         '#default_value' => variable_get('uc_worldpay_live_url', 'https://secure.wp3.rbsworldpay.com/wcc/purchase'),
       );
-      
+
+      $form['payment_parameters']['uc_worldpay_md5'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Worldpay MD5 secret'),
+        '#description' => t('WorldPay MD5 Secret. This can be used to secure your worldpay account so only your server can send transactions to Worldpay. This needs to be configured on your Worldpay account first.'),
+        '#size' => 20,
+        '#maxlength' => 255,
+        '#default_value' => variable_get('uc_worldpay_md5', ''),
+      );
+      //Auth valid to
+      $wp_minutes = array(0,5,10,15,30,60);
+      $form['payment_parameters']['uc_worldpay_min_valid'] = array(
+        '#type' => 'select',
+        '#title' => t('Worldpay number of minutes valid'),
+        '#default_value' => variable_get('uc_worldpay_min_valid', '0'),
+        '#options' => $wp_minutes,
+        '#description' => t('WorldPay Auth Valid to. Set the number of minutes the current transaction is valid for. 0 leaves this unset'),
+      );
+
       return $form;
   }
 }
@@ -216,6 +235,8 @@ function uc_worldpay_form_alter(&$form, 
         );
       }
 
+      $callback_url = url(UC_WORLDPAY_CALLBACK_URL,array('absolute' => TRUE));
+
       $data += array(
         'instId' => variable_get('uc_worldpay_sid', ''),
         'amount' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
@@ -233,6 +254,7 @@ function uc_worldpay_form_alter(&$form, 
         'M_uc_cart_id' => uc_cart_get_id(),
         'lang' => variable_get('uc_worldpay_lang', 'en-GB'),
         'M_http_host' => $_SERVER['HTTP_HOST'],
+        'MC_callback' => $callback_url,
       );
 
       if (variable_get('uc_worldpay_desc', FALSE)) {
@@ -246,13 +268,29 @@ function uc_worldpay_form_alter(&$form, 
           'fixContact' => '',
         );
       }
-      
+
       if (!variable_get('uc_worldpay_show_contact', TRUE)) {
         $data += array(
           'hideContact' => '',
         );
       }
 
+      $worldpay_md5 = variable_get('uc_worldpay_md5', '');
+      if (drupal_strlen($worldpay_md5) > 0) {
+        $data += array(
+          'signatureFields' => "currency:cartId:amount",
+          'signature' => md5($worldpay_md5 .':'. $data['currency'] .':'. $data['cartId'] .":". $data['amount']),
+        );
+      }
+
+      $worldpay_min_valid = variable_get('uc_worldpay_min_valid', 0);
+      if ($worldpay_min_valid > 0) {
+        // valid to time in milliseconds in standard unix time
+        $data += array(
+          'authValidTo' => (time() + ($worldpay_min_valid * 60)) * 1000,
+        );
+      }
+
       foreach ($data as $name => $value) {
         $form[$name] = array(
           '#type' => 'hidden',
@@ -326,6 +364,7 @@ function uc_worldpay_complete($cart_id =
         $output .= t('Your order has been cancelled.');
         drupal_set_message(t('Your order has been cancelled.'));
         uc_order_comment_save($order->order_id, 0, t('Payment cancelled by user.'), 'admin');
+        uc_order_update_status($order->order_id, 'canceled');
         print theme('page', $output);
         return;
         break;
