'default' => 'no'
),
+ // Specify Maximum number of Card Attempts - both pre-auth and transcation
+ 'max_card_attempts' => array(
+ 'title' => __('Maximum Card Attempts', 'glm-merchant_e_solutions'),
+ 'type' => 'decimal',
+ 'description' => __('Maximum number of times a credit card pre-authorization or transaction may be attempted. (0 = no limit)', 'glm-merchant_e_solutions'),
+ 'default' => '4'
+ ),
+
'sep_1' => array(
'title' => __('Test Mode Credentials', 'glm-merchant_e_solutions'),
'type' => 'title',
}
+ /*
+ * Check for maximum number of card attempts
+ *
+ * @access public
+ * @return boolean False if maximum not reached, true if reached
+ */
+ private function check_max_attempts()
+ {
+ global $woocommerce;
+
+ // Get the maximum number of credit card attempts permitted
+ $maxAttempts = $this->settings['max_card_attempts'];
+
+ // If maximum attempts is 0 then unlimited
+ if ($maxAttempts == 0) {
+ return false;
+ }
+
+ // Check if attempt count is already set in the WooCommerce session
+ if ( isset( $woocommerce->session->cc_attempts ) ) {
+
+ // Get the current number of attempts plus one attempt (this attempt)
+ $attempts = $woocommerce->session->cc_attempts + 1;
+
+ // If the maximum number of attempts have been exceeded
+ if ($attempts > $maxAttempts) {
+ return true;
+ }
+
+ // Max attempts have not been reached - Update # of attempts
+ $woocommerce->session->cc_attempts = $attempts;
+ return false;
+
+ // Otherwise initialize the attempt count
+ } else {
+
+ $attempts = 0;
+ $woocommerce->session->cc_attempts = $attempts;
+ return false;
+
+ }
+
+ }
+
+
/*
* Process order with MES 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());