Code Duplication    Length = 43-47 lines in 2 locations

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

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