[eluser]nandish[/eluser]
Hi guys
I integrated Instant Payment Notification WITH direct_payment pro
No luck, but it gives always invalid response
Paypal_library
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
-------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------
class Paypal_Lib {
var $ipn_data = array();
var $last_error;
var $ipn_response;
var $paypal_url;
var $CI;
// -------------------------------------------------------------------------------------------------------------
//assigning urls,providing constant values
// -------------------------------------------------------------------------------------------------------------
function Paypal_Lib() {
$this->CI =& get_instance();
$this->CI->load->helper('url');
$this->CI->load->helper('form');
$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //intialize paypal sandbox website url
//$this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; //initialize paypal main website url
//$this->paypal_url = fsockopen('ssl://www.sandbox.paypal.com');
}
// -------------------------------------------------------------------------------------------------------------
//validating ipn while sending data against paypal website
// -------------------------------------------------------------------------------------------------------------
function validate_ipn() {
$url_parsed = parse_url($this->paypal_url);
$post_string = '';
if(isset($_POST) {
foreach ($_POST as $field=>$value) {
//store the values in the array to send mail
$this->ipn_data[$field] = str_replace("\n", "\r\n", $value);
//$this->ipn_data[$field] = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
}
$post_string.="cmd=_notify-validate";
log_message('debug','POST DATA'.print_R($post_string,true));
// open the connection to paypal
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
//$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
if(!$fp) {
$this->last_error = "fsockopen error no. $errnum: $errstr";
log_message('debug','socket connection error'.print_r($fp,true));
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
log_message('debug','socket connection'.print_r($fp,true));
// loop through the response from the server and append to variable
while(!feof($fp))
$this->ipn_response .= fgets($fp, 1024);
fclose($fp); // close connection
log_message('debug','IPN DATA'.print_R($this->ipn_response,true));
}
if (eregi("VERIFIED",$this->ipn_response)) {
// Valid IPN transaction.
log_message('debug','IPN VERIFED'.print_R($this->ipn_response,true));
return true;
} else {
// Invalid IPN transaction. Check the log for details.
log_message('debug','IPN FAIL'.print_R($this->ipn_response,true));
$this->last_error = 'IPN Validation Failed.';
return false;
}
}
}
?>
LOG MESSAGE
-------------------------------------------------------------------------------------
DEBUG - 2009-07-13 00:07:27 --> IPN FAILURE HTTP/1.1 200 OK
Date: Mon, 13 Jul 2009 05:07:31 GMT
Server: Apache/1.3.33 (Unix) mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a mod_ssl/2.8.22 OpenSSL/0.9.7e
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=4ttWW-N-3uG6De42zBoekW0jMBwuUePpuXbQ8pNqlBAwdf7WFSNg3q565BrEvZekmFkS-h4LZasdsjpzroKW3i0s-61XLLix-kMbdZkd8rg5c5T52aNHCEXSJQiL_HC62UsP9W|oZdrjYo_0F2PYvJbtaWFjt-9vapH7AygcjILSg8GhmArs6X65TI9CLMkNtRv3u0_3ehYiG|3rX0CTFyPWy0nGFNCWSG08u2pRrTpJOlLe9R0AyVXmHtO2OQd_siqOTjFNppYA-XlLanZm|1247461652; domain=.paypal.com; path=/
Set-Cookie: cookie_check=yes; expires=Thu, 11-Jul-2019 05:07:32 GMT; domain=.paypal.com; path=/
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/
Set-Cookie: navlns=0; expires=Sun, 08-Jul-2029 05:07:32 GMT; domain=.paypal.com; path=/
Set-Cookie: Apache=10.191.196.11.307281247461651850; path=/; expires=Sat, 30-May-03 22:39:15 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
7
INVALID
0
Thanks in advance
|