Skip to content
Browse files

Fix expire date validation so it allows cards expiring in the current…

… year.

The current implementation has a bug when validating the expire date for cards expiring later in the current year. Added a condition to pass validation when year == currentYear and month >= currentMonth.
  • Loading branch information...
1 parent c5c1a43 commit ea5f19833449dd725855cda043a41cb1a260c529 @VictorGarcia VictorGarcia committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 validators/ECCValidator/ECCValidator.php
View
10 validators/ECCValidator/ECCValidator.php
@@ -109,13 +109,15 @@ public function validateNumber($creditCardNumber){
*/
public function validateDate($creditCardExpiredMonth, $creditCardExpiredYear){
- $currentYear = intval(date('Y'));
+ $currentYear = intval(date('Y'));
+ $currentMonth = intval(date('m'));
if(is_scalar($creditCardExpiredMonth)) $creditCardExpiredMonth = intval($creditCardExpiredMonth);
if(is_scalar($creditCardExpiredYear)) $creditCardExpiredYear = intval($creditCardExpiredYear);
- return is_integer($creditCardExpiredMonth) && $creditCardExpiredMonth >= 1 && $creditCardExpiredMonth <= 12 &&
- is_integer( $creditCardExpiredYear ) && $creditCardExpiredYear > $currentYear && $creditCardExpiredYear < $currentYear+10;
+ return is_integer($creditCardExpiredMonth) && is_integer($creditCardExpiredYear) && $creditCardExpiredMonth <= 12
+ && ($creditCardExpiredMonth >= 1 && $creditCardExpiredYear > $currentYear
+ && $creditCardExpiredYear < $currentYear + 10) || ($creditCardExpiredYear == $currentYear && $creditCardExpiredMonth >= $currentMonth);
}
/**
*
@@ -206,4 +208,4 @@ protected function checkType(){
return false;
}
-}
+}

0 comments on commit ea5f198

Please sign in to comment.
Something went wrong with that request. Please try again.