? api_can
? api_can.tar.gz
? api_us
? api_us.tar.gz
? uc_moneris-730048-2.patch
? uc_moneris-730048-3.patch
Index: uc_moneris.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_moneris/uc_moneris.module,v
retrieving revision 1.9
diff -u -p -r1.9 uc_moneris.module
--- uc_moneris.module	12 Jan 2010 22:28:18 -0000	1.9
+++ uc_moneris.module	9 Mar 2010 07:13:44 -0000
@@ -15,18 +15,18 @@
  * Implementation of hook_menu().
  */
 function uc_moneris_menu() {
-  $items = array();
-  $items['cart/checkout/mpi'] = array(
-    'title' => 'Verified By VISA/Mastercard SecureCode',
-    'page callback' => 'uc_moneris_mpi_check',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-  $items['cart/checkout/mpi/complete'] = array(
-    'title' => 'Verified By VISA/Mastercard SecureCode',
-    'page callback' => 'uc_moneris_mpi_complete',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
+  $items = array();
+  $items['cart/checkout/mpi'] = array(
+    'title' => 'Verified By VISA/Mastercard SecureCode',
+    'page callback' => 'uc_moneris_mpi_check',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['cart/checkout/mpi/complete'] = array(
+    'title' => 'Verified By VISA/Mastercard SecureCode',
+    'page callback' => 'uc_moneris_mpi_complete',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
   );
 
   return $items;
@@ -35,7 +35,7 @@ function uc_moneris_menu() {
 /**
 * @desc Make a change to the review order form so that we can insert our own VBV process if needed.
 */
-function uc_moneris_form_alter(&$form, $form_state, $form_id) {
+function uc_moneris_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'uc_cart_checkout_form') {
     // Clear the uc_moneris info at checkout stage
     $_SESSION['uc_moneris'] = NULL;
@@ -150,7 +150,7 @@ function uc_moneris_checkout_review_form
   switch ($form_state['values']['op']) {
     case variable_get('uc_checkout_submit_button', t('Submit order')):
       $_SESSION['uc_moneris']['post'] = $_POST;
-      $_SESSION['uc_moneris']['form_id'] = $form_state['values']['form_id'];
+      $_SESSION['uc_moneris']['form_id'] = $form_state['values']['form_id'];
       $_SESSION['uc_moneris']['form_values'] = $form_state['values'];
       $order = uc_order_load($_SESSION['cart_order']);
       if ($order->payment_details['cc_type'] == 'Visa') {
@@ -169,15 +169,15 @@ function uc_moneris_checkout_review_form
         // Pass the transaction on as a normal credit card purchase
         return;
       }
-  }
+  }
   //TODO6: Based on the switch above, will the current function ever call uc_moneris_mpi_complete?
   uc_moneris_mpi_complete();
 }
 
 /**
 * @desc Location that we are returned to after the inline JS form has been submitted
-*/
-
+*/
+
 function uc_moneris_mpi_complete() {
   global $form_values;
   if ($_POST['MD']) {
@@ -187,10 +187,10 @@ function uc_moneris_mpi_complete() {
     $_SESSION['uc_moneris']['cart_order'] = $_SESSION['cart_order'];
   }
   // Re-instate the post vars as they were at the start
-  $_POST        = $_SESSION['uc_moneris']['post'];
-  $form_state['values']  = $_SESSION['uc_moneris']['form_values'];
-  $form_state['values']['op'] = variable_get('uc_checkout_submit_button', t('Submit order'));
-
+  $_POST        = $_SESSION['uc_moneris']['post'];
+  $form_state['values']  = $_SESSION['uc_moneris']['form_values'];
+  $form_state['values']['op'] = variable_get('uc_checkout_submit_button', t('Submit order'));
+
   // TODO6: this seems like it won't work.
   $result = uc_cart_checkout_review_form_submit('uc_cart_checkout_review_form_submit', $form_state);
 
@@ -328,7 +328,13 @@ function uc_moneris_charge($order_id, $a
   $order = uc_order_load($order_id);
 
   require_once(drupal_get_path('module', 'uc_moneris') .'/api/mpiClasses.php');
-  require_once(drupal_get_path('module', 'uc_moneris') .'/api/mpgClasses.php');
+  $is_us = (variable_get('uc_moneris_api_version','') != '');
+  if ($is_us) {
+    require_once(drupal_get_path('module', 'uc_moneris') .'/api_us/mpgClasses.php');
+  }
+  else {
+    require_once(drupal_get_path('module', 'uc_moneris') .'/api_can/mpgClasses.php');
+  }
   /**************************** Request Variables *******************************/
   $store_id   = variable_get('uc_moneris_store_id', '');
   $api_token  = variable_get('uc_moneris_api_token', '');
@@ -432,11 +438,11 @@ function uc_moneris_charge($order_id, $a
       'pan'         => $order->payment_details['cc_number'],
       'expdate'     => $expiry,
       'crypt_type'  => $crypt_type,
-    );
-    // Default the type to a purchase if not specified.
-    if (empty($txn_array['type'])) {
-      $txn_array['type'] = variable_get('uc_moneris_api_version') . 'purchase';
-    }
+    );
+    // Default the type to a purchase if not specified.
+    if (empty($txn_array['type'])) {
+      $txn_array['type'] = variable_get('uc_moneris_api_version') . 'purchase';
+    }
 
     // Do we have an MPI Authorized transaction?
     if ($cavv) {
@@ -458,6 +464,26 @@ function uc_moneris_charge($order_id, $a
     /******************************* Response ************************************/
     $mpgResponse  = $mpgHttpPost->getMpgResponse();
     $response_code = $mpgResponse->getResponseCode();
+    
+    $wd = array();
+    
+    $wd[] = 'CardType = ' . $mpgResponse->getCardType();
+    $wd[] = 'TransAmount = ' . $mpgResponse->getTransAmount();
+    $wd[] = 'TxnNumber = ' . $mpgResponse->getTxnNumber();
+    $wd[] = 'ReceiptId = ' . $mpgResponse->getReceiptId();
+    $wd[] = 'TransType = ' . $mpgResponse->getTransType();
+    $wd[] = 'ReferenceNum = ' . $mpgResponse->getReferenceNum();
+    $wd[] = 'ResponseCode = ' . $mpgResponse->getResponseCode();
+    $wd[] = 'Message = ' . $mpgResponse->getMessage();
+    $wd[] = 'AuthCode = ' . $mpgResponse->getAuthCode();
+    $wd[] = 'Complete = ' . $mpgResponse->getComplete();
+    $wd[] = 'TransDate = ' . $mpgResponse->getTransDate();
+    $wd[] = 'TransTime = ' . $mpgResponse->getTransTime();
+    $wd[] = 'Ticket = ' . $mpgResponse->getTicket();
+    $wd[] = 'TimedOut = ' . $mpgResponse->getTimedOut();
+    
+    watchdog('uc_moneris', '<pre>'.join("\n",$wd).'</pre>');
+    
     $txn_number    = $mpgResponse->getTxnNumber();
     $completed = strtolower($mpgResponse->getComplete());
     //Check the CVD?
@@ -507,7 +533,7 @@ function uc_moneris_charge($order_id, $a
       }
     }
 
-    if (($this_trans_type == uc_moneris_preauth_string() && $txn_type == uc_moneris_transaction_type()) && intval($response_code) < 49 || $completed == 'true') {
+    if ($this_trans_type == uc_moneris_preauth_string() && $txn_type == uc_moneris_transaction_type() && intval($response_code) <= 49 && $completed == 'true') {
       //The previous transaction was a preauth before a capture. Run the transaction again in Capture mode.
       $txnArray = array(
         'type'        =>  variable_get('uc_moneris_api_version', '') .'completion',
@@ -602,4 +628,4 @@ function uc_moneris_order($op, $order) {
         WHERE order_id = %d AND comment LIKE '%preauth**%' AND amount > 0", $order->order_id);
       break;
   }
-}
+}
