WC_Gateway_Paypal_PDT_Handler::validate_transaction()protectedWC 1.0

Validate a PDT transaction to ensure its authentic.

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

Хуков нет.

Возвращает

true|false|Массив. False or result array if successful and valid.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_transaction( $transaction );
$transaction(строка) (обязательный)
TX ID.

Код WC_Gateway_Paypal_PDT_Handler::validate_transaction() WC 8.7.0

protected function validate_transaction( $transaction ) {
	$pdt = array(
		'body'        => array(
			'cmd' => '_notify-synch',
			'tx'  => $transaction,
			'at'  => $this->identity_token,
		),
		'timeout'     => 60,
		'httpversion' => '1.1',
		'user-agent'  => 'WooCommerce/' . Constants::get_constant( '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', $pdt );

	if ( is_wp_error( $response ) || strpos( $response['body'], 'SUCCESS' ) !== 0 ) {
		return false;
	}

	// Parse transaction result data.
	$transaction_result  = array_map( 'wc_clean', array_map( 'urldecode', explode( "\n", $response['body'] ) ) );
	$transaction_results = array();

	foreach ( $transaction_result as $line ) {
		$line                            = explode( '=', $line );
		$transaction_results[ $line[0] ] = isset( $line[1] ) ? $line[1] : '';
	}

	if ( ! empty( $transaction_results['charset'] ) && function_exists( 'iconv' ) ) {
		foreach ( $transaction_results as $key => $value ) {
			$transaction_results[ $key ] = iconv( $transaction_results['charset'], 'utf-8', $value );
		}
	}

	return $transaction_results;
}