Code Duplication    Length = 39-43 lines in 2 locations

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

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