Page 1 of 1

problem with paypal PDT

Posted: Fri May 29, 2009 8:25 am
by jawedshamshedi
Hi to all,

I am using sandbox paypal PDT for checking the online transaction thing.
After paypal returns to my page I again verify the payment before writing them in to database. The code i am using for verification is below,

Code: Select all

 
$req = 'cmd=_notify-synch';
    
     $tx_token = $_GET['tx'];
    $auth_token = "my token";
    $req .= "&tx=$tx_token&at=$auth_token";
    
    // 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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
    // If possible, securely post back to paypal using HTTPS
    // Your PHP server will need to be SSL enabled
    // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
 
    if (!$fp) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    // read the body data
    $res = '';
    $headerdone = false;
    while (!feof($fp)) {
    $line = fgets ($fp, 1024);
        if (strcmp($line, "\r\n") == 0) {
        // read the header
        $headerdone = true;
    
    }
        else if ($headerdone)
        {
        
        // header has been read. now read the contents
        $res .= $line;
        
        }
    }
 
    // parse the data
    $lines = explode("\n", $res);
    $keyarray = array();
    if (strcmp ($lines[0], "SUCCESS") == 0) {
    header("location:thankyou_advertiser.php");
    }
    else if (strcmp ($lines[0], "FAIL") == 0) {
        
        header("location:error.php");
        // log for manual investigation
    }
 
}
fclose ($fp);
 
This piece of code was working fine, few hours back, now what is happening that with the username and password with which i am paying by sandbox is always returning false, but when I login in to paypal sandbox with the same user name and password it show there sucessful transaction.

I am clueless can anybody help ???????

Thanks in advance
Jawed

Re: problem with paypal PDT

Posted: Fri May 29, 2009 1:48 pm
by califdon
I recently went through these issues and finally succeeded, but I must admit that I struggled through several such problems. I found the most help in the PayPal Devloper forums (http://paypaldeveloper.com/pdn/forums).

You say you are using PDT, but your code appears to be appropriate to IPN, where you return a validated transaction. I decided to use both, because you can never be assured that the user will actually return to your site (they could shut down their browser, for example), so, for local database maintenance, I think it's safer to rely on the IPN transaction that doesn't depend on what your user might do. I still use the PDT transaction to confirm to the user, assuming they return to your site.

On your issue about user/password, if I understand your problem, you're saying that the sandbox is rejecting your business account? Make sure that you're using the correct account--there are so many different accounts required, it gets confusing! There is a developer account for the sandbox, then within that developer account you have to establish 2 fake accounts for testing, one business account and one personal account. It's very easy to get confused and try to use the wrong account for the wrong purpose.

Re: problem with paypal PDT

Posted: Mon Jun 01, 2009 1:26 pm
by jawedshamshedi
Thanks for the reply, but i got my problem. The bussiness account setting for PDT and redirect changes automatically somehow.. so there was the problem, now its being resolved....But anyway thanks for the reply......