class-wc-payment-token-echeck.php
106 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WC_Payment_Token_eCheck file. |
| 4 | * |
| 5 | * @package WooCommerce\PaymentTokens |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * WooCommerce eCheck Payment Token. |
| 14 | * |
| 15 | * Representation of a payment token for eChecks. |
| 16 | * |
| 17 | * @class WC_Payment_Token_ECheck |
| 18 | * @version 3.0.0 |
| 19 | * @since 2.6.0 |
| 20 | * @package WooCommerce\PaymentTokens |
| 21 | */ |
| 22 | class WC_Payment_Token_ECheck extends WC_Payment_Token { |
| 23 | |
| 24 | /** |
| 25 | * Token Type String. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | protected $type = 'eCheck'; |
| 30 | |
| 31 | /** |
| 32 | * Stores eCheck payment token data. |
| 33 | * |
| 34 | * @var array |
| 35 | */ |
| 36 | protected $extra_data = array( |
| 37 | 'last4' => '', |
| 38 | ); |
| 39 | |
| 40 | /** |
| 41 | * Get type to display to user. |
| 42 | * |
| 43 | * @since 2.6.0 |
| 44 | * @param string $deprecated Deprecated since WooCommerce 3.0. |
| 45 | * @return string |
| 46 | */ |
| 47 | public function get_display_name( $deprecated = '' ) { |
| 48 | $display = sprintf( |
| 49 | /* translators: 1: last 4 digits */ |
| 50 | __( 'eCheck ending in %1$s', 'woocommerce' ), |
| 51 | $this->get_last4() |
| 52 | ); |
| 53 | return $display; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Hook prefix |
| 58 | * |
| 59 | * @since 3.0.0 |
| 60 | */ |
| 61 | protected function get_hook_prefix() { |
| 62 | return 'woocommerce_payment_token_echeck_get_'; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Validate eCheck payment tokens. |
| 67 | * |
| 68 | * These fields are required by all eCheck payment tokens: |
| 69 | * last4 - string Last 4 digits of the check |
| 70 | * |
| 71 | * @since 2.6.0 |
| 72 | * @return boolean True if the passed data is valid |
| 73 | */ |
| 74 | public function validate() { |
| 75 | if ( false === parent::validate() ) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | if ( ! $this->get_last4( 'edit' ) ) { |
| 80 | return false; |
| 81 | } |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the last four digits. |
| 87 | * |
| 88 | * @since 2.6.0 |
| 89 | * @param string $context What the value is for. Valid values are view and edit. |
| 90 | * @return string Last 4 digits |
| 91 | */ |
| 92 | public function get_last4( $context = 'view' ) { |
| 93 | return $this->get_prop( 'last4', $context ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Set the last four digits. |
| 98 | * |
| 99 | * @since 2.6.0 |
| 100 | * @param string $last4 eCheck last four digits. |
| 101 | */ |
| 102 | public function set_last4( $last4 ) { |
| 103 | $this->set_prop( 'last4', $last4 ); |
| 104 | } |
| 105 | } |
| 106 |