WC_Gateway_Paypal_API_Handler::refund_transaction()public staticWC 1.0

Refund an order via PayPal.

Method of the class: WC_Gateway_Paypal_API_Handler{}

No Hooks.

Return

Object. Either an object of name value pairs for a success, or a WP_ERROR object.

Usage

$result = WC_Gateway_Paypal_API_Handler::refund_transaction( $order, $amount, $reason );
$order(WC_Order) (required)
Order object.
$amount(float)
Refund amount.
Default: null
$reason(string)
Refund reason.
Default: ''

WC_Gateway_Paypal_API_Handler::refund_transaction() code WC 8.7.0

public static function refund_transaction( $order, $amount = null, $reason = '' ) {
	$raw_response = wp_safe_remote_post(
		self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp',
		array(
			'method'      => 'POST',
			'body'        => self::get_refund_request( $order, $amount, $reason ),
			'timeout'     => 70,
			'user-agent'  => 'WooCommerce/' . WC()->version,
			'httpversion' => '1.1',
		)
	);

	WC_Gateway_Paypal::log( 'Refund Response: ' . wc_print_r( $raw_response, true ) );

	if ( is_wp_error( $raw_response ) ) {
		return $raw_response;
	} elseif ( empty( $raw_response['body'] ) ) {
		return new WP_Error( 'paypal-api', 'Empty Response' );
	}

	parse_str( $raw_response['body'], $response );

	return (object) $response;
}