Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Paypal IPN

  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Paypal IPN

    Hi,

    I have the following code for paypal ipn. Using the sandbox to test it. When the transaction goes thru successfully, it emails me saying it failed?

    This is the php code direct from paypal un modified.

    PHP Code:
    <?php

        $req 
    'cmd=_notify-validate';
        
    $to 'emailaddy';

        foreach (
    $_POST as $key => $value) {
        
    $value urlencode(stripslashes($value));
        
    $req .= "&$key=$value";
        }

        
    $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 ('www.paypal.com'80$errno$errstr30);

        
    $item_name $_POST['item_name'];
        
    $item_number $_POST['item_number'];
        
    $payment_status $_POST['payment_status'];
        
    $payment_amount $_POST['mc_gross'];
        
    $payment_currency $_POST['mc_currency'];
        
    $txn_id $_POST['txn_id'];
        
    $receiver_email $_POST['receiver_email'];
        
    $payer_email $_POST['payer_email'];

        if (!
    $fp) {

        
    // Failed to connect
        
    $subject 'Failed to connect';
        
    $to "$to";
        
    $body =  "Failed to connect to paypal\n";
        
    mail($to$subject$body);
        
        }else{
        
    fputs ($fp$header $req);
        while (!
    feof($fp)) {
        
    $res fgets ($fp1024);
        if (
    strcmp ($res"VERIFIED") == 0) {

        
    // Worked
        
    $subject 'Instant Payment Notification - Payment Worked';
        
    $to "$to";
        
    $body =  "An instant payment notification worked\n";
        
    mail($to$subject$body);

        }
        else if (
    strcmp ($res"INVALID") == 0) {

        
    // Failed
        
    $subject 'Instant Payment Notification - Payment Failed';
        
    $to "$to";
        
    $body =  "An instant payment notification failed\n";
        
    mail($to$subject$body);

         }
        }
        
    fclose ($fp);
        }
        
    ?>
    Am I doing something wrong?

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If you are using the sandbox then you need to modify the script to open the sandbox URL rather than the "real" URL. Find the www.paypal.com URL and change it to the sandbox URL... I think it's sandbox.paypal.com? Or sandbox.www.paypal.com? I forget exactly.

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doh, that was the problem.

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •