Code Duplication    Length = 26-30 lines in 2 locations

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

@@ 528-553 (lines=26) @@
525
	 * @since 4.0.6
526
	 * @param object $notification
527
	 */
528
	public function process_review_opened( $notification ) {
529
		if ( isset( $notification->data->object->payment_intent ) ) {
530
			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
531
532
			if ( ! $order ) {
533
				WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
534
				return;
535
			}
536
		} else {
537
			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
538
539
			if ( ! $order ) {
540
				WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge );
541
				return;
542
			}
543
		}
544
545
		/* translators: 1) The URL to the order. 2) The reason type. */
546
		$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 );
547
548
		if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
549
			$order->update_status( 'on-hold', $message );
550
		} else {
551
			$order->add_order_note( $message );
552
		}
553
	}
554
555
	/**
556
	 * Process webhook reviews that are closed. i.e Radar.
@@ 561-590 (lines=30) @@
558
	 * @since 4.0.6
559
	 * @param object $notification
560
	 */
561
	public function process_review_closed( $notification ) {
562
		if ( isset( $notification->data->object->payment_intent ) ) {
563
			$order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent );
564
565
			if ( ! $order ) {
566
				WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent );
567
				return;
568
			}
569
		} else {
570
			$order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge );
571
572
			if ( ! $order ) {
573
				WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge );
574
				return;
575
			}
576
		}
577
578
		/* translators: 1) The reason type. */
579
		$message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason );
580
581
		if ( $order->has_status( 'on-hold' ) ) {
582
			if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) {
583
				$order->update_status( 'processing', $message );
584
			} else {
585
				$order->add_order_note( $message );
586
			}
587
		} else {
588
			$order->add_order_note( $message );
589
		}
590
	}
591
592
	/**
593
	 * Checks if capture is partial.