Code Duplication    Length = 43-47 lines in 2 locations

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

@@ 467-513 (lines=47) @@
464
	 * @since 4.0.0
465
	 * @version 4.0.0
466
	 */
467
	public function display_payment_request_button_html() {
468
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
469
470
		if ( ! isset( $gateways['stripe'] ) ) {
471
			return;
472
		}
473
474
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
475
			return;
476
		}
477
478
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
479
			return;
480
		}
481
482
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
483
			return;
484
		}
485
486
		if ( is_product() ) {
487
			global $post;
488
489
			$product = wc_get_product( $post->ID );
490
491
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
492
				return;
493
			}
494
495
			// Pre Orders charge upon release not supported.
496
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
497
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
498
				return;
499
			}
500
		} else {
501
			if ( ! $this->allowed_items_in_cart() ) {
502
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
503
				return;
504
			}
505
		}
506
		?>
507
		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;">
508
			<div id="wc-stripe-payment-request-button">
509
				<!-- A Stripe Element will be inserted here. -->
510
			</div>
511
		</div>
512
		<?php
513
	}
514
515
	/**
516
	 * Display payment request button separator.
@@ 521-563 (lines=43) @@
518
	 * @since 4.0.0
519
	 * @version 4.0.0
520
	 */
521
	public function display_payment_request_button_separator_html() {
522
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
523
524
		if ( ! isset( $gateways['stripe'] ) ) {
525
			return;
526
		}
527
528
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
529
			return;
530
		}
531
532
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
533
			return;
534
		}
535
536
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) {
537
			return;
538
		}
539
540
		if ( is_product() ) {
541
			global $post;
542
543
			$product = wc_get_product( $post->ID );
544
545
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
546
				return;
547
			}
548
549
			// Pre Orders charge upon release not supported.
550
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
551
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
552
				return;
553
			}
554
		} else {
555
			if ( ! $this->allowed_items_in_cart() ) {
556
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
557
				return;
558
			}
559
		}
560
		?>
561
		<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>
562
		<?php
563
	}
564
565
	/**
566
	 * Log errors coming from Payment Request