Skip to content

Commit

Permalink
PayFlow - Empty Card Data Validation Problem, ref #220
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Dec 28, 2015
1 parent 8b1877d commit da88447
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions classes/wc-gateway-paypal-pro-payflow-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,48 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
}
return false;
}

/**
* Validate the payment form
* PayFlow - Empty Card Data Validation Problem #220
* @since 1.1.7.6
*/
public function validate_fields() {

$card_number = !empty($_POST['paypal_pro_payflow_card_number']) ? str_replace(array(' ', '-'), '', wc_clean($_POST['paypal_pro_payflow_card_number'])) : '';
$card_csc = !empty($_POST['paypal_pro_payflow_card_csc']) ? wc_clean($_POST['paypal_pro_payflow_card_csc']) : '';
$card_exp = !empty($_POST['paypal_pro_payflow_card_expiration']) ? wc_clean($_POST['paypal_pro_payflow_card_expiration']) : '';

$card_exp_month = substr($card_exp, 0, 2);
$card_exp_year = substr($card_exp, 2, 2);

do_action('before_angelleye_pro_payflow_checkout_validate_fields', $card_number, $card_csc, $card_exp);

// Check card security code

if (!ctype_digit($card_csc)) {
wc_add_notice(__('Card security code is invalid (only digits are allowed)', 'paypal-for-woocommerce'), "error");
return false;
}

// Check card expiration data

if (!ctype_digit($card_exp_month) || !ctype_digit($card_exp_year) || $card_exp_month > 12 || $card_exp_month < 1 || $card_exp_year < date('y') || $card_exp_year > date('y') + 20) {
wc_add_notice(__('Card expiration date is invalid', 'paypal-for-woocommerce'), "error");
return false;
}

// Check card number

$card_number = str_replace(array(' ', '-'), '', $card_number);

if (empty($card_number) || !ctype_digit($card_number)) {
wc_add_notice(__('Card number is invalid', 'paypal-for-woocommerce'), "error");
return false;
}

do_action('after_angelleye_pro_payflow_checkout_validate_fields', $card_number, $card_csc, $card_exp);

return true;
}
}

0 comments on commit da88447

Please sign in to comment.