/** * Validates the provided credit card account number * * @since 2.1.0 * @param string $account_number the credit card account number * @return boolean true if the card account number is valid, false otherwise */ protected function validate_credit_card_account_number($account_number) { $is_valid = true; // validate card number $account_number = str_replace(array(' ', '-'), '', $account_number); if (empty($account_number)) { SV_WC_Helper::wc_add_notice(_x('Card number is missing', 'Supports direct credit card', $this->text_domain), 'error'); $is_valid = false; } else { if (strlen($account_number) < 12 || strlen($account_number) > 19) { SV_WC_Helper::wc_add_notice(_x('Card number is invalid (wrong length)', 'Supports direct credit card', $this->text_domain), 'error'); $is_valid = false; } if (!ctype_digit($account_number)) { SV_WC_Helper::wc_add_notice(_x('Card number is invalid (only digits allowed)', 'Supports direct credit card', $this->text_domain), 'error'); $is_valid = false; } if (!SV_WC_Payment_Gateway_Helper::luhn_check($account_number)) { SV_WC_Helper::wc_add_notice(_x('Card number is invalid', 'Supports direct credit card', $this->text_domain), 'error'); $is_valid = false; } } return $is_valid; }
/** * Validates the provided credit card account number * * @since 2.1.0 * @param string $account_number the credit card account number * @return boolean true if the card account number is valid, false otherwise */ protected function validate_credit_card_account_number($account_number) { $is_valid = true; // validate card number $account_number = str_replace(array(' ', '-'), '', $account_number); if (empty($account_number)) { SV_WC_Helper::wc_add_notice(esc_html__('Card number is missing', 'woocommerce-plugin-framework'), 'error'); $is_valid = false; } else { if (strlen($account_number) < 12 || strlen($account_number) > 19) { SV_WC_Helper::wc_add_notice(esc_html__('Card number is invalid (wrong length)', 'woocommerce-plugin-framework'), 'error'); $is_valid = false; } if (!ctype_digit($account_number)) { SV_WC_Helper::wc_add_notice(esc_html__('Card number is invalid (only digits allowed)', 'woocommerce-plugin-framework'), 'error'); $is_valid = false; } if (!SV_WC_Payment_Gateway_Helper::luhn_check($account_number)) { SV_WC_Helper::wc_add_notice(esc_html__('Card number is invalid', 'woocommerce-plugin-framework'), 'error'); $is_valid = false; } } return $is_valid; }