Code Duplication    Length = 43-47 lines in 2 locations

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

@@ 520-566 (lines=47) @@
517
	 * @since 4.0.0
518
	 * @version 4.0.0
519
	 */
520
	public function display_payment_request_button_html() {
521
		global $post;
522
523
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
524
525
		if ( ! isset( $gateways['stripe'] ) ) {
526
			return;
527
		}
528
529
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
530
			return;
531
		}
532
533
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
534
			return;
535
		}
536
537
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
538
			return;
539
		}
540
541
		if ( is_product() ) {
542
			$product = wc_get_product( $post->ID );
543
544
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
545
				return;
546
			}
547
548
			// Pre Orders charge upon release not supported.
549
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
550
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
551
				return;
552
			}
553
		} else {
554
			if ( ! $this->allowed_items_in_cart() ) {
555
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
556
				return;
557
			}
558
		}
559
		?>
560
		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;">
561
			<div id="wc-stripe-payment-request-button">
562
				<!-- A Stripe Element will be inserted here. -->
563
			</div>
564
		</div>
565
		<?php
566
	}
567
568
	/**
569
	 * Display payment request button separator.
@@ 574-616 (lines=43) @@
571
	 * @since 4.0.0
572
	 * @version 4.0.0
573
	 */
574
	public function display_payment_request_button_separator_html() {
575
		global $post;
576
577
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
578
579
		if ( ! isset( $gateways['stripe'] ) ) {
580
			return;
581
		}
582
583
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
584
			return;
585
		}
586
587
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) {
588
			return;
589
		}
590
591
		if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) {
592
			return;
593
		}
594
595
		if ( is_product() ) {
596
			$product = wc_get_product( $post->ID );
597
598
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
599
				return;
600
			}
601
602
			// Pre Orders charge upon release not supported.
603
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
604
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
605
				return;
606
			}
607
		} else {
608
			if ( ! $this->allowed_items_in_cart() ) {
609
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
610
				return;
611
			}
612
		}
613
		?>
614
		<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>
615
		<?php
616
	}
617
618
	/**
619
	 * Log errors coming from Payment Request