WC_Payment_Token_CC::validate()publicWC 2.6.0

Validate credit card payment tokens.

These fields are required by all credit card payment tokens: expiry_month - string Expiration date (MM) for the card expiry_year - string Expiration date (YYYY) for the card last4 - string Last 4 digits of the card card_type - string Card type (visa, mastercard, etc)

Method of the class: WC_Payment_Token_CC{}

No Hooks.

Return

true|false. True if the passed data is valid

Usage

$WC_Payment_Token_CC = new WC_Payment_Token_CC();
$WC_Payment_Token_CC->validate();

Changelog

Since 2.6.0 Introduced.

WC_Payment_Token_CC::validate() code WC 8.6.1

public function validate() {
	if ( false === parent::validate() ) {
		return false;
	}

	if ( ! $this->get_last4( 'edit' ) ) {
		return false;
	}

	if ( ! $this->get_expiry_year( 'edit' ) ) {
		return false;
	}

	if ( ! $this->get_expiry_month( 'edit' ) ) {
		return false;
	}

	if ( ! $this->get_card_type( 'edit' ) ) {
		return false;
	}

	if ( 4 !== strlen( $this->get_expiry_year( 'edit' ) ) ) {
		return false;
	}

	if ( 2 !== strlen( $this->get_expiry_month( 'edit' ) ) ) {
		return false;
	}

	return true;
}