Code Duplication    Length = 39-43 lines in 2 locations

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

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