Added option to just check ZIP code and not full address
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 29 Mar 2016 17:53:15 +0000 (13:53 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 29 Mar 2016 17:53:15 +0000 (13:53 -0400)
classes/glmMesGateway.php

index 35cd46f..fe96f08 100644 (file)
@@ -555,11 +555,19 @@ class GlmMesGateway extends WC_Payment_Gateway
                         'default' => 'no'
                 ),
 
-                // Require Address Verification
+                // Require Full Address Verification
                 'address_verification' => array(
                         'title' => __('Require Address Verification', 'glm-merchant_e_solutions'),
                         'type' => 'checkbox',
-                        'label' => __('Check to require valid address verification before charging credit card.', 'glm-merchant_e_solutions'),
+                        'label' => __('Check to require valid address and ZIP/Postal code verification before charging credit card.<br>Overrides ZIP match option below.', 'glm-merchant_e_solutions'),
+                        'default' => 'no'
+                ),
+
+                // Require ZIP Match
+                'zip_verification' => array(
+                        'title' => __('Require ZIP Verification', 'glm-merchant_e_solutions'),
+                        'type' => 'checkbox',
+                        'label' => __('Check to require valid ZIP/Postal code verification before charging credit card.', 'glm-merchant_e_solutions'),
                         'default' => 'no'
                 ),
 
@@ -742,17 +750,21 @@ class GlmMesGateway extends WC_Payment_Gateway
                     wc_add_notice('GLM MeS Gateway: Running Address Verification', 'success');
                 }
 
-                // Only run address verification test if selected
-                if ($this->settings['address_verification'] == 'yes') {
+                // Only run address and/or ZIP verification test if selected
+                if ($this->settings['address_verification'] == 'yes' || $this->settings['zip_verification'] == 'yes') {
 
-                        $trans = new TpgSale($this->profile_id, $this->profile_key);
+                    if (GLM_MES_DEBUG_VERBOSE) {
+                        wc_add_notice('GLM MeS Gateway: Address Verification Requested', 'success');
+                    }
 
-                        // Set transaction type to Address Verification Only
-                        $trans->TranType = "A";
+                    $trans = new TpgSale($this->profile_id, $this->profile_key);
 
-                        $sendRequestData = true;
+                    // Set transaction type to Address Verification Only
+                    $trans->TranType = "A";
 
-                        break;
+                    $sendRequestData = true;
+
+                    break;
 
                 // otherwise, no AVS, so say we're OK to go
                 } else {
@@ -910,6 +922,12 @@ 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>";
                     }
+                } elseif ($this->settings['zip_verification'] == 'yes') {
+                    if ($response['avs_result'] == 'A' || !in_array($response['avs_result'], array('Z', 'Y', 'X'))) {
+                        $auth = false;
+                        $response['auth_response_descr'] = "The ZIP/Postal code you entered does not seem to match this credit card.
+                                Please check your ZIP/Postal code and try again.<br>";
+                    }
                 } else {
 
                     if (GLM_MES_DEBUG_VERBOSE) {
@@ -1108,13 +1126,18 @@ class GlmMesGateway extends WC_Payment_Gateway
         }
 
         // Check if Address Verification is required
-        if ($this->settings['address_verification'] == 'yes') {
+        if ($this->settings['zip_verification'] == 'yes' || $this->settings['address_verification'] == 'yes') {
 
             // Try Address Verification
             $response = $this->run_transaction('AVS');
 
             // If AVS was successful - run sale
             if ($response['success']) {
+
+                if (GLM_MES_DEBUG_VERBOSE) {
+                    wc_add_notice('GLM MeS Gateway: Address Verification OK, running sale', 'success');
+                }
+
                 $response = $this->run_transaction('Sale', false);
             }
 
@@ -1143,12 +1166,11 @@ class GlmMesGateway extends WC_Payment_Gateway
         } else {
 
             // Tell the user we had a payment failure
-// THE VARIABLE DATA NEEDS TO BE APPENDED RATHER THAT INCLUDED. woothemes is not our method title
+            // THE VARIABLE DATA NEEDS TO BE APPENDED RATHER THAT INCLUDED. woothemes is not our method title
             wc_add_notice(
                     __(
                             "<h4>We're sorry, there was a problem with your payment...</h4><p><b>Reason:</b> " .
-                                     $response['auth_response_text'] .
-                                     '</p><p>'.$response['auth_response_descr'],
+                                     $response['auth_response_descr']."</p>",
                                     'woothemes'), 'error');
 
             // Add a note to the customer order for reference