problem with paypal PDT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jawedshamshedi
Forum Commoner
Posts: 35
Joined: Fri May 16, 2008 1:17 am
Location: India
Contact:

problem with paypal PDT

Post 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
Last edited by Benjamin on Fri May 29, 2009 10:35 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: problem with paypal PDT

Post 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.
jawedshamshedi
Forum Commoner
Posts: 35
Joined: Fri May 16, 2008 1:17 am
Location: India
Contact:

Re: problem with paypal PDT

Post 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......
Post Reply