public function validate()
    {
        $requiredParameters = array(
            'number' => 'credit card number',
            'expiryMonth' => 'expiration month',
            'expiryYear' => 'expiration year'
        );

        foreach ($requiredParameters as $key => $val) {
            if (!$this->getParameter($key)) {
                throw new InvalidCreditCardException("The $val is required");
            }
        }

        if ($this->getExpiryDate('Ym') < gmdate('Ym')) {
            throw new InvalidCreditCardException('Card has expired');
        }

        if (!Helper::validateLuhn($this->getNumber())) {
            throw new InvalidCreditCardException('Card number is invalid');
        }

        if (!is_null($this->getNumber()) && !preg_match('/^\d{12,19}$/i', $this->getNumber())) {
            throw new InvalidCreditCardException('Card number should have 12 to 19 digits');
        }
    }
public function validate()
    {
        $requiredParameters = array(
            'number' => 'credit card number',
            'expiryMonth' => 'expiration month',
            'expiryYear' => 'expiration year'
        );

        foreach ($requiredParameters as $key => $val) {
            if (!$this->getParameter($key)) {
                throw new InvalidCreditCardException("The $val is required");
            }
        }

        if ($this->getExpiryDate('Ym') < gmdate('Ym')) {
            throw new InvalidCreditCardException('Card has expired');
        }

        if (!Helper::validateLuhn($this->getNumber())) {
            throw new InvalidCreditCardException('Card number is invalid');
        }

        if (!is_null($this->getNumber()) && !preg_match('/^\d{12,19}$/i', $this->getNumber())) {
            throw new InvalidCreditCardException('Card number should have 12 to 19 digits');
        }
    }
public function validate ( ) { $ requiredParameters = array ( 'number' => 'credit card number' , 'expiryMonth' => 'expiration month' , 'expiryYear' => 'expiration year' ) ; foreach ( $ requiredParameters as $ key => $ val ) { if ( ! $ this -> getParameter ( $ key ) ) { throw new InvalidCreditCardException ( "The $val is required" ) ; } } if ( $ this -> getExpiryDate ( 'Ym' ) < gmdate ( 'Ym' ) ) { throw new InvalidCreditCardException ( 'Card has expired' ) ; } if ( ! Helper :: validateLuhn ( $ this -> getNumber ( ) ) ) { throw new InvalidCreditCardException ( 'Card number is invalid' ) ; } if ( ! is_null ( $ this -> getNumber ( ) ) && ! preg_match ( '/^\d{12,19}$/i' , $ this -> getNumber ( ) ) ) { throw new InvalidCreditCardException ( 'Card number should have 12 to 19 digits' ) ; } }
Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown.

This method is called internally by gateways to avoid wasting time with an API call
when the credit card is clearly invalid.

Generally if you want to validate the credit card yourself with custom error
messages, you should use your framework's validation library, not this method.

@return void
@throws Exception\InvalidRequestException
@throws InvalidCreditCardException
Validate this credit card . If the card is invalid InvalidCreditCardException is thrown .