Sorted out change from PreAuth to AVS.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 6 Aug 2015 20:53:36 +0000 (16:53 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 6 Aug 2015 20:53:36 +0000 (16:53 -0400)
classes/glmMesGateway.php

index f87616a..d103090 100644 (file)
@@ -692,10 +692,10 @@ class GlmMesGateway extends WC_Payment_Gateway
     }
 
     /*
-     * Run PreAuth to check address and CSV if set
+     * Run requested transaction
      *
      *
-     * @var string $tans_type 'PreAuth', 'Settle', 'Sale', or 'Refund'
+     * @var string $tans_type 'AVS', 'Settle', 'Sale', or 'Refund'
      * @var float $amount Override order amount, used for refunds
      *
      * @access public
@@ -716,33 +716,37 @@ class GlmMesGateway extends WC_Payment_Gateway
         // Select transaction object by type requested
         switch ($trans_type) {
 
-            case 'PreAuth':
+            // Address Verification Service
+            case 'AVS':
 
                 if (GLM_MES_DEBUG_VERBOSE) {
-                    wc_add_notice('GLM MeS Gateway: Running Pre-Authorization', 'success');
+                    wc_add_notice('GLM MeS Gateway: Running Address Verification', 'success');
                 }
 
-                // Only run pre-auth if address verification or CVV test is selected
-                if ($this->settings['address_verification'] == 'yes' ||
-                    $this->settings['cvv_required'] == 'yes' ) {
+                // Only run address verification test if selected
+                if ($this->settings['address_verification'] == 'yes') {
+
+                        $trans = new TpgSale($this->profile_id, $this->profile_key);
 
-                        $trans = new TpgPreAuth($this->profile_id, $this->profile_key);
+                        // Set transaction type to Address Verification Only
+                        $trans->TranType = "A";
 
                         $sendRequestData = true;
 
                         break;
 
-                // otherwise, no pre-auth needs to be run, so say we're OK to go
+                // otherwise, no AVS, so say we're OK to go
                 } else {
 
                     if (GLM_MES_DEBUG_VERBOSE) {
-                        wc_add_notice('GLM MeS Gateway: No Pre-Authorization requested', 'success');
+                        wc_add_notice('GLM MeS Gateway: Address Verification Not Required', 'success');
                     }
 
                 }
 
                 // break;  - If no pre-auth was required, we're just falling through to Sale
 
+            //
             case 'Sale':
 
                 if (GLM_MES_DEBUG_VERBOSE) {
@@ -755,6 +759,7 @@ class GlmMesGateway extends WC_Payment_Gateway
 
                 break;
 
+/*
             case 'Settle':      // Requires a prior pre-auth
 
                 if (GLM_MES_DEBUG_VERBOSE) {
@@ -781,6 +786,7 @@ class GlmMesGateway extends WC_Payment_Gateway
                 $sendRequestData = false;
 
                 break;
+*/
 
             case 'Refund':
 
@@ -805,11 +811,22 @@ class GlmMesGateway extends WC_Payment_Gateway
 
         if ($sendRequestData) {
 
-            // Send transaction amount
-            if ($this->amount_driven_test) {
+            // Set transaction amount
+            if ($trans->TranType == "A") {
+
+                // AVS Only
+                $amount = 0;
+
+            } elseif ($this->amount_driven_test) {
+
+                // An amount driven test has been selected in admin
                 $amount = $this->amount_driven_test;
+
             } else {
+
+                // A normal transaction
                 $amount = $this->cust_order->order_total;
+
             }
 
             // Send billing information
@@ -861,7 +878,7 @@ class GlmMesGateway extends WC_Payment_Gateway
         // Check for success based on transaction type
         switch ($trans_type) {
 
-            case 'PreAuth':
+            case 'AVS':
 
                 $auth = true;
 
@@ -874,13 +891,19 @@ class GlmMesGateway extends WC_Payment_Gateway
                         $response['auth_response_descr'] = "The address you entered does not seem to match the address for this credit card.
                                 Please check your address and try again.<br>";
                     }
+                } else {
+
+                    if (GLM_MES_DEBUG_VERBOSE) {
+                        wc_add_notice('GLM MeS Gateway: Address Verification OK', 'success');
+                    }
+
                 }
 
                 // If CVV required
                 if ($this->settings['cvv_required'] == 'yes') {
                     if (!in_array($response['cvv2_result'], array('M'))) {
                         $auth = false;
-                        $response['auth_response_descr'] = 'You may not have entered the correct "Card Code" below.
+                        $response['auth_response_descr'] .= 'You may not have entered the correct "Card Code" below.
                                 Please check the code on the back of your card and try again.<br>';
                     }
                 }
@@ -889,7 +912,6 @@ class GlmMesGateway extends WC_Payment_Gateway
 
                 break;
 
-            case 'Settle':
             case 'Sale':
 
                 // Ask MES gateway code if the transaction was approved
@@ -1050,22 +1072,21 @@ class GlmMesGateway extends WC_Payment_Gateway
                              print_r($this->cust_order, 1) . '</pre></p>', 'success');
         }
 
-        // Check if pre-authorization is required
-        if ($this->settings['address_verification'] == 'yes' ||
-                $this->settings['cvv_required'] == 'yes' ) {
+        // Check if Address Verification is required
+        if ($this->settings['address_verification'] == 'yes') {
 
-            // Try pre-authorization first
-            $response = $this->run_transaction('PreAuth');
+            // Try Address Verification
+            $response = $this->run_transaction('AVS');
 
-            // If pre-auth was not requested or was successful - run sale
+            // If AVS was successful - run sale
             if ($response['success']) {
-                $response = $this->run_transaction('Settle', false, $response['transaction_id']);
+                $response = $this->run_transaction('Sale', false);
             }
 
         // Ohterwise we're just going to run it as a final sale
         } else {
 
-            $response = $this->run_transaction('Sale', false, $response['transaction_id']);
+            $response = $this->run_transaction('Sale', false);
 
         }