Files
assets
i18n
includes
abstracts
admin
blocks
cli
customizer
data-stores
emails
export
gateways
import
integrations
interfaces
legacy
libraries
log-handlers
payment-tokens
class-wc-payment-token-cc.php
class-wc-payment-token-echeck.php
queue
rest-api
shipping
shortcodes
theme-support
tracks
traits
walkers
wccom-site
widgets
class-wc-ajax.php
class-wc-api.php
class-wc-auth.php
class-wc-autoloader.php
class-wc-background-emailer.php
class-wc-background-updater.php
class-wc-breadcrumb.php
class-wc-cache-helper.php
class-wc-cart-fees.php
class-wc-cart-session.php
class-wc-cart-totals.php
class-wc-cart.php
class-wc-checkout.php
class-wc-cli.php
class-wc-comments.php
class-wc-countries.php
class-wc-coupon.php
class-wc-customer-download-log.php
class-wc-customer-download.php
class-wc-customer.php
class-wc-data-exception.php
class-wc-data-store.php
class-wc-datetime.php
class-wc-deprecated-action-hooks.php
class-wc-deprecated-filter-hooks.php
class-wc-discounts.php
class-wc-download-handler.php
class-wc-emails.php
class-wc-embed.php
class-wc-form-handler.php
class-wc-frontend-scripts.php
class-wc-geo-ip.php
class-wc-geolite-integration.php
class-wc-geolocation.php
class-wc-https.php
class-wc-install.php
class-wc-integrations.php
class-wc-log-levels.php
class-wc-logger.php
class-wc-meta-data.php
class-wc-order-factory.php
class-wc-order-item-coupon.php
class-wc-order-item-fee.php
class-wc-order-item-meta.php
class-wc-order-item-product.php
class-wc-order-item-shipping.php
class-wc-order-item-tax.php
class-wc-order-item.php
class-wc-order-query.php
class-wc-order-refund.php
class-wc-order.php
class-wc-payment-gateways.php
class-wc-payment-tokens.php
class-wc-post-data.php
class-wc-post-types.php
class-wc-privacy-background-process.php
class-wc-privacy-erasers.php
class-wc-privacy-exporters.php
class-wc-privacy.php
class-wc-product-attribute.php
class-wc-product-download.php
class-wc-product-external.php
class-wc-product-factory.php
class-wc-product-grouped.php
class-wc-product-query.php
class-wc-product-simple.php
class-wc-product-variable.php
class-wc-product-variation.php
class-wc-query.php
class-wc-rate-limiter.php
class-wc-regenerate-images-request.php
class-wc-regenerate-images.php
class-wc-register-wp-admin-settings.php
class-wc-rest-authentication.php
class-wc-rest-exception.php
class-wc-session-handler.php
class-wc-shipping-rate.php
class-wc-shipping-zone.php
class-wc-shipping-zones.php
class-wc-shipping.php
class-wc-shortcodes.php
class-wc-structured-data.php
class-wc-tax.php
class-wc-template-loader.php
class-wc-tracker.php
class-wc-validation.php
class-wc-webhook.php
class-woocommerce.php
wc-account-functions.php
wc-attribute-functions.php
wc-cart-functions.php
wc-conditional-functions.php
wc-core-functions.php
wc-coupon-functions.php
wc-deprecated-functions.php
wc-formatting-functions.php
wc-notice-functions.php
wc-order-functions.php
wc-order-item-functions.php
wc-page-functions.php
wc-product-functions.php
wc-rest-functions.php
wc-stock-functions.php
wc-template-functions.php
wc-template-hooks.php
wc-term-functions.php
wc-update-functions.php
wc-user-functions.php
wc-webhook-functions.php
wc-widget-functions.php
lib
packages
sample-data
src
templates
vendor
composer.json
license.txt
readme.txt
uninstall.php
woocommerce.php
woocommerce/includes/payment-tokens/class-wc-payment-token-cc.php
2021-12-10 12:03:04 +00:00

199 lines
4.5 KiB
PHP

<?php
/**
* Class WC_Payment_Token_CC file.
*
* @package WooCommerce\PaymentTokens
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* WooCommerce Credit Card Payment Token.
*
* Representation of a payment token for credit cards.
*
* @class WC_Payment_Token_CC
* @version 3.0.0
* @since 2.6.0
* @package WooCommerce\PaymentTokens
*/
class WC_Payment_Token_CC extends WC_Payment_Token {
/**
* Token Type String.
*
* @var string
*/
protected $type = 'CC';
/**
* Stores Credit Card payment token data.
*
* @var array
*/
protected $extra_data = array(
'last4' => '',
'expiry_year' => '',
'expiry_month' => '',
'card_type' => '',
);
/**
* Get type to display to user.
*
* @since 2.6.0
* @param string $deprecated Deprecated since WooCommerce 3.0.
* @return string
*/
public function get_display_name( $deprecated = '' ) {
$display = sprintf(
/* translators: 1: credit card type 2: last 4 digits 3: expiry month 4: expiry year */
__( '%1$s ending in %2$s (expires %3$s/%4$s)', 'woocommerce' ),
wc_get_credit_card_type_label( $this->get_card_type() ),
$this->get_last4(),
$this->get_expiry_month(),
substr( $this->get_expiry_year(), 2 )
);
return $display;
}
/**
* Hook prefix
*
* @since 3.0.0
*/
protected function get_hook_prefix() {
return 'woocommerce_payment_token_cc_get_';
}
/**
* 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;
}
/**
* Returns the card type (mastercard, visa, ...).
*
* @since 2.6.0
* @param string $context What the value is for. Valid values are view and edit.
* @return string Card type
*/
public function get_card_type( $context = 'view' ) {
return $this->get_prop( 'card_type', $context );
}
/**
* Set the card type (mastercard, visa, ...).
*
* @since 2.6.0
* @param string $type Credit card type (mastercard, visa, ...).
*/
public function set_card_type( $type ) {
$this->set_prop( 'card_type', $type );
}
/**
* Returns the card expiration year (YYYY).
*
* @since 2.6.0
* @param string $context What the value is for. Valid values are view and edit.
* @return string Expiration year
*/
public function get_expiry_year( $context = 'view' ) {
return $this->get_prop( 'expiry_year', $context );
}
/**
* Set the expiration year for the card (YYYY format).
*
* @since 2.6.0
* @param string $year Credit card expiration year.
*/
public function set_expiry_year( $year ) {
$this->set_prop( 'expiry_year', $year );
}
/**
* Returns the card expiration month (MM).
*
* @since 2.6.0
* @param string $context What the value is for. Valid values are view and edit.
* @return string Expiration month
*/
public function get_expiry_month( $context = 'view' ) {
return $this->get_prop( 'expiry_month', $context );
}
/**
* Set the expiration month for the card (formats into MM format).
*
* @since 2.6.0
* @param string $month Credit card expiration month.
*/
public function set_expiry_month( $month ) {
$this->set_prop( 'expiry_month', str_pad( $month, 2, '0', STR_PAD_LEFT ) );
}
/**
* Returns the last four digits.
*
* @since 2.6.0
* @param string $context What the value is for. Valid values are view and edit.
* @return string Last 4 digits
*/
public function get_last4( $context = 'view' ) {
return $this->get_prop( 'last4', $context );
}
/**
* Set the last four digits.
*
* @since 2.6.0
* @param string $last4 Credit card last four digits.
*/
public function set_last4( $last4 ) {
$this->set_prop( 'last4', $last4 );
}
}