add expiration date validation

Project: 
Ubercart
Category: 
feature request
Priority: 
normal
Status: 
fixed

Hi,

uc_credit validates several fields (cc num, cvv, owners...) during checkout, but it's still possible to enter an expiration date in the past (I can currently select Jan 2008, for example). What do you think about adding to this a validation function that makes sure expiration is not in the past?

Chad

$return = TRUE;
      if (variable_get('uc_credit_owner_enabled', FALSE) && empty($_POST['cc_owner'])) {
        drupal_set_message(t('Enter the owner name as it appears on the card.'), 'error');
        $return = FALSE;
      }
      if (variable_get('uc_credit_cvv_enabled', TRUE) && !_valid_cvv($_POST['cc_cvv'])) {
        drupal_set_message(t('You have entered an invalid CVV number.'), 'error');
        $return = FALSE;
      }
      if (variable_get('uc_credit_bank_enabled', FALSE) && empty($_POST['cc_bank'])) {
        drupal_set_message(t('You must enter the issuing bank for that card.'), 'error');
        $return = FALSE;
      }
      if (variable_get('uc_credit_validate_numbers', TRUE) && !_valid_card_number($arg1->payment_details['cc_number'])) {
        drupal_set_message(t('You have entered an invalid credit card number.'), 'error');
        $return = FALSE;
      }

Re: add expiration date validation

Good idea - added it into the conditional statement for validating card numbers.

Re: add expiration date validation

here's how I solved it in my uc_credit.module file:

      if (date(Y)<=$arg1->payment_details['cc_exp_year']&&$arg1->payment_details['cc_exp_month']<=date(m)) { //if year is less than or equal to now AND month is less than or equal to now, throw error
        drupal_set_message(t('The expiration date entered is expired'), 'error');
        $return = FALSE;
      }