PayPal - PHP中的即时付款通知/ doDirectPayment

时间:2013-09-03 09:48:44

标签: php paypal paypal-ipn

我已经构建了一个IPN侦听器,并在沙盒中使用IPN Simulator对其进行了测试,但它工作正常,但是当我添加“NOTIFYURL”参数并将其设置为我的IPN侦听器时,我没有收到来自我的侦听器的任何通知,但是付款仍然有效。

我还需要做些什么才能让它发挥作用吗?

这是我的代码

我的IPN侦听器(为了测试它,只需将整个结果导入SQL表)

 include "dbconnect.php";
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
    $email .= "$varname: $varvalue\n";  

    if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){  
        $varvalue = urlencode(stripslashes($varvalue));
    }
    else {
        $value = urlencode($value);
    }
    $request .= "&$varname=$varvalue";
}

    mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$email."')");

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);

我的付款处理脚本中与paypal交互的部分:

// Store request params in an array
$request_params = array
                    (
                    'METHOD' => 'DoDirectPayment', 
                    'USER' => $api_username, 
                    'PWD' => $api_password, 
                    'SIGNATURE' => $api_signature, 
                    'VERSION' => $api_version, 
                    'PAYMENTACTION' => 'Sale',                  
                    'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
                    'CREDITCARDTYPE' => 'Visa', 
                    'ACCT' => '4887864152287206',                       
                    'EXPDATE' => '072018',          
                    'CVV2' => '123', 
                    'FIRSTNAME' => 'Tester', 
                    'LASTNAME' => 'Testerson', 
                    'STREET' => '707 W. Bay Drive', 
                    'CITY' => 'Largo', 
                    'STATE' => 'FL',                    
                    'COUNTRYCODE' => 'US', 
                    'ZIP' => '33770', 
                    'AMT' => '100.00', 
                    'CURRENCYCODE' => 'USD', 
                    'NOTIFYURL' => 'http://www.mysite.com/ipnlistener.php',
                    'DESC' => 'Testing Payments Pro' 
                    );

// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
    $nvp_string .= '&'.$var.'='.urlencode($val);    
}

// Send NVP string to PayPal and store response
$curl = curl_init();
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_URL, $api_endpoint);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);

$result = curl_exec($curl);
echo $result.'<br /><br />';
    mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$result."')");

为什么我没有收到通知?

2 个答案:

答案 0 :(得分:0)

ipn监听器的目的是让PayPal传回支付信息,以便您可以处理它,它不会向您发送任何通知,除非您添加日志文件,记录每个支付状态或发送电子邮件等内容关于已处理的付款(无论是否失败)

答案 1 :(得分:0)

您可以在https://github.com/paypal/ipn-code-samples/blob/master/IPN_PHP.txt查看PHP IPN脚本吗?

启用USE_SANDBOXUSE_DEBUG并在同一目录中创建一个名为'ipn.txt'的空文件(可由Web服务器写入)。

这将记录IPN过程的所有步骤(接收,发回,验证结果等)。应该做什么,这应该说清楚。