我有以下表单在沙盒paypal帐户中发送数据
<form name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="item_name" value="bronze">
<input type="hidden" name="business" value="xxx@gmail.com">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="0.1">
<input type="hidden" name="notify_url" value="http://mywebsite.com/return.php?action=ipn">
<input type="hidden" name="cancel_return" value="http://mywebsite.com/return.php?action=cancel">
<input type="hidden" name="return" value="http://mywebsite.com/return.php?action=success">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="p3" value="1">
</form>
我遇到问题,因为IPN模拟器给了我正确的通知,但在交易中它不起作用。我也检查了IPN历史记录,但也没有发送。
我已将IPN通知设置设置为“开启”,并在沙盒商家帐户中设置notify_url。
以下是我的IPN侦听器代码:
class ipn {
var $last_error;
var $ipn_log;
var $ipn_log_file;
var $ipn_response;
var $ipn_data = array();
function __construct() {
$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->last_error = '';
$this->ipn_log_file = 'ipn_log.txt';
$this->ipn_log = true;
$this->ipn_response = '';
}
function validate_ipn() {
$this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$url_parsed = parse_url( $this->paypal_url );
$post_string = '';
foreach ( $_POST as $field => $value ) {
$this->ipn_data[ "$field" ] = $value;
$post_string .= $field . '=' . urlencode( $value ) . '&';
}
$post_string.="cmd=_notify-validate";
$fp = fsockopen( $url_parsed[ 'host' ], 80, $err_num, $err_str, 30 );
if ( !$fp ) {
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results( false );
return false;
} else {
$this->ipn_response = file_get_contents( $this->paypal_url . "?" . $post_string);
fclose( $fp );
}
if ( preg_match('/VERIFIED/i', $this->ipn_response ) ) {
$this->log_ipn_results( true );
return true;
} else {
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results( false );
return false;
}
}
function log_ipn_results( $success ) {
if ( !$this->ipn_log )
return;
$text = '[' . date( 'm/d/Y g:i A' ) . '] - ';
if ( $success )
$text .= "SUCCESS!\n";
else
$text .= 'FAIL: ' . $this->last_error . "\n";
$text .= "IPN POST Vars from Paypal:\n";
foreach ( $this->ipn_data as $key => $value ) {
$text .= "$key=$value, ";
}
$text .= "\nIPN Response from Paypal Server:\n " . $this->ipn_response;
$fp = fopen( $this->ipn_log_file, 'a' );
fwrite( $fp, $text . "\n\n" );
fclose( $fp );
}
}
当任何用户订购定期付款时,首次IPN会收到订阅注册和订阅付款,但第二天IPN无法接收。