2016-02-02 17:08:32 +00:00
|
|
|
<?php
|
2018-03-07 17:55:04 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Payment_Token_eCheck file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PaymentTokens
|
|
|
|
*/
|
2016-02-02 17:08:32 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2018-03-07 17:55:04 +00:00
|
|
|
exit; // Exit if accessed directly.
|
2016-02-02 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-01 19:37:06 +00:00
|
|
|
* WooCommerce eCheck Payment Token.
|
2016-02-02 17:08:32 +00:00
|
|
|
*
|
2016-03-01 19:37:06 +00:00
|
|
|
* Representation of a payment token for eChecks.
|
2016-02-02 17:08:32 +00:00
|
|
|
*
|
2018-03-07 17:50:21 +00:00
|
|
|
* @class WC_Payment_Token_ECheck
|
2017-03-15 16:36:53 +00:00
|
|
|
* @version 3.0.0
|
2018-03-07 17:37:08 +00:00
|
|
|
* @since 2.6.0
|
|
|
|
* @package WooCommerce/PaymentTokens
|
2016-02-02 17:08:32 +00:00
|
|
|
*/
|
2018-03-07 17:50:21 +00:00
|
|
|
class WC_Payment_Token_ECheck extends WC_Payment_Token {
|
2016-02-02 17:08:32 +00:00
|
|
|
|
2018-03-07 17:55:04 +00:00
|
|
|
/**
|
|
|
|
* Token Type String.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-02-08 16:26:57 +00:00
|
|
|
protected $type = 'eCheck';
|
|
|
|
|
2017-03-14 19:21:51 +00:00
|
|
|
/**
|
|
|
|
* Stores eCheck payment token data.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $extra_data = array(
|
|
|
|
'last4' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get type to display to user.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2018-03-07 17:55:04 +00:00
|
|
|
* @param string $deprecated Deprecated since WooCommerce 3.0.
|
2017-03-14 19:21:51 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2017-03-15 15:21:02 +00:00
|
|
|
public function get_display_name( $deprecated = '' ) {
|
2018-05-03 10:00:07 +00:00
|
|
|
$display = sprintf(
|
|
|
|
/* translators: 1: credit card type 2: last 4 digits 3: expiry month 4: expiry year */
|
|
|
|
__( 'eCheck ending in %1$s', 'woocommerce' ),
|
|
|
|
$this->get_last4()
|
|
|
|
);
|
|
|
|
return $display;
|
2017-03-14 19:21:51 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 14:20:41 +00:00
|
|
|
/**
|
|
|
|
* Hook prefix
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-11-14 14:20:41 +00:00
|
|
|
*/
|
|
|
|
protected function get_hook_prefix() {
|
|
|
|
return 'woocommerce_payment_token_echeck_get_';
|
|
|
|
}
|
|
|
|
|
2016-06-06 19:04:45 +00:00
|
|
|
/**
|
2016-02-02 17:08:32 +00:00
|
|
|
* Validate eCheck payment tokens.
|
|
|
|
*
|
2016-02-08 16:26:57 +00:00
|
|
|
* These fields are required by all eCheck payment tokens:
|
2016-02-04 16:23:41 +00:00
|
|
|
* last4 - string Last 4 digits of the check
|
2016-02-02 17:08:32 +00:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2016-02-08 16:26:57 +00:00
|
|
|
* @return boolean True if the passed data is valid
|
2016-02-02 17:08:32 +00:00
|
|
|
*/
|
2016-02-08 18:33:53 +00:00
|
|
|
public function validate() {
|
2016-02-08 16:26:57 +00:00
|
|
|
if ( false === parent::validate() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-14 14:20:41 +00:00
|
|
|
if ( ! $this->get_last4( 'edit' ) ) {
|
2016-02-02 17:08:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-01 19:37:06 +00:00
|
|
|
* Returns the last four digits.
|
2016-11-14 14:20:41 +00:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2018-03-07 17:55:04 +00:00
|
|
|
* @param string $context What the value is for. Valid values are view and edit.
|
2016-02-02 17:08:32 +00:00
|
|
|
* @return string Last 4 digits
|
|
|
|
*/
|
2016-11-14 14:20:41 +00:00
|
|
|
public function get_last4( $context = 'view' ) {
|
2017-03-14 19:21:51 +00:00
|
|
|
return $this->get_prop( 'last4', $context );
|
2016-02-02 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-01 19:37:06 +00:00
|
|
|
* Set the last four digits.
|
2018-03-07 17:37:08 +00:00
|
|
|
*
|
2016-02-02 17:08:32 +00:00
|
|
|
* @since 2.6.0
|
2018-03-07 17:55:04 +00:00
|
|
|
* @param string $last4 eCheck last four digits.
|
2016-02-02 17:08:32 +00:00
|
|
|
*/
|
|
|
|
public function set_last4( $last4 ) {
|
2017-03-14 19:21:51 +00:00
|
|
|
$this->set_prop( 'last4', $last4 );
|
2016-02-02 17:08:32 +00:00
|
|
|
}
|
|
|
|
}
|