Code Duplication    Length = 26-30 lines in 2 locations

includes/class-wc-stripe-webhook-handler.php 2 locations

@@ 542-567 (lines=26) @@
539
	 * @since 4.0.6
540
	 * @param object $notification
541
	 */
542
	public function process_review_opened( $notification ) {
543
		if ( isset( $notification->data->object->payment_intent ) ) {
544
			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
545
546
			if ( ! $order ) {
547
				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
548
				return;
549
			}
550
		} else {
551
			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
552
553
			if ( ! $order ) {
554
				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
555
				return;
556
			}
557
		}
558
559
		/* translators: 1) The URL to the order. 2) The reason type. */
560
		$message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason );
561
562
		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
563
			$order->update_status( 'on-hold', $message );
564
		} else {
565
			$order->add_order_note( $message );
566
		}
567
	}
568
569
	/**
570
	 * Process webhook reviews that are closed. i.e Radar.
@@ 575-604 (lines=30) @@
572
	 * @since 4.0.6
573
	 * @param object $notification
574
	 */
575
	public function process_review_closed( $notification ) {
576
		if ( isset( $notification->data->object->payment_intent ) ) {
577
			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
578
579
			if ( ! $order ) {
580
				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
581
				return;
582
			}
583
		} else {
584
			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
585
586
			if ( ! $order ) {
587
				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
588
				return;
589
			}
590
		}
591
592
		/* translators: 1) The reason type. */
593
		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
594
595
		if ( $order->has_status( 'on-hold' ) ) {
596
			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
597
				$order->update_status( 'processing', $message );
598
			} else {
599
				$order->add_order_note( $message );
600
			}
601
		} else {
602
			$order->add_order_note( $message );
603
		}
604
	}
605
606
	/**
607
	 * Checks if capture is partial.