/    Sign up×
Community /Pin to ProfileBookmark

PayPal IPN keeps returning INVALID

I’m running PayPal’s IPN simulator. I am using the following code, which I got from a tutorial, to create a listener.:

[code=php]
<?php
header(“HTTP/1.1 200 OK”);

$resp = ‘cmd=_notify-validate’;

foreach($_POST as $parm => $var)
{
$var = urlencode(stripslashes($var));
$resp .= “&$parm=$var”;
}

$payment_status = $_POST[“payment_status”];

$httpshead = “POST /cgi-bin/webscr HTTP/1.0rn”;
$httpshead .= “Content-Type: application/x-www-form-urlencodedrn”;
$httpshead .= “Content-Length: ” . strlen($resp) . “rnrn”;

$errno = ”;
$errstr = ”;

$fh = fsockopen(‘ssl://www.paypal.com’, 443, $errno, $errstr, 30);

fputs($fh, $httpshead . $resp);

while(!feof($fh))
{
$readresp = fgets($fh, 1024);
if(strcmp($readresp, “VERIFIED”) == 0)
{
file_put_contents(“response.txt”, “The payment status is: ” . $payment_status);
}
else if(strcmp($readresp, “INVALID”) == 0)
{
file_put_contents(“response.txt”, $readresp);
}
}

fclose($fh);
?>
[/code]

This listener is designed to retrieve the POST message sent to it by the PayPal server, and return the exact same message back to PayPal’s server (preceded by ‘cmd=_notify-validate’). However, when I run the simulator, my response keeps coming up as invalid because the message I send back is not the EXACT same as the message sent from PayPal. I can’t see what I’m doing wrong, but I have a feeling it has to do with the encoding of $_POST[‘payment_data’].

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mmoore25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...