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