WC_Gateway_Paypal::process_refund()publicWC 1.0

Process a refund if supported.

Метод класса: WC_Gateway_Paypal{}

Хуков нет.

Возвращает

true|false|WP_Error.

Использование

$WC_Gateway_Paypal = new WC_Gateway_Paypal();
$WC_Gateway_Paypal->process_refund( $order_id, $amount, $reason );
$order_id(int) (обязательный)
Order ID.
$amount(float)
Refund amount.
По умолчанию: null
$reason(строка)
Refund reason.
По умолчанию: ''

Код WC_Gateway_Paypal::process_refund() WC 9.3.3

public function process_refund( $order_id, $amount = null, $reason = '' ) {
	$order = wc_get_order( $order_id );

	if ( ! $this->can_refund_order( $order ) ) {
		return new WP_Error( 'error', __( 'Refund failed.', 'woocommerce' ) );
	}

	$this->init_api();

	$result = WC_Gateway_Paypal_API_Handler::refund_transaction( $order, $amount, $reason );

	if ( is_wp_error( $result ) ) {
		static::log( 'Refund Failed: ' . $result->get_error_message(), 'error' );
		return new WP_Error( 'error', $result->get_error_message() );
	}

	static::log( 'Refund Result: ' . wc_print_r( $result, true ) );

	switch ( strtolower( $result->ACK ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
		case 'success':
		case 'successwithwarning':
			$order->add_order_note(
				/* translators: 1: Refund amount, 2: Refund ID */
				sprintf( __( 'Refunded %1$s - Refund ID: %2$s', 'woocommerce' ), $result->GROSSREFUNDAMT, $result->REFUNDTRANSACTIONID ) // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
			);
			return true;
	}

	return isset( $result->L_LONGMESSAGE0 ) ? new WP_Error( 'error', $result->L_LONGMESSAGE0 ) : false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}