Code Duplication    Length = 24-24 lines in 2 locations

includes/gateways/paypal/includes/class-wc-gateway-paypal-api-handler.php 2 locations

@@ 80-103 (lines=24) @@
77
	 * @param  float $amount
78
	 * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
79
	 */
80
	public static function do_capture( $order, $amount = null ) {
81
		$raw_response = wp_safe_remote_post(
82
			self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp',
83
			array(
84
				'method'      => 'POST',
85
				'body'        => self::get_capture_request( $order, $amount ),
86
				'timeout'     => 70,
87
				'user-agent'  => 'WooCommerce',
88
				'httpversion' => '1.1'
89
			)
90
		);
91
92
		WC_Gateway_Paypal::log( 'DoCapture Response: ' . print_r( $raw_response, true ) );
93
94
		if ( empty( $raw_response['body'] ) ) {
95
			return new WP_Error( 'paypal-api', 'Empty Response' );
96
		} elseif ( is_wp_error( $raw_response ) ) {
97
			return $raw_response;
98
		}
99
100
		parse_str( $raw_response['body'], $response );
101
102
		return (object) $response;
103
	}
104
105
	/**
106
	 * Refund an order via PayPal.
@@ 112-135 (lines=24) @@
109
	 * @param  string   $reason
110
	 * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
111
	 */
112
	public static function refund_transaction( $order, $amount = null, $reason = '' ) {
113
		$raw_response = wp_safe_remote_post(
114
			self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp',
115
			array(
116
				'method'      => 'POST',
117
				'body'        => self::get_refund_request( $order, $amount, $reason ),
118
				'timeout'     => 70,
119
				'user-agent'  => 'WooCommerce',
120
				'httpversion' => '1.1'
121
			)
122
		);
123
124
		WC_Gateway_Paypal::log( 'Refund Response: ' . print_r( $raw_response, true ) );
125
126
		if ( empty( $raw_response['body'] ) ) {
127
			return new WP_Error( 'paypal-api', 'Empty Response' );
128
		} elseif ( is_wp_error( $raw_response ) ) {
129
			return $raw_response;
130
		}
131
132
		parse_str( $raw_response['body'], $response );
133
134
		return (object) $response;
135
	}
136
}
137
138
/**