Code Duplication    Length = 43-47 lines in 2 locations

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

@@ 537-583 (lines=47) @@
534
	 * @since 4.0.0
535
	 * @version 4.0.0
536
	 */
537
	public function display_payment_request_button_html() {
538
		global $post;
539
540
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
541
542
		if ( ! isset( $gateways['stripe'] ) ) {
543
			return;
544
		}
545
546
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
547
			return;
548
		}
549
550
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
551
			return;
552
		}
553
554
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
555
			return;
556
		}
557
558
		if ( is_product() ) {
559
			$product = wc_get_product( $post->ID );
560
561
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
562
				return;
563
			}
564
565
			// Pre Orders charge upon release not supported.
566
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
567
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
568
				return;
569
			}
570
		} else {
571
			if ( ! $this->allowed_items_in_cart() ) {
572
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
573
				return;
574
			}
575
		}
576
		?>
577
		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;">
578
			<div id="wc-stripe-payment-request-button">
579
				<!-- A Stripe Element will be inserted here. -->
580
			</div>
581
		</div>
582
		<?php
583
	}
584
585
	/**
586
	 * Display payment request button separator.
@@ 591-633 (lines=43) @@
588
	 * @since 4.0.0
589
	 * @version 4.0.0
590
	 */
591
	public function display_payment_request_button_separator_html() {
592
		global $post;
593
594
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
595
596
		if ( ! isset( $gateways['stripe'] ) ) {
597
			return;
598
		}
599
600
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
601
			return;
602
		}
603
604
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
605
			return;
606
		}
607
608
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
609
			return;
610
		}
611
612
		if ( is_product() ) {
613
			$product = wc_get_product( $post->ID );
614
615
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
616
				return;
617
			}
618
619
			// Pre Orders charge upon release not supported.
620
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
621
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
622
				return;
623
			}
624
		} else {
625
			if ( ! $this->allowed_items_in_cart() ) {
626
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
627
				return;
628
			}
629
		}
630
		?>
631
		<p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
632
		<?php
633
	}
634
635
	/**
636
	 * Log errors coming from Payment Request