Code Duplication    Length = 33-33 lines in 2 locations

includes/legacy/class-wc-gateway-stripe.php 1 location

@@ 563-595 (lines=33) @@
560
	 * @param  float $amount
561
	 * @return bool
562
	 */
563
	public function process_refund( $order_id, $amount = null, $reason = '' ) {
564
		$order = wc_get_order( $order_id );
565
566
		if ( ! $order || ! $order->get_transaction_id() ) {
567
			return false;
568
		}
569
570
		$body = array();
571
572
		if ( ! is_null( $amount ) ) {
573
			$body['amount']	= $this->get_stripe_amount( $amount );
574
		}
575
576
		if ( $reason ) {
577
			$body['metadata'] = array(
578
				'reason'	=> $reason,
579
			);
580
		}
581
582
		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
583
584
		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
585
586
		if ( is_wp_error( $response ) ) {
587
			WC_Stripe::log( "Error: " . $response->get_error_message() );
588
			return $response;
589
		} elseif ( ! empty( $response->id ) ) {
590
			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
591
			$order->add_order_note( $refund_message );
592
			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
593
			return true;
594
		}
595
	}
596
}
597

includes/class-wc-gateway-stripe.php 1 location

@@ 709-741 (lines=33) @@
706
	 * @param  float $amount
707
	 * @return bool
708
	 */
709
	public function process_refund( $order_id, $amount = null, $reason = '' ) {
710
		$order = wc_get_order( $order_id );
711
712
		if ( ! $order || ! $order->get_transaction_id() ) {
713
			return false;
714
		}
715
716
		$body = array();
717
718
		if ( ! is_null( $amount ) ) {
719
			$body['amount']	= $this->get_stripe_amount( $amount );
720
		}
721
722
		if ( $reason ) {
723
			$body['metadata'] = array(
724
				'reason'	=> $reason,
725
			);
726
		}
727
728
		WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" );
729
730
		$response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' );
731
732
		if ( is_wp_error( $response ) ) {
733
			WC_Stripe::log( "Error: " . $response->get_error_message() );
734
			return $response;
735
		} elseif ( ! empty( $response->id ) ) {
736
			$refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason );
737
			$order->add_order_note( $refund_message );
738
			WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) );
739
			return true;
740
		}
741
	}
742
743
	/**
744
	 * Sends the failed order email to admin