Code Duplication    Length = 43-47 lines in 2 locations

includes/payment-methods/class-wc-stripe-payment-request.php 2 locations

@@ 445-491 (lines=47) @@
442
	 * @since 4.0.0
443
	 * @version 4.0.0
444
	 */
445
	public function display_payment_request_button_html() {
446
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
447
448
		if ( ! isset( $gateways['stripe'] ) ) {
449
			return;
450
		}
451
452
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
453
			return;
454
		}
455
456
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
457
			return;
458
		}
459
460
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
461
			return;
462
		}
463
464
		if ( is_product() ) {
465
			global $post;
466
467
			$product = wc_get_product( $post->ID );
468
469
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
470
				return;
471
			}
472
473
			// Pre Orders charge upon release not supported.
474
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
475
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
476
				return;
477
			}
478
		} else {
479
			if ( ! $this->allowed_items_in_cart() ) {
480
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
481
				return;
482
			}
483
		}
484
		?>
485
		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;">
486
			<div id="wc-stripe-payment-request-button">
487
				<!-- A Stripe Element will be inserted here. -->
488
			</div>
489
		</div>
490
		<?php
491
	}
492
493
	/**
494
	 * Display payment request button separator.
@@ 499-541 (lines=43) @@
496
	 * @since 4.0.0
497
	 * @version 4.0.0
498
	 */
499
	public function display_payment_request_button_separator_html() {
500
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
501
502
		if ( ! isset( $gateways['stripe'] ) ) {
503
			return;
504
		}
505
506
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
507
			return;
508
		}
509
510
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
511
			return;
512
		}
513
514
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
515
			return;
516
		}
517
518
		if ( is_product() ) {
519
			global $post;
520
521
			$product = wc_get_product( $post->ID );
522
523
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
524
				return;
525
			}
526
527
			// Pre Orders charge upon release not supported.
528
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
529
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
530
				return;
531
			}
532
		} else {
533
			if ( ! $this->allowed_items_in_cart() ) {
534
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
535
				return;
536
			}
537
		}
538
		?>
539
		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p>
540
		<?php
541
	}
542
543
	/**
544
	 * Log errors coming from Payment Request