WC_Gateway_Paypal_PDT_Handler::validate_transaction()
Validate a PDT transaction to ensure its authentic.
Method of the class: WC_Gateway_Paypal_PDT_Handler{}
No Hooks.
Return
true|false|Array
. False or result array if successful and valid.
Usage
// protected - for code of main (parent) or child class $result = $this->validate_transaction( $transaction );
- $transaction(string) (required)
- TX ID.
WC_Gateway_Paypal_PDT_Handler::validate_transaction() WC Gateway Paypal PDT Handler::validate transaction code WC 8.3.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; }