woocommerce-square
/
includes
/
Framework
/
PaymentGateway
/
PaymentTokens
/
Square_Credit_Card_Payment_Token.php
Payment_Gateway_Payment_Token.php
3 years ago
Payment_Gateway_Payment_Tokens_Handler.php
1 year ago
Square_Credit_Card_Payment_Token.php
3 years ago
Square_Credit_Card_Payment_Token.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WooCommerce\Square\Framework\PaymentGateway\PaymentTokens; |
| 4 | |
| 5 | /** |
| 6 | * Square Payment Gateway Token |
| 7 | * |
| 8 | * Represents a credit card payment token. |
| 9 | * |
| 10 | * @since 3.8.0 |
| 11 | */ |
| 12 | class Square_Credit_Card_Payment_Token extends \WC_Payment_Token_CC { |
| 13 | public function __construct( $token = '' ) { |
| 14 | $this->extra_data = array_merge( |
| 15 | $this->extra_data, |
| 16 | array( |
| 17 | 'environment' => '', |
| 18 | 'billing_hash' => '', |
| 19 | 'nickname' => '', |
| 20 | ) |
| 21 | ); |
| 22 | |
| 23 | parent::__construct( $token ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Setter for a card's encironment. |
| 28 | * |
| 29 | * @param string $env Environment of the Square account. |
| 30 | * @since 3.8.0 |
| 31 | */ |
| 32 | public function set_environment( $env = '' ) { |
| 33 | $this->set_prop( 'environment', $env ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Setter for billing hash. |
| 38 | * |
| 39 | * @param string $value The billing hash string. |
| 40 | * @since 3.8.0 |
| 41 | */ |
| 42 | public function set_billing_hash( $value = '' ) { |
| 43 | $this->set_prop( 'billing_hash', $value ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Setter for a card's nickname. |
| 48 | * |
| 49 | * @param string $value The billing hash string. |
| 50 | * @since 3.8.0 |
| 51 | */ |
| 52 | public function set_nickname( $value = '' ) { |
| 53 | $this->set_prop( 'nickname', $value ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Getter for a card's environment. |
| 58 | * |
| 59 | * @since 3.8.0 |
| 60 | * @return string |
| 61 | */ |
| 62 | public function get_environment( $context = 'view' ) { |
| 63 | return $this->get_prop( 'environment', $context ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Getter for billing hash. |
| 68 | * |
| 69 | * @since 3.8.0 |
| 70 | * @return string |
| 71 | */ |
| 72 | public function get_billing_hash( $context = 'view' ) { |
| 73 | return $this->get_prop( 'billing_hash', $context ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get expiry date. |
| 78 | * |
| 79 | * @since 3.8.0 |
| 80 | * @return string |
| 81 | */ |
| 82 | public function get_exp_date() { |
| 83 | $expiry_month = $this->get_expiry_month(); |
| 84 | $expiry_year = $this->get_expiry_year(); |
| 85 | |
| 86 | $expiry_date = $expiry_month . '/' . substr( $expiry_year, -2 ); |
| 87 | |
| 88 | return $expiry_date; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Getter for a card's nickname. |
| 93 | * |
| 94 | * @param string $value The billing hash string. |
| 95 | * @since 3.8.0 |
| 96 | */ |
| 97 | public function get_nickname( $context = 'view' ) { |
| 98 | $this->get_prop( 'nickname', $context ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Retrieves array of Square Payment Tokens. |
| 103 | * |
| 104 | * @param WC_Payment_Token_CC[] $tokens Array of tokens |
| 105 | * @since 3.8.0 |
| 106 | * |
| 107 | * @return Square_Credit_Card_Payment_Token[]; |
| 108 | */ |
| 109 | public static function get_square_customer_tokens( $tokens = array() ) { |
| 110 | $square_customer_tokens = array(); |
| 111 | |
| 112 | /** @var \WC_Payment_Token_CC $token */ |
| 113 | foreach ( $tokens as $token_id => $token ) { |
| 114 | if ( \WooCommerce\Square\Plugin::GATEWAY_ID !== $token->get_gateway_id() ) { |
| 115 | continue; |
| 116 | } |
| 117 | |
| 118 | $square_customer_tokens[ $token_id ] = new Square_Credit_Card_Payment_Token( $token ); |
| 119 | } |
| 120 | |
| 121 | return $square_customer_tokens; |
| 122 | } |
| 123 | } |
| 124 |