tags:

views:

17

answers:

0

Morning all.

I am trying to test a SIMPLE php script to deal with the IPN response from paypal sandbox.

    <?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($post as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('ssl://www.sandbox.paypal.com/', 443, $errno, $errstr, 30);

if ( !$fp ) {
    // HTTP ERROR
    $fp = fopen('thinbg.txt', 'a');
    fwrite($fp, "false !fp - " . implode(" ", $post) );
    fclose($fp);
} else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);   
        if (strcmp ($res, "VERIFIED") == 0) {
            // PAYMENT VALIDATED & VERIFIED!
            $fp2 = fopen('thinbg.txt', 'a');
            fwrite($fp2, "true - " . implode(" ", $post) );
            fclose($fp2);   
        }
        else if (strcmp ($res, "INVALID") == 0) {
            // PAYMENT INVALID & INVESTIGATE MANUALY!
            $fp2 = fopen('thinbg.txt', 'a');
            fwrite($fp2, "false - " . implode(" ", $post) );
            fclose($fp2);
        }
    }
    fclose ($fp);
}


?>

When I click on "send IPN" in the test ac"IPN successfully sent". when I look at the file that I created to check the vars it begins with "false !fp" yet still displays all the vars. Can anyone see whats happening and how I go about fixing.

Regards,

Phil