I can't seem to get this PayPal PDT script working. PayPal hits the return URL but then I'm presented with a blank screen and nothing happens. Can anyone see what is incorrect? Here's my code:
$tx = $_GET['tx'];
$ID = $_GET['cm'];
$amount = $_GET['amt'];
$currency = $_GET['cc'];
$identity = '###########################################';
// Init cURL
$ch = curl_init();
// Set request options
$url = 'https:www.paypal.com/cgi-bin/webscr';
$fields = array(
'cmd' => '_notify-synch',
'tx' => $tx,
'at' => $identity,
);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_HEADER, FALSE);
// Execute request and get response and status code
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close connection
curl_close($ch);
if($status == 200 AND strpos($response, 'SUCCESS') === 0)
{
wp_redirect(home_url('/account'));
exit;
} else {
wp_redirect(home_url());
exit;
}
The URL string shows that the necessary information initially being returned (transaction ID etc) is correct but I don't know if it's actually being used but simply failing with the wordpress redirects or if it's failing at some point beforehand.
CoreyRS,
Using your code I was able to to get PDT to work with a few changes:
$url = 'https:www.paypal.com/cgi-bin/webscr';
to
$url = 'https://www.paypal.com/cgi-bin/webscr';
and
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
to
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
Also, make sure if you are testing with sandbox to use the url https://www.sandbox.paypal.com/cgi-bin/webscr instead.