public function validate()
    {
        $parameters = func_get_args();

        if ( count($parameters) == 0 )
        {
            $parameters = ['number', 'cvv', 'expiryMonth', 'expiryYear'];
        }

        foreach ($parameters as $key)
        {
            $value = $this->parameters->get($key);

            if ( empty($value) )
            {
                throw new InvalidCreditCardException("The $key parameter is required");
            }
        }

        if ( isset($parameters['expiryMonth']) && isset($parameters['expiryYear']) )
        {
            if ( $this->getExpiryDate('Ym') < gmdate('Ym') )
            {
                throw new InvalidCreditCardException('Card has expired');
            }
        }

        if ( isset($parameters['number']) )
        {
            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');
            }
        }

        if ( isset($parameters['cvv']) )
        {
            if ( !is_null( $this->getCvv() ) && !preg_match( '/^\d{3,4}$/i', $this->getCvv() ) )
            {
                throw new InvalidCreditCardException('Card CVV should have 3 to 4 digits');
            }
        }
    }
public function validate()
    {
        $parameters = func_get_args();

        if ( count($parameters) == 0 )
        {
            $parameters = ['number', 'cvv', 'expiryMonth', 'expiryYear'];
        }

        foreach ($parameters as $key)
        {
            $value = $this->parameters->get($key);

            if ( empty($value) )
            {
                throw new InvalidCreditCardException("The $key parameter is required");
            }
        }

        if ( isset($parameters['expiryMonth']) && isset($parameters['expiryYear']) )
        {
            if ( $this->getExpiryDate('Ym') < gmdate('Ym') )
            {
                throw new InvalidCreditCardException('Card has expired');
            }
        }

        if ( isset($parameters['number']) )
        {
            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');
            }
        }

        if ( isset($parameters['cvv']) )
        {
            if ( !is_null( $this->getCvv() ) && !preg_match( '/^\d{3,4}$/i', $this->getCvv() ) )
            {
                throw new InvalidCreditCardException('Card CVV should have 3 to 4 digits');
            }
        }
    }
public function validate ( ) { $ parameters = func_get_args ( ) ; if ( count ( $ parameters ) == 0 ) { $ parameters = [ 'number' , 'cvv' , 'expiryMonth' , 'expiryYear' ] ; } foreach ( $ parameters as $ key ) { $ value = $ this -> parameters -> get ( $ key ) ; if ( empty ( $ value ) ) { throw new InvalidCreditCardException ( "The $key parameter is required" ) ; } } if ( isset ( $ parameters [ 'expiryMonth' ] ) && isset ( $ parameters [ 'expiryYear' ] ) ) { if ( $ this -> getExpiryDate ( 'Ym' ) < gmdate ( 'Ym' ) ) { throw new InvalidCreditCardException ( 'Card has expired' ) ; } } if ( isset ( $ parameters [ 'number' ] ) ) { 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' ) ; } } if ( isset ( $ parameters [ 'cvv' ] ) ) { if ( ! is_null ( $ this -> getCvv ( ) ) && ! preg_match ( '/^\d{3,4}$/i' , $ this -> getCvv ( ) ) ) { throw new InvalidCreditCardException ( 'Card CVV should have 3 to 4 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.

Falls back to validating number, cvv, expiryMonth, expiryYear if no parameters are present.

@param string ... Optional variable length list of required parameters
@throws InvalidCreditCardException
Validate this credit card . If the card is invalid InvalidCreditCardException is thrown .