Code Duplication    Length = 39-43 lines in 2 locations

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

@@ 431-473 (lines=43) @@
428
	 * @since 4.0.0
429
	 * @version 4.0.0
430
	 */
431
	public function display_payment_request_button_html() {
432
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
433
434
		if ( ! isset( $gateways['stripe'] ) ) {
435
			return;
436
		}
437
438
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
439
			return;
440
		}
441
442
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
443
			return;
444
		}
445
446
		if ( is_product() ) {
447
			global $post;
448
449
			$product = wc_get_product( $post->ID );
450
451
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
452
				return;
453
			}
454
455
			// Pre Orders charge upon release not supported.
456
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
457
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
458
				return;
459
			}
460
		} else {
461
			if ( ! $this->allowed_items_in_cart() ) {
462
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
463
				return;
464
			}
465
		}
466
		?>
467
		<div id="wc-stripe-payment-request-wrapper" style="clear:both;padding-top:1.5em;">
468
			<div id="wc-stripe-payment-request-button">
469
				<!-- A Stripe Element will be inserted here. -->
470
			</div>
471
		</div>
472
		<?php
473
	}
474
475
	/**
476
	 * Display payment request button separator.
@@ 481-519 (lines=39) @@
478
	 * @since 4.0.0
479
	 * @version 4.0.0
480
	 */
481
	public function display_payment_request_button_separator_html() {
482
		$gateways = WC()->payment_gateways->get_available_payment_gateways();
483
484
		if ( ! isset( $gateways['stripe'] ) ) {
485
			return;
486
		}
487
488
		if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) {
489
			return;
490
		}
491
492
		if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) {
493
			return;
494
		}
495
496
		if ( is_product() ) {
497
			global $post;
498
499
			$product = wc_get_product( $post->ID );
500
501
			if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
502
				return;
503
			}
504
505
			// Pre Orders charge upon release not supported.
506
			if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) {
507
				WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' );
508
				return;
509
			}
510
		} else {
511
			if ( ! $this->allowed_items_in_cart() ) {
512
				WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' );
513
				return;
514
			}
515
		}
516
		?>
517
		<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>
518
		<?php
519
	}
520
521
	/**
522
	 * Log errors coming from Payment Request