PluginProbe
WooCommerce Square / 4.4.0
WooCommerce Square v4.4.0
5.5.0 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 All 132 releases
woocommerce-square / includes / Plugin.php

Plugin.php in WooCommerce Square 4.4.0, at includes/Plugin.php

913 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Square
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@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
22 */
23
24 namespace WooCommerce\Square;
25
26 defined( 'ABSPATH' ) || exit;
27
28 use WooCommerce\Square\Framework\PaymentGateway\Payment_Gateway_Plugin;
29 use WooCommerce\Square\Framework\Square_Helper;
30 use WooCommerce\Square\Handlers\Background_Job;
31 use WooCommerce\Square\Handlers\Async_Request;
32 use WooCommerce\Square\Handlers\Email;
33 use WooCommerce\Square\Handlers\Order;
34 use WooCommerce\Square\Handlers\Product;
35 use WooCommerce\Square\Handlers\Sync;
36 use WooCommerce\Square\Handlers\Products;
37
38 /**
39 * The main plugin class.
40 *
41 * @since 2.0.0
42 */
43 class Plugin extends Payment_Gateway_Plugin {
44
45
46 /** plugin version number */
47 const VERSION = WC_SQUARE_PLUGIN_VERSION;
48
49 /** plugin ID */
50 const PLUGIN_ID = 'square';
51
52 /** string gateway ID */
53 const GATEWAY_ID = 'square_credit_card';
54
55
56 /** @var Plugin plugin instance */
57 protected static $instance;
58
59 /** @var Settings settings handler instance */
60 private $settings_handler;
61
62 /** @var Handlers\Connection connection handler instance */
63 private $connection_handler;
64
65 /** @var Admin admin handler instance */
66 private $admin_handler;
67
68 /** @var Sync sync handler instance */
69 private $sync_handler;
70
71 /** @var Background_Job background handler instance */
72 private $background_job_handler;
73
74 /** @var AJAX handler instance */
75 private $ajax_handler;
76
77 /** @var Email emails handler */
78 private $email_handler;
79
80 /** @var Order orders handler */
81 private $order_handler;
82
83 /** @var Products products handler */
84 private $products_handler;
85
86 /** @var Async_Request Asynchronous request handler */
87 private $async_request_handler;
88
89 /**
90 * Constructs the plugin.
91 *
92 * @since 2.0.0
93 */
94 public function __construct() {
95
96 parent::__construct(
97 self::PLUGIN_ID,
98 self::VERSION,
99 array(
100 'text_domain' => 'woocommerce-square',
101 'gateways' => array( self::GATEWAY_ID => Gateway::class ),
102 'require_ssl' => true,
103 'supports' => array(
104 self::FEATURE_CAPTURE_CHARGE,
105 self::FEATURE_CUSTOMER_ID,
106 self::FEATURE_MY_PAYMENT_METHODS,
107 ),
108 'dependencies' => array(
109 'php_extensions' => array( 'curl', 'json', 'mbstring' ),
110 ),
111 )
112 );
113
114 $this->includes();
115
116 /**
117 * Fires upon plugin loaded (legacy hook).
118 *
119 * @since 1.0.0
120 */
121 do_action( 'wc_square_loaded' );
122
123 add_action( 'woocommerce_register_taxonomy', array( $this, 'init_taxonomies' ) );
124 add_action( 'admin_notices', array( $this, 'add_admin_notices' ) );
125 add_filter( 'woocommerce_locate_template', array( $this, 'locate_template' ), 20, 3 );
126 add_filter( 'woocommerce_locate_core_template', array( $this, 'locate_template' ), 20, 3 );
127 }
128
129
130 /**
131 * Includes required classes.
132 *
133 * @since 2.0.0
134 */
135 private function includes() {
136
137 $this->connection_handler = new Handlers\Connection( $this );
138
139 $this->sync_handler = new Sync( $this );
140
141 // background export must be loaded all the time, because otherwise background jobs simply won't work
142 require_once $this->get_framework_path() . '/Utilities/WP_Background_Job_Handler.php';
143
144 $this->background_job_handler = new Background_Job();
145
146 $this->ajax_handler = new AJAX();
147
148 $this->email_handler = new Email();
149
150 $this->order_handler = new Order();
151
152 if ( class_exists( '\WooCommerce\Square\Handlers\Async_Request' ) ) {
153 $this->async_request_handler = new Async_Request();
154 }
155 }
156
157
158 /**
159 * Adds API request logging.
160 *
161 * @internal
162 *
163 * @since 2.0.0
164 */
165 public function add_api_request_logging() {
166
167 if ( ! has_action( 'wc_square_api_request_performed' ) ) {
168 add_action( 'wc_square_api_request_performed', array( $this, 'log_api_request' ), 10, 2 );
169 }
170 }
171
172
173 /**
174 * Logs an API request & response.
175 *
176 * @since 2.0.0
177 *
178 * @param array $request request data
179 * @param array $response response data
180 * @param string|null $log_id log ID
181 */
182 public function log_api_request( $request, $response, $log_id = null ) {
183
184 if ( $this->get_settings_handler() && $this->get_settings_handler()->is_debug_enabled() ) {
185 parent::log_api_request( $request, $response, $log_id );
186 }
187 }
188
189
190 /**
191 * If debug logging is enabled, saves errors or messages to Square Log
192 *
193 * @since 2.2.4
194 * @param string $message error or message to save to log
195 * @param string $log_id optional log id to segment the files by, defaults to plugin id
196 */
197 public function log( $message, $log_id = null ) {
198
199 if ( $this->get_settings_handler() && $this->get_settings_handler()->is_debug_enabled() ) {
200 parent::log( $message, $log_id );
201 }
202 }
203
204
205 /**
206 * Initializes the lifecycle handler.
207 *
208 * @since 2.0.0
209 */
210 public function init_lifecycle_handler() {
211
212 $this->lifecycle_handler = new Lifecycle( $this );
213 }
214
215
216 /**
217 * Registers custom taxonomies.
218 *
219 * @internal
220 *
221 * @since 2.0.0
222 */
223 public function init_taxonomies() {
224
225 Product::init_taxonomies();
226 }
227
228
229 /**
230 * Initializes the general plugin functionality.
231 *
232 * @since 2.0.0
233 */
234 public function init_plugin() {
235
236 $this->settings_handler = new Settings( $this );
237 $this->products_handler = new Products( $this );
238
239 if ( ! $this->admin_handler && is_admin() ) {
240 $this->admin_handler = new Admin( $this );
241 }
242
243 /**
244 * @see wc_square_initialized
245 * @since 2.0.0
246 */
247 do_action( 'wc_square_initialized' );
248 }
249
250
251 /**
252 * Locates the WooCommerce template files from our templates directory.
253 *
254 * @internal
255 *
256 * @since 2.0.0
257 *
258 * @param string $template already found template
259 * @param string $template_name searchable template name
260 * @param string $template_path template path
261 * @return string search result for the template
262 */
263 public function locate_template( $template, $template_name, $template_path ) {
264
265 // only keep looking if no custom theme template was found
266 // or if a default WooCommerce template was found
267 if ( ! $template || Square_Helper::str_starts_with( $template, WC()->plugin_path() ) ) {
268
269 // set the path to our templates directory
270 $plugin_path = $this->get_plugin_path() . '/templates/';
271
272 // if a template is found, make it so
273 if ( is_readable( $plugin_path . $template_name ) ) {
274 $template = $plugin_path . $template_name;
275 }
276 }
277
278 return $template;
279 }
280
281
282 /** Admin methods *************************************************************************************************/
283
284
285 /**
286 * Adds admin notices.
287 *
288 * @since 2.0.0
289 */
290 public function add_admin_notices() {
291
292 // show any one-off messages
293 $this->get_message_handler()->show_messages();
294
295 // display a notice if the auto-refresh failed
296 if ( get_option( 'wc_square_refresh_failed', false ) ) {
297
298 $message = sprintf(
299 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
300 __( 'Heads up! There may be a problem with your connection to Square. In order to continue accepting payments, please %1$sdisconnect and re-connect your site%2$s.', 'woocommerce-square' ),
301 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
302 '</a>'
303 );
304
305 $this->get_admin_notice_handler()->add_admin_notice(
306 $message,
307 'refresh-failed',
308 array(
309 'dismissible' => false,
310 'notice_class' => 'notice-warning',
311 )
312 );
313 }
314
315 if ( $this->get_settings_handler()->is_connected() ) {
316
317 $message = '<strong>' . __( 'You are connected to Square!', 'woocommerce-square' ) . '</strong>';
318
319 // prompt to set a location if not set
320 if ( ! $this->get_settings_handler()->get_location_id() ) {
321
322 if ( $this->is_plugin_settings() ) {
323
324 $instruction = __( 'To get started, set your business location.', 'woocommerce-square' );
325
326 } else {
327
328 $instruction = sprintf(
329 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
330 __( 'Visit the %1$splugin settings%2$s to set your business location.', 'woocommerce-square' ),
331 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
332 '</a>'
333 );
334 }
335
336 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
337
338 } elseif ( ! $this->get_sync_handler()->get_last_synced_at() && $this->get_settings_handler()->is_product_sync_enabled() ) {
339
340 $message = __( 'You are ready to sync products!', 'woocommerce-square' );
341
342 if ( ! empty( Product::get_products_synced_with_square() ) ) {
343
344 $instruction = sprintf(
345 /* translators: Placeholders: %1$s - <strong> tag, %2$s - product count, %3$s - </strong> tag, %4$s - <a> tag, %5$s - </a> tag */
346 __( '%1$s%2$d products%3$s are marked "sync with Square". %4$sStart a new sync now &raquo;%5$s', 'woocommerce-square' ),
347 '<strong>',
348 count( Product::get_products_synced_with_square() ),
349 '</strong>',
350 '<a href="' . esc_url( add_query_arg( 'section', 'update', $this->get_settings_url() ) ) . '">',
351 '</a>'
352 );
353
354 } else {
355
356 $instruction = sprintf(
357 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
358 __( '%1$sNo products%2$s are marked "sync with Square". %3$sUpdate your products to sync data &raquo;%4$s', 'woocommerce-square' ),
359 '<strong>',
360 '</strong>',
361 '<a href="' . esc_url( admin_url( 'edit.php?post_type=product' ) ) . '">',
362 '</a>'
363 );
364 }
365
366 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'set-location' );
367 }
368
369 // a notice for when WC stock handling is globally disabled
370 if ( 'yes' !== get_option( 'woocommerce_manage_stock' ) && $this->get_settings_handler()->is_inventory_sync_enabled() ) {
371
372 $message = sprintf(
373 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
374 __( 'Heads up! Square is configured to sync product inventory, but WooCommerce stock management is disabled. Please %1$senable stock management%2$s to ensure product inventory counts are kept in sync.', 'woocommerce-square' ),
375 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) ) . '">',
376 '</a>'
377 );
378
379 $this->get_admin_notice_handler()->add_admin_notice(
380 $message,
381 'enable-wc-sync',
382 array(
383 'notice_class' => 'notice-warning',
384 )
385 );
386 }
387 } else {
388
389 if ( $this->is_plugin_settings() ) {
390
391 $instruction = __( 'To get started, connect with Square.', 'woocommerce-square' );
392
393 } else {
394
395 $instruction = sprintf(
396 /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
397 __( 'To get started, %1$sconnect with Square &raquo;%2$s', 'woocommerce-square' ),
398 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
399 '</a>'
400 );
401 }
402
403 $message = sprintf(
404 /* translators: Placeholders: %1$s - plugin name */
405 __( 'Thanks for installing %1$s!', 'woocommerce-square' ),
406 esc_html( $this->get_plugin_name() )
407 );
408
409 $this->get_admin_notice_handler()->add_admin_notice( $message . ' ' . $instruction, 'connect' );
410 }
411
412 // add a notice for out-of-bounds base locations
413 $this->add_base_location_admin_notice();
414
415 // add a notice when no refresh token is available
416 $this->add_missing_refresh_token_notice();
417
418 // add a tax-inclusive warning to product pages
419 $this->add_tax_inclusive_pricing_notice();
420
421 if ( get_option( 'wc_square_updated_to_2_0_0' ) ) {
422
423 $this->get_admin_notice_handler()->add_admin_notice(
424 sprintf(
425 /* translators: Placeholders: %1$s - plugin name, %2$ - plugin version number, %3$s - opening <a> HTML link tag, %4$s - closing </a> HTML link tag, %5$s - opening <a> HTML link tag, %6$s - closing </a> HTML link tag*/
426 esc_html__( '%1$s has been updated to version %2$s. In order to continue syncing product inventory, please make sure to disconnect and reconnect with Square from the %3$splugin settings%4$s and re-sync your products. Read more in the %5$supdated documentation%6$s.', 'woocommerce-square' ),
427 '<strong>' . esc_html( $this->get_plugin_name() ) . '</strong>',
428 $this->get_version(),
429 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
430 '</a>',
431 '<a href="' . esc_url( $this->get_documentation_url() ) . '">',
432 '</a>'
433 ),
434 'updated-to-v2',
435 array( 'notice_class' => 'notice-warning' )
436 );
437 }
438 }
439
440
441 /**
442 * Adds a notice for out-of-bounds base locations.
443 *
444 * @since 2.0.0
445 */
446 protected function add_base_location_admin_notice() {
447
448 $accepted_countries = array(
449 'US',
450 'CA',
451 'GB',
452 'AU',
453 'JP',
454 'IE',
455 'FR',
456 'ES',
457 );
458
459 $base_location = wc_get_base_location();
460
461 if ( isset( $base_location['country'] ) && ! in_array( $base_location['country'], $accepted_countries, true ) ) {
462
463 $this->get_admin_notice_handler()->add_admin_notice(
464 sprintf(
465 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - 2-character country code, %4$s - comma separated list of 2-character country codes */
466 __( '%1$sWooCommerce Square:%2$s Your base country is %3$s, but Square can’t accept transactions from merchants outside of %4$s.', 'woocommerce-square' ),
467 '<strong>',
468 '</strong>',
469 esc_html( $base_location['country'] ),
470 esc_html( Square_Helper::list_array_items( $accepted_countries ) )
471 ),
472 'wc-square-base-location',
473 array(
474 'notice_class' => 'notice-error',
475 )
476 );
477 }
478 }
479
480 /**
481 * Adds a notice if no refresh token has been cached.
482 *
483 * @since 2.0.5
484 */
485 protected function add_missing_refresh_token_notice() {
486 if ( $this->get_settings_handler()->is_sandbox() ) {
487 return;
488 }
489
490 $refresh_token = '';
491 $settings_handler = $this->get_settings_handler();
492
493 if ( method_exists( $settings_handler, 'get_access_token' ) ) {
494 $access_token = $settings_handler->get_access_token();
495 if ( empty( $access_token ) ) {
496 // We are already in a disconnected state, don't show the warning.
497 return;
498 }
499 }
500
501 if ( method_exists( $settings_handler, 'get_refresh_token' ) ) {
502 $refresh_token = $settings_handler->get_refresh_token();
503 }
504
505 if ( empty( $refresh_token ) ) {
506 $this->get_admin_notice_handler()->add_admin_notice(
507 sprintf(
508 /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s - <a> tag, %4$s - </a> tag */
509 __( '%1$sWooCommerce Square:%2$s Automatic refreshing of the connection to Square is inactive. Please disconnect and reconnect to resolve.', 'woocommerce-square' ),
510 '<strong>',
511 '</strong>'
512 ),
513 'wc-square-missing-refresh-token',
514 array(
515 'dismissible' => false,
516 'notice_class' => 'notice-error',
517 )
518 );
519 }
520 }
521
522
523 /**
524 * Adds a tax-inclusive admin warning to product pages.
525 *
526 * @since 2.0.0
527 */
528 protected function add_tax_inclusive_pricing_notice() {
529 global $typenow;
530
531 // only show on product edit pages when configured that prices include tax
532 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce not required, not writing any changes.
533 if ( 'product' === $typenow && isset( $_GET['action'], $_GET['post'] ) && 'edit' === $_GET['action'] && wc_prices_include_tax() && $this->get_settings_handler()->is_product_sync_enabled() ) {
534
535 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce not required, not writing any changes.
536 $product = wc_get_product( (int) $_GET['post'] );
537
538 // only show for products configured as taxable and sync with Square
539 if ( $product instanceof \WC_Product && $product->is_taxable() && Product::is_synced_with_square( $product ) ) {
540
541 $this->get_admin_notice_handler()->add_admin_notice(
542 sprintf(
543 /* translators: Placeholders: %1$s = <strong> tag, %2$s = </strong> tag */
544 __( '%1$sWooCommerce Square:%2$s Product prices are entered inclusive of tax, but Square does not support syncing tax-inclusive prices. Please make sure your Square tax rates match your WooCommerce tax rates.', 'woocommerce-square' ),
545 '<strong>',
546 '</strong>'
547 ),
548 'wc-square-tax-inclusive',
549 array(
550 'notice_class' => 'notice-warning',
551 )
552 );
553 }
554 }
555 }
556
557
558 /**
559 * Adds admin notices for currency issues.
560 *
561 * @since 2.0.0
562 */
563 protected function add_currency_admin_notices() {
564
565 parent::add_currency_admin_notices();
566
567 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce not required, only showing a notice.
568 if ( isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && $this->get_settings_handler()->is_connected() ) {
569
570 foreach ( $this->get_settings_handler()->get_locations() as $location ) {
571
572 if ( $this->get_settings_handler()->get_location_id() === $location->getId() && get_woocommerce_currency() !== $location->getCurrency() ) {
573
574 $this->get_admin_notice_handler()->add_admin_notice(
575 sprintf(
576 /* translators: Placeholders: %1$s = store currency, %2$s = configured Square business location currency, %3$s = <a> tag, %4$s = </a> tag, %5$s = <a> tag, %6$s = </a> tag */
577 __( 'Heads up! Your store currency is %1$s but your configured Square business location currency is %2$s, so payments cannot be processed. Please %3$schoose a different business location%4$s or change your %5$sshop currency%6$s.', 'woocommerce-square' ),
578 '<strong>' . esc_html( get_woocommerce_currency() ) . '</strong>',
579 '<strong>' . esc_html( $location->getCurrency() ) . '</strong>',
580 '<a href="' . esc_url( $this->get_settings_url() ) . '">',
581 '</a>',
582 '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings' ) ) . '">',
583 '</a>'
584 ),
585 'wc-square-currency-mismatch',
586 array(
587 'notice_class' => 'notice-error',
588 )
589 );
590 }
591 }
592 }
593 }
594
595
596 /** Helper methods ************************************************************************************************/
597
598
599 /**
600 * Returns an idempotency key to be used in Square API requests.
601 *
602 * @since 2.0.0
603 *
604 * @param string $key_input
605 * @param bool $append_key_input
606 * @return string
607 */
608 public function get_idempotency_key( $key_input = '', $append_key_input = true ) {
609
610 if ( '' === $key_input ) {
611 $key_input = uniqid( '', false );
612 }
613
614 /**
615 * Filters an idempotency key.
616 *
617 * @since 2.0.0
618 *
619 * @param string $key_input
620 */
621 return apply_filters( 'wc_square_idempotency_key', sha1( get_option( 'siteurl' ) . $key_input ) . ( $append_key_input ? ':' . $key_input : '' ) );
622 }
623
624
625 /** Conditional methods *******************************************************************************************/
626
627
628 /**
629 * Determines if viewing the plugin settings.
630 *
631 * @since 2.0.0
632 *
633 * @return bool
634 */
635 public function is_plugin_settings() {
636 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce note required, read-only check.
637 return parent::is_plugin_settings() || ( isset( $_GET['page'], $_GET['tab'] ) && 'wc-settings' === $_GET['page'] && self::PLUGIN_ID === $_GET['tab'] );
638 }
639
640 /**
641 * Determines if viewing the gateway settings.
642 *
643 * @since 2.3.0
644 *
645 * @return bool
646 */
647 public function is_gateway_settings() {
648 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce note required, read-only check.
649 return isset( $_GET['page'], $_GET['tab'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'checkout' === $_GET['tab'] && self::GATEWAY_ID === $_GET['section'];
650 }
651
652
653 /** Getter methods ************************************************************************************************/
654
655
656 /**
657 * Gets the main Square API handler.
658 *
659 * @since 2.0.0
660 *
661 * @param string|null $access_token API access token
662 * @return API
663 */
664 public function get_api( $access_token = null, $is_sandbox = null ) {
665
666 if ( ! $access_token ) {
667 $access_token = $this->get_settings_handler()->get_access_token();
668 }
669
670 if ( is_null( $is_sandbox ) ) {
671 $is_sandbox = $this->get_settings_handler()->is_sandbox();
672 }
673
674 return new API( $access_token, $is_sandbox );
675 }
676
677
678 /**
679 * Gets the connection handler.
680 *
681 * @since 2.0.0
682 *
683 * @return Handlers\Connection
684 */
685 public function get_connection_handler() {
686
687 return $this->connection_handler;
688 }
689
690
691 /**
692 * Gets the sync handler instance.
693 *
694 * @since 2.0.0
695 *
696 * @return Sync
697 */
698 public function get_sync_handler() {
699
700 return $this->sync_handler;
701 }
702
703
704 /**
705 * Gets the background sync handler instance.
706 *
707 * @since 2.0.0
708 *
709 * @return Background_Job
710 */
711 public function get_background_job_handler() {
712
713 return $this->background_job_handler;
714 }
715
716
717 /**
718 * Gets the settings handler instance.
719 *
720 * @since 2.0.0
721 *
722 * @return Settings
723 */
724 public function get_settings_handler() {
725
726 return $this->settings_handler;
727 }
728
729
730
731 /**
732 * Gets the admin handler instance.
733 *
734 * @since 2.0.0
735 *
736 * @return Admin|null
737 */
738 public function get_admin_handler() {
739
740 // throw a notice if calling before admin_init
741 Square_Helper::maybe_doing_it_early( 'admin_init', __METHOD__, '2.0.0' );
742
743 return $this->admin_handler;
744 }
745
746
747 /**
748 * Gets the email handler instance.
749 *
750 * @since 2.0.0
751 *
752 * @return Email
753 */
754 public function get_email_handler() {
755
756 return $this->email_handler;
757 }
758
759
760 /**
761 * Gets the order handler instance.
762 *
763 * @since 2.0.0
764 *
765 * @return Order
766 */
767 public function get_order_handler() {
768
769 return $this->order_handler;
770 }
771
772 /**
773 * Get the products handler instance/
774 *
775 * @since 2.0.8
776 *
777 * @return Products
778 */
779 public function get_products_handler() {
780 return $this->products_handler;
781 }
782
783 /**
784 * Gets the Asynchronous request handler instance.
785 *
786 * @since 4.1.0
787 *
788 * @return Async_Request
789 */
790 public function get_async_request_handler() {
791 return $this->async_request_handler;
792 }
793
794 /**
795 * Gets the plugin name.
796 *
797 * @since 2.0.0
798 *
799 * @return string
800 */
801 public function get_plugin_name() {
802
803 return __( 'WooCommerce Square', 'woocommerce-square' );
804 }
805
806
807 /**
808 * Gets the settings URL.
809 *
810 * @since 2.0.0
811 *
812 * @param null|string $gateway_id gateway ID
813 * @return string
814 */
815 public function get_settings_url( $gateway_id = null ) {
816
817 $params = array(
818 'page' => 'wc-settings',
819 'tab' => self::PLUGIN_ID,
820 );
821
822 // All usage of this return value has been escaped late.
823 // nosemgrep audit.php.wp.security.xss.query-arg
824 return add_query_arg( $params, admin_url( 'admin.php' ) );
825 }
826
827
828 /**
829 * Gets the sale page URL.
830 *
831 * @since 2.0.0
832 *
833 * @return string
834 */
835 public function get_sales_page_url() {
836
837 return 'https://woocommerce.com/products/square/';
838 }
839
840
841 /**
842 * Gets the documentation URL.
843 *
844 * @since 2.0.0
845 *
846 * @return string
847 */
848 public function get_documentation_url() {
849
850 return 'https://docs.woocommerce.com/document/woocommerce-square/';
851 }
852
853
854 /**
855 * Gets the plugin reviews page URL.
856 *
857 * Used for the 'Reviews' plugin action and review prompts.
858 *
859 * @since 2.1.7
860 *
861 * @return string
862 */
863 public function get_reviews_url() {
864
865 return $this->get_sales_page_url() ? $this->get_sales_page_url() . '#comments' : '';
866 }
867
868
869 /**
870 * Gets the support URL.
871 *
872 * @since 2.0.0
873 *
874 * @return string
875 */
876 public function get_support_url() {
877
878 return 'https://woocommerce.com/my-account/create-a-ticket/?select=1770503';
879 }
880
881
882 /**
883 * Gets __DIR__.
884 *
885 * @since 2.0.0
886 *
887 * @return string
888 */
889 protected function get_file() {
890
891 return __DIR__;
892 }
893
894
895 /**
896 * Gets the singleton instance of the plugin.
897 *
898 * @since 2.0.0
899 *
900 * @return Plugin
901 */
902 public static function instance() {
903
904 if ( null === self::$instance ) {
905 self::$instance = new self();
906 }
907
908 return self::$instance;
909 }
910
911
912 }
913