Added check for missing CC info and blocking submit on "ENTER" key.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 11 Dec 2015 21:40:43 +0000 (16:40 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 11 Dec 2015 21:40:43 +0000 (16:40 -0500)
classes/glmMesGateway.php
glm-woocommerce-merchant-e-solutions-gateway.php

index 585cc0f..35cd46f 100644 (file)
@@ -331,6 +331,25 @@ class GlmMesGateway extends WC_Payment_Gateway
                     ));
         }
 
+
+        // Add script to checkout page to block
+        add_action( 'woocommerce_after_checkout_form', array($this, 'glmAddCheckoutPageScript'));
+
+    }
+
+    public function glmAddCheckoutPageScript() {
+        echo '
+            <script type="text/javascript">
+                jQuery(document).ready(function($) {
+                    $(window).keydown(function(event){
+                        if(event.keyCode == 13) {
+                          event.preventDefault();
+                          return false;
+                        }
+                      });
+                });
+            </script>
+        ';
     }
 
     // Tell WooCommerce that we exist
@@ -996,31 +1015,6 @@ class GlmMesGateway extends WC_Payment_Gateway
         global $woocommerce;
         $this->cust_order = new WC_Order($order_id);
 
-        // Check for a maximum number of attempts
-        if ($this->check_max_attempts()) {
-
-            wc_add_notice(
-                    __(
-                            '<p><h4><b style="color: red;">We\'re sorry, there was a problem with your payment...</b></h4><p><b>Reason:</b><br>' .
-                            'You have exceeded the maximum number of attempts to process your credit card.<br>
-                            Please contact us for assistance.',
-                            'woothemes'), 'notice');
-
-            // Add a note to the customer order for reference
-            $this->cust_order->add_order_note( 'Error: '. 'Number of credit card processing attempts exceeded.' );
-
-            if (GLM_MES_DEBUG && ! GLM_MES_DEBUG_VERBOSE) {
-                wc_add_notice(
-                        'GLM MeS Gateway: Maximum attempts exceeded!', 'notice');
-            }
-
-            return array(
-                    'result' => 'failure',
-                    'redirect' => $this->get_return_url($this->cust_order)
-            );
-
-        }
-
         // Get our invoice number
         $this->invNumb = str_replace("#", "", $this->cust_order->get_order_number());
 
@@ -1038,6 +1032,22 @@ class GlmMesGateway extends WC_Payment_Gateway
         $this->cc_cvc = (isset($_POST[GLM_MES_ID . '-card-cvc'])) ? $_POST[GLM_MES_ID .
                  '-card-cvc'] : '';
 
+        // Check for required credit card data
+        if (trim($this->ccNumb) == '' || trim($this->cc_exp) == '' || trim($this->cc_cvc) == '') {
+
+            wc_add_notice(
+                    __(
+                            '<p><h4><b style="color: red;">You have not supplied the required Credit Card information!</b></h4>
+                            Please complete the credit card number, expiration date, and card code in the form below at the bottom of the page.',
+                            'woothemes'), 'notice');
+
+            return array(
+                    'result' => 'failure',
+                    'redirect' => $this->get_return_url($this->cust_order)
+            );
+
+        }
+
         /*
          * Other data available from WooCommerce
          *
@@ -1072,6 +1082,31 @@ class GlmMesGateway extends WC_Payment_Gateway
                              print_r($this->cust_order, 1) . '</pre></p>', 'success');
         }
 
+        // Check for a maximum number of attempts
+        if ($this->check_max_attempts()) {
+
+            wc_add_notice(
+                    __(
+                            '<p><h4><b style="color: red;">We\'re sorry, there was a problem with your payment...</b></h4><p><b>Reason:</b><br>' .
+                            'You have exceeded the maximum number of attempts to process your credit card.<br>
+                            Please contact us for assistance.',
+                            'woothemes'), 'notice');
+
+            // Add a note to the customer order for reference
+            $this->cust_order->add_order_note( 'Error: '. 'Number of credit card processing attempts exceeded.' );
+
+            if (GLM_MES_DEBUG && ! GLM_MES_DEBUG_VERBOSE) {
+                wc_add_notice(
+                        'GLM MeS Gateway: Maximum attempts exceeded!', 'notice');
+            }
+
+            return array(
+                    'result' => 'failure',
+                    'redirect' => $this->get_return_url($this->cust_order)
+            );
+
+        }
+
         // Check if Address Verification is required
         if ($this->settings['address_verification'] == 'yes') {
 
index ab20e26..f0100a5 100644 (file)
@@ -3,7 +3,7 @@
  * Plugin Name: GLM WooCommerce Merchant e-Solutions Gateway
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Merchant e-Solutions support for WooCommerce. Provides a payment gateway that will process WooCommerce payments and refunds through Merchant e-Solutions. For more information on Merchant e-Solutions see their Website at <a href="https://www.merchante-solutions.com/">https://www.merchante-solutions.com/</a>.
- * Version: 1.0.3
+ * Version: 1.0.4
  * Author: Gaslight Media
  * Author URI: http://www.gaslightmedia.com/
  * Text Domain: glm-woocommerce-merchant-e-solutions-gateway
@@ -21,7 +21,7 @@
  * @package glmMerchantESolutions
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.0.3
+ * @version 1.0.4
  */
 
 /*