PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.4.3
WooCommerce Square v5.4.3
5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Framework / PaymentGateway / Payment_Gateway_My_Payment_Methods.php
woocommerce-square / includes / Framework / PaymentGateway Last commit date
Admin 1 month ago Api 2 years ago ApplePay 4 months ago Handlers 11 months ago Integrations 1 year ago PaymentTokens 1 year ago Payment_Gateway.php 4 months ago Payment_Gateway_Direct.php 1 year ago Payment_Gateway_Helper.php 3 years ago Payment_Gateway_My_Payment_Methods.php 3 years ago Payment_Gateway_Payment_Form.php 4 months ago Payment_Gateway_Plugin.php 3 months ago Payment_Gateway_Privacy.php 1 year ago
Payment_Gateway_My_Payment_Methods.php
185 lines
1 <?php
2 /**
3 * WooCommerce Payment Gateway Framework
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@skyverge.com so we can send you a copy immediately.
12 *
13 * @since 3.0.0
14 * @author WooCommerce / SkyVerge
15 * @copyright Copyright (c) 2013-2019, SkyVerge, Inc.
16 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
17 *
18 * Modified by WooCommerce on 15 December 2021.
19 */
20
21 namespace WooCommerce\Square\Framework\PaymentGateway;
22
23 use WooCommerce\Square\Framework\PaymentGateway\PaymentTokens\Payment_Gateway_Payment_Token;
24
25 defined( 'ABSPATH' ) || exit;
26
27 /**
28 * My Payment Methods Class
29 *
30 * Renders the My Payment Methods table on the My Account page and handles
31 * any associated actions (deleting a payment method, etc)
32 *
33 * @since 3.0.0
34 */
35 class Payment_Gateway_My_Payment_Methods {
36
37
38 /** @var Payment_Gateway_Plugin */
39 protected $plugin;
40
41 /** @var Payment_Gateway_Payment_Token[] array of token objects */
42 protected $tokens;
43
44 /** @var Payment_Gateway_Payment_Token[] array of token objects */
45 protected $credit_card_tokens;
46
47 /** @var Payment_Gateway_Payment_Token[] array of token objects */
48 protected $echeck_tokens;
49
50 /** @var bool true if there are tokens */
51 protected $has_tokens;
52
53
54 /**
55 * Setup Class
56 *
57 * Note: this constructor executes during the `wp` action
58 *
59 * @param Payment_Gateway_Plugin $plugin gateway plugin
60 * @since 3.0.0
61 */
62 public function __construct( $plugin ) {
63
64 $this->plugin = $plugin;
65
66 add_filter( 'woocommerce_account_payment_methods_columns', array( $this, 'filter_payment_method_columns' ) );
67 add_action( 'woocommerce_account_payment_methods_column_method', array( $this, 'render_payment_method_method_data' ) );
68 add_action( 'woocommerce_account_payment_methods_column_details', array( $this, 'render_payment_method_details_data' ) );
69 }
70
71 /** Payment Method actions ************************************************/
72
73 /**
74 * Adds the details column next to method.
75 *
76 * @param array $columns Array of columns for payment methods.
77 * @return array
78 */
79 public function filter_payment_method_columns( $columns ) {
80 $filtered_columns = array();
81
82 foreach ( $columns as $slug => $title ) {
83 if ( 'method' === $slug ) {
84 $filtered_columns[ $slug ] = $title;
85 $filtered_columns['details'] = '&nbsp;';
86 } else {
87 $filtered_columns[ $slug ] = $title;
88 }
89 }
90
91 return $filtered_columns;
92 }
93
94 /**
95 * Renders the card brand.
96 *
97 * @param array $method Holds data about the payment method.
98 */
99 public function render_payment_method_method_data( $method ) {
100 echo esc_html( $method['method']['brand'] );
101 }
102
103 /**
104 * Renders card details.
105 *
106 * @param array $method Holds data about the payment method.
107 */
108 public function render_payment_method_details_data( $method ) {
109 $card_brand = $method['method']['brand'];
110 $card_image_url = wc_square()->get_gateway()->get_payment_method_image_url( $card_brand );
111 ?>
112
113 <?php if ( ! empty( $card_image_url ) ) : ?>
114 <img
115 src="<?php echo esc_url( $card_image_url ); ?>"
116 width="40"
117 height="25"
118 alt="<?php echo esc_attr( $card_brand ); ?>"
119 title="<?php echo esc_attr( $card_brand ); ?>"
120 >
121 <?php endif; ?>
122 <span>&bull; &bull; &bull;<?php echo esc_html( $method['method']['last4'] ); ?></span>
123 <?php
124 }
125
126 /**
127 * Redirect back to the Payment Methods (WC 2.6+) or My Account page
128 *
129 * @since 3.0.0
130 */
131 protected function redirect_to_my_account() {
132
133 wp_safe_redirect( wc_get_account_endpoint_url( 'payment-methods' ) );
134 exit;
135 }
136
137
138 /**
139 * Return the gateway plugin, primarily a convenience method to other actors
140 * using filters
141 *
142 * @since 3.0.0
143 *
144 * @return Payment_Gateway_Plugin
145 */
146 public function get_plugin() {
147
148 return $this->plugin;
149 }
150
151
152 /**
153 * Returns true if at least one of the plugin's gateways supports the
154 * add new payment method feature
155 *
156 * @since 3.0.0
157 * @return bool
158 */
159 protected function supports_add_payment_method() {
160
161 foreach ( $this->get_plugin()->get_gateways() as $gateway ) {
162
163 if ( $gateway->is_direct_gateway() && $gateway->supports_add_payment_method() ) {
164 return true;
165 }
166 }
167
168 return false;
169 }
170
171
172 /**
173 * Determines if we're viewing the My Account -> Payment Methods page.
174 *
175 * @since 3.0.0
176 *
177 * @return bool
178 */
179 protected function is_payment_methods_page() {
180 global $wp;
181
182 return is_user_logged_in() && is_account_page() && isset( $wp->query_vars['payment-methods'] );
183 }
184 }
185