WC_Gateway_Paypal_IPN_Handler::validate_ipn()publicWC 1.0

Check PayPal IPN validity.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WC_Gateway_Paypal_IPN_Handler = new WC_Gateway_Paypal_IPN_Handler();
$WC_Gateway_Paypal_IPN_Handler->validate_ipn();

Код WC_Gateway_Paypal_IPN_Handler::validate_ipn() WC 9.4.2

public function validate_ipn() {
	WC_Gateway_Paypal::log( 'Checking IPN response is valid' );

	// Get received values from post data.
	$validate_ipn        = wp_unslash( $_POST ); // WPCS: CSRF ok, input var ok.
	$validate_ipn['cmd'] = '_notify-validate';

	// Send back post vars to paypal.
	$params = array(
		'body'        => $validate_ipn,
		'timeout'     => 60,
		'httpversion' => '1.1',
		'compress'    => false,
		'decompress'  => false,
		'user-agent'  => 'WooCommerce/' . WC()->version,
	);

	// Post back to get a response.
	$response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );

	WC_Gateway_Paypal::log( 'IPN Response: ' . wc_print_r( $response, true ) );

	// Check to see if the request was valid.
	if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
		WC_Gateway_Paypal::log( 'Received valid response from PayPal IPN' );
		return true;
	}

	WC_Gateway_Paypal::log( 'Received invalid response from PayPal IPN' );

	if ( is_wp_error( $response ) ) {
		WC_Gateway_Paypal::log( 'Error response: ' . $response->get_error_message() );
	}

	return false;
}