Need help with my PayPal IPN Script in PHP

Nerks
Contributor
Contributor

Hello! There is something wrong with my PHP script for the callback PayPal IPN request. I made it so that it sends the results back to a txt file which I can see and by the statistics the file_get_contents seems to not be getting a VERIFIED nor INVALID return back, and seems to just be timing out instead.

Could someone please help me with this? Thank you very much.

<?php
    // Get POST data and refine the GET value.
        foreach ($_POST as $name => $value) {
            $postdata = $name.'='.$value.'&';
            $result .= substr('?'.$postdata, 0, -1);
        }
    
    // Verify that payment was really made.
    $verify = file_get_contents('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr/'.$result.'');
    
        if ($verify == "VERIFIED") {
            // Any code run here will only be run if payment is verified.
            echo 'Payment success!';
            $data = "Payment made successfully.";
            $fp = fopen('stats.txt', 'a');
            fwrite($fp, $data);
        }
        elseif ($verify == "INVALID") {
            echo 'Payment Declined.';
            $data = "The payment isn't valid.";
            $fp = fopen('stats.txt', 'a');
            fwrite($fp, $data);
        }
        else {
            echo 'An unexpected error occured.';
            $data = "A timeout error occured.";
            $fp = fopen('stats.txt', 'a');
            fwrite($fp, $data);
        }
    
        // Let PayPal know that the IPN was successful.
            header("HTTP/1.1 200 OK");
?>
Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.