class-wc-payment-token-echeck.php 2.0 KB

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