/** * Validate the IPN notification * * @param none * @return boolean */ public function validateIpn() { $this->set_mode(); // Get recieved values from post data $ipn_data = (array) stripslashes_deep($_POST); $ipn_data['cmd'] = '_notify-validate'; // Send back post vars to paypal $params = array('body' => $ipn_data, 'sslverify' => false, 'timeout' => 30, 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url('/')); $response = wp_remote_post($this->gateway_url, $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strcmp($response['body'], "VERIFIED") == 0) { return true; } else { WPUF_Main::log('error', "IPN Failed\n" . $ipn_response); return false; } }
/** * Insert payment info to database * * @global object $wpdb * @param array $data payment data to insert * @param int $transaction_id the transaction id in case of update */ public static function insert_payment($data, $transaction_id = 0) { global $wpdb; //check if it's already there $sql = "SELECT transaction_id\n FROM " . $wpdb->prefix . "wpuf_transaction\n WHERE transaction_id = '" . $wpdb->escape(wpuf_clean_tags($transaction_id)) . "' LIMIT 1"; $result = $wpdb->get_row($sql); if (!$result) { $wpdb->insert($wpdb->prefix . 'wpuf_transaction', $data); do_action('wpuf_payment_received', $data); } else { $wpdb->update($wpdb->prefix . 'wpuf_transaction', $data, array('transaction_id' => $transaction_id)); WPUF_Main::log('info', 'updating existing transaction: ' . $transaction_id); } }