开发者

PHP paypal IPN in sandbox returns unverified

I have a paypal IPN script an I'm currently testing it with the sandbox. Right now though every payment I try keeps comming up as unverified. Is it because the sandbox never verifies anything or is it an error in my code?

<?php 
$ourpaypal= "dmanjr_1310054821_biz@gmail.com";
// Set the request paramaeter 
$req = 'cmd=_notify-validate'; 

// Run through the posted array 
foreach ($_POST as $key => $value) 
{ 
    // If magic quotes is enabled strip slashes 
    if (get_magic_quotes_gpc()) 
    { 
        $_POST[$key] = stripslashes($value); 
        $value = stripslashes($value); 
    } 
    $value = urlencode($value); 
    // Add the value to the request parameter 
    $req .= "&$key=$value"; 
} 

$url = "http://www.paypal.com/cgi-bin/webscr"; 
$ch = curl_init();    // Starts the curl handler 
curl_setopt($ch, CURLOPT_URL,$url); // Sets the paypal address for curl 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Returns result to a variable instead of echoing 
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // Sets a time limit for curl in seconds (do not set too low) 
curl_setopt($ch, CURLOPT_POST, 1); // Set curl to send data using post 
curl_setopt($ch, CURLOPT_POSTFIELDS, $req); // Add the requ开发者_如何学Pythonest parameters to the post 
$result = curl_exec($ch); // run the curl process (and return the result to $result 
curl_close($ch); 

$errors = false;
if (strcmp ($result, "VERIFIED") == 0) // It may seem strange but this function returns 0 if the result matches the string So you MUST check it is 0 and not just do strcmp ($result, "VERIFIED") (the if will fail as it will equate the result as false) 
{ 
    $errors = true;
    // Do some checks to ensure that the payment has been sent to the correct person 
    if ($_POST['receiver_email'] == $ourpaupal){
        // Check and ensure currency and amount are correct 
        if ($_POST['mc_currency'] == "USD"){
            require_once('DonationHandler.php');
            $don = new DonationHandler();
            if ($don->hasDB()){
                $don->RenewMembership($_POST['option_selection2'],$_POST['mc_gross'],$_POST['payer_email'],$_POST['txn_id']);
                $errors = false;
            }
        }
    }
} 
else  
{ 
    // Log an invalid request to look into 
    $myFile = "ipn_unverified.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, "======================================================\r\n");
    foreach ($_POST as $stdata){
        fwrite($fh, array_search($stdata, $_POST, true).": ". $stdata."\r\n");
    }
    fclose($fh);
}
//If there was any error with any verified payment, place it here
if ($errors){
    $myFile = "ipn_errors.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, "======================================================\r\n");
    foreach ($_POST as $stdata){
        fwrite($fh, array_search($stdata, $_POST, true).": ". $stdata."\r\n");
    }
    fclose($fh);
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜