/** * Validate eCheck payment tokens. * * These fields are required by all eCheck payment tokens: * last4 - string Last 4 digits of the check * * @since 2.6.0 * @return boolean True if the passed data is valid */ public function validate() { if (false === parent::validate()) { return false; } if (empty($this->meta['last4'])) { return false; } return true; }
/** * Validate eCheck payment tokens. * * These fields are required by all eCheck payment tokens: * last4 - string Last 4 digits of the check * * @since 2.6.0 * @return boolean True if the passed data is valid */ public function validate() { if (false === parent::validate()) { return false; } if (!$this->get_last4()) { return false; } return true; }
/** * 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) * * @since 2.6.0 * @return boolean True if the passed data is valid */ 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; }
/** * 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) * * @since 2.6.0 * @return boolean True if the passed data is valid */ public function validate() { if (false === parent::validate()) { return false; } if (empty($this->meta['last4'])) { return false; } if (empty($this->meta['expiry_year'])) { return false; } if (empty($this->meta['expiry_month'])) { return false; } if (empty($this->meta['card_type'])) { return false; } if (4 !== strlen($this->meta['expiry_year'])) { return false; } if (2 !== strlen($this->meta['expiry_month'])) { return false; } return true; }
/** * Update a payment token. * * @since 2.7.0 * @param WC_Payment_Token $token */ public function update(&$token) { if (false === $token->validate()) { throw new Exception(__('Invalid or missing payment token fields.', 'woocommerce')); } global $wpdb; $payment_token_data = array('gateway_id' => $token->get_gateway_id('edit'), 'token' => $token->get_token('edit'), 'user_id' => $token->get_user_id('edit'), 'type' => $token->get_type('edit')); $wpdb->update($wpdb->prefix . 'woocommerce_payment_tokens', $payment_token_data, array('token_id' => $token->get_id('edit'))); $token->save_meta_data(); $token->apply_changes(); // Make sure all other tokens are not set to default if ($token->is_default() && $token->get_user_id() > 0) { WC_Payment_Tokens::set_users_default($token->get_user_id(), $token->get_id()); } do_action('woocommerce_payment_token_updated', $token->get_id()); }