← Back
Editing: class-wc-payment-token-wcpay-link.php
<?php /** * Class WC_Payment_Token_WCPay_Link * * @package WooCommerce\Payments */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * WooCommerce Link Payment Token. * * Representation of a payment token for Link. * * @class WC_Payment_Token_WCPay_Link */ class WC_Payment_Token_WCPay_Link extends WC_Payment_Token { /** * Class Constant so other code can be unambiguous. * * @type string */ const TYPE = 'wcpay_link'; /** * The payment method type of this token. * * @var string */ protected $type = self::TYPE; /** * Stores Link payment token data. * * @var array */ protected $extra_data = [ 'email' => '', ]; /** * Get payment method type to display to user. * * @param string $_unused_deprecated Deprecated since WooCommerce 3.0. * @return string */ public function get_display_name( $_unused_deprecated = '' ) { $account_country = WC_Payments::get_gateway()->get_account_country(); return sprintf( /* translators: 1: Link brand name (Link or Onelink), 2: customer email. */ __( '%1$s email ending in %2$s', 'woocommerce-payments' ), \WCPay\PaymentMethods\Configs\Definitions\LinkDefinition::get_title( $account_country ), $this->get_redacted_email() ); } /** * Hook prefix. */ protected function get_hook_prefix() { return 'woocommerce_payments_token_wcpay_link_get_'; } /** * Returns the customer email. * * @param string $context What the value is for. Valid values are view and edit. * * @return string Customer email. */ public function get_email( $context = 'view' ) { return $this->get_prop( 'email', $context ); } /** * Set the customer email. * * @param string $email Customer email. */ public function set_email( $email ) { $this->set_prop( 'email', $email ); } /** * Returns redacted/shortened customer email * * @param string $context What the value is for. Valid values are view and edit. * @return string Redacted/shortened customer email. */ public function get_redacted_email( $context = 'view' ) { return $this->redact_email_address( $this->get_email( $context ) ); } /** * Returns the type of this payment token (CC, eCheck, or something else). * * @param string $_unused_deprecated Deprecated since WooCommerce 3.0. * @return string Payment Token Type (CC, eCheck) */ public function get_type( $_unused_deprecated = '' ) { return self::TYPE; } /** * Transforms email address into redacted/shortened format like ***xxxx@x.com. * Using shortened length of four characters will mimic CC last-4 digits of card number. * * @param string $email Email address. * @return string Redacted/shortened email address. */ private function redact_email_address( $email ) { $placeholder = '***'; $shortened_length = 4; list( $handle, $domain ) = explode( '@', $email ); $redacted_handle = strlen( $handle ) > $shortened_length ? substr( $handle, - $shortened_length ) : $handle; return "$placeholder$redacted_handle@$domain"; } }
Save File
Cancel