我試圖捕獲用戶在貝寶(沙箱)中進行支付。 IPN是這個問題的答案,但似乎我沒有從中得到任何迴應。我試圖把它放在日誌中,甚至是數據庫中,但是沒有數據輸入。我知道IPN是一個聽衆,但我不知道爲什麼不工作..任何澄清和想法呢?Codeigniter paypal_lib IPN不工作
我使用笨Paypal_Lib
這裏是我的腳本:
首先我宣佈領域
$this->paypal_lib->add_field('cmd','_cart');
$this->paypal_lib->add_field('upload','1');
$this->paypal_lib->add_field('business', $business_email);
$this->paypal_lib->add_field('return', site_url('invoice/payment_success/'.$invoice_id.'/'.$album_id));
$this->paypal_lib->add_field('cancel_return', site_url('invoice/payment_cancel/'.$invoice_id));
$this->paypal_lib->add_field('notify_url', site_url('invoice/payment_validate/'.$invoice_id)); // <-- IPN url
$this->paypal_lib->add_field('custom', $invoice_id); // <-- Verify return
這裏是我的IPN,只是檢查,如果它的工作原理是有日誌,但沒有運氣。
public function payment_validate(){
//$this->paypal_lib->dump();
$invoice_id = $this->uri->segment(3);
if ($this->paypal_lib->validate_ipn()){
$payer_email = $this->paypal_lib->ipn_data['payer_email'];
$fp=fopen('temp/logs/paypal_ipn.log','a');
fwrite($fp, $this->paypal_lib->ipn_data . "\n");
fclose($fp); // close file
}
}
這裏是庫中的validate_ipn。
功能validate_ipn(){
// get instance
$CI =& get_instance();
// parse the paypal URL
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
#if(count($_POST))
if($_POST)
{
#foreach (array_keys($_POST) as $field)
foreach ($_POST as $field => $value)
{
#$value = $CI->input->post($field, true);
$this->ipn_data[$field] = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
}
$post_string.='cmd=_notify-validate'; // append ipn command
// open the connection to paypal
$fp = fsockopen($url_parsed['host'],'80',$err_num,$err_str,30);
if(!$fp)
{
// could not open the connection. If loggin is on, the error message
// will be in the log.
$this->last_error = 'fsockopen error no. '.$err_num.': '.$err_str;
$this->log_ipn_results(false);
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");
// loop through the response from the server and append to variable
while(!feof($fp))
$this->ipn_response .= fgets($fp, 1024);
fclose($fp); // close connection
}
if (eregi('VERIFIED',$this->ipn_response))
{
// Valid IPN transaction.
if ($this->ipn_log_method == 'db')
{
return $this->log_ipn_results(true);
}
/*// Valid IPN transaction.
$this->log_ipn_results(true);*/
return true;
}
else
{
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
}
我已經考慮這個事實,但我認爲它應該工作,因爲我可以去PayPal(沙箱),當我點擊付費按鈕。 我可以在paypal沙箱中找到這個IPN歷史記錄嗎? –
是的,你是對的。我發現它在這裏http://stackoverflow.com/questions/8407620/paypal-ipn-validation-doesnt-work-despite-success-page-being-reached謝謝你的提示。 –