--- commerce_moneris/commerce_moneris.module
+++ commerce_moneris/commerce_moneris.module
@@ -76,6 +76,24 @@
 }
 
 /**
+ * Implements hook_commerce_order_status_info().
+ */
+function commerce_moneris_commerce_order_status_info() {
+  $order_statuses = array();
+  
+  // Add Payment Verification Required
+  $order_statuses['moneris_hpp_verification'] = array(
+    'name' => 'moneris_hpp_verification',
+    'title' => t('Payment Transaction Verification'),
+    'description' => t('An error occurred while processing the payment for this order. Verify the payment transactions for this order, and make any corrections necessary before changing its status.'),
+    'state' => 'pending',
+    'weight' => 20,
+  );
+
+  return $order_statuses;
+}
+
+/**
  * Form used to collect Moneris data.
  *
  * @param Array $payment_method
@@ -408,7 +426,7 @@
 }
 
 /**
- * Callback page for Moneris.
+ * Callback page for Moneris HPP.
  */
 function commerce_moneris_hpp_callback_page() {
   $payment_method = commerce_payment_method_instance_load('commerce_moneris_hpp|commerce_payment_commerce_moneris_hpp');
@@ -426,9 +444,21 @@
     $transaction_id = isset($_REQUEST['bank_transaction_id']) ? $_REQUEST['bank_transaction_id'] : FALSE;
     $amount = isset($_REQUEST['charge_total']) ? $_REQUEST['charge_total'] : 0;
     $response_code = isset($_REQUEST['response_code']) ? $_REQUEST['response_code'] : -1;
+    $message = check_plain(isset($_REQUEST['message'])) ? check_plain($_REQUEST['message']) : FALSE;
+    if (isset($_REQUEST['cancelTXN'])){    
     $cancel = isset($_REQUEST['cancelTXN']) && $_REQUEST['cancelTXN'] ? TRUE : FALSE;
   }
+    
+    // Test for "Enhanced Cancel" code 914
+    elseif (intval($response_code) == 914 ) {
+      $cancel = TRUE;
+    }
   else {
+      $cancel = FALSE;
+    }
+  }
+
+  else {
     if (!isset($_REQUEST['order_no'])) {
       drupal_not_found();
       return;
@@ -439,6 +469,7 @@
     $transaction_id = $_REQUEST['ref_num'];
     $amount = $_REQUEST['amount'];
     $response_code = isset($_REQUEST['response_code']) ? $_REQUEST['response_code'] : -1;
+    $message = check_plain(isset($_REQUEST['message'])) ? check_plain($_REQUEST['message']) : FALSE;
     $cancel = isset($_REQUEST['cancel']) && $_REQUEST['cancel'] ? TRUE : FALSE;
   }
 
@@ -448,6 +479,11 @@
     drupal_set_message(t('There was an error with your request. Please contact the site administrator.'), 'error');
   }
 
+  // Load the order's current state.
+  $order_status_load = commerce_order_status_load($order->status);
+  $order_state = $order_status_load['state'];
+  $order_status = $order->status;
+  
   // Create a commerce payment transaction.
   $transaction = commerce_payment_transaction_new('commerce_moneris_hpp', $order->order_id);
   $transaction->remote_id = $transaction_id;
@@ -458,8 +494,15 @@
     '@message' => print_r($_REQUEST, 1),
   );
 
+  // Process the Transaction.  
+  // Verify that the response code is not null.
+  if ($response_code != "null") {
+
+    // Verify the order was not cancelled.
   if (! $cancel) {
     $response_code = intval($response_code);
+
+      // Verify that the response code indicates an approved payment.
     if ((0 <= $response_code) && ($response_code <= 49)) {
       $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
       $payment_approved = TRUE;
@@ -470,16 +513,21 @@
     }
   }
   else {
-    $transaction->status = COMMERCE_PAYMENT_STATUS_CANCELED;
+      $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
     $payment_approved = FALSE;
   }
+  }
+  else {
+    $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
+    $payment_approved = FALSE;
+  }
 
   // Save the payment transaction.
   commerce_payment_transaction_save($transaction);
 
+  // Verify that the order is in the checkout_payment state.
+  if ($order_status == 'checkout_payment'){
   if ($payment_approved) {
-    drupal_set_message(t('Payment succesfully.'));
-
     // Complete the order.
     $order = commerce_order_status_update($order, 'completed');
     commerce_checkout_complete($order);
@@ -487,15 +535,46 @@
   }
   else {
     if ($cancel) {
-      drupal_set_message(t('Payment was canceled.'), 'error');
+        drupal_set_message(t('Payment was canceled. Please try again.'), 'error');
     }
+
+      // If the response code is null.
+      elseif ($response_code == "null") {
+
+        // Print an error message with message data generated by Moneris.
+        drupal_set_message(t('There was an error processing your payment: ' . $message . '.<br />Please try again. If the problem persists please contact the site administrator.'), 'error');
+      }
     else {
-      // If the payment failed, display an error meesage.
+
+        // If the payment failed, display an error message.
       drupal_set_message(t('We were unable to process your payment. Please enter your information again or try a different card.'), 'error');
     }
 
-    // Set the order back to review.
+      // Send the order back to the review page.
     $order = commerce_order_status_update($order, 'checkout_review');
     drupal_goto('checkout/' . $order->order_id . '/review');
   }
 }
+
+  // If the order is in completed or pending state go to the complete page and print a message.
+  elseif ($order_state == 'completed' || $order_state == 'pending' ) {
+
+    // If the payment went through flag it for verification.
+    if ($payment_approved){
+      $order = commerce_order_status_update($order, 'moneris_hpp_verification'); 
+    }  
+    drupal_set_message(t('Payment for this order has already been submitted.'), 'status');
+    drupal_goto('checkout/' . $order->order_id . '/complete');
+  }
+  
+  // If the order is in any other state (such as shopping cart or canceled) return an error, and go to the homepage.
+  else {
+
+    // If the payment went through flag it for verification.
+    if ($payment_approved){
+      $order = commerce_order_status_update($order, 'moneris_hpp_verification'); 
+    }
+    drupal_set_message(t('An unknown error occurred while attempting to process your payment. Please try again. If the problem persists please contact the site administrator.'), 'error');
+    drupal_goto('<front>');
+  }
+}
