VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: alvinwang21 on August 23, 2013, 01:58:52 AM

Title: Paypal IPN: HTTP1.0 to HTTP1.1 - php coding
Post by: alvinwang21 on August 23, 2013, 01:58:52 AM
Recently we got a email from paypal said they want to update IPN(instant payment notification) from Http 1.0 to http 1.1 protocol. I search the website and they want us to do the changes. Otherwise payment transactions are not confirmed. Does anyone face the same problem?  where should we apply the following code in php? Any pro has a solution? :)

Developers need to include the "Host" and "Connection" headers in the IPN postback script:

PHP
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n\r\n";


PLEASE NOTE:

1)     For further compatibility your php script should also trim the IPN validation response.
Please modify your script:

From:
if (strcmp ($res, "VERIFIED") == 0) {
..
else if (strcmp ($res, "INVALID") == 0) {

To:
if (strcmp (trim($res), "VERIFIED") == 0) {
..
else if (strcmp (trim($res), "INVALID") == 0) {


2)     In php make sure the last line of your header includes double end-of-line markers: \r\n\r\n as in the example above: $header .="Connection: close\r\n\r\n";

3)     In php make sure to open the socket connection to the same host declared in the header. As your header is declaring the host as

$header .="Host: www.paypal.com\r\n";

        You should open the connection to the same host:

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
Title: Re: Paypal IPN: HTTP1.0 to HTTP1.1 - php coding
Post by: alvinwang21 on August 23, 2013, 02:33:55 AM
Now we see our customers paid in paypal are in pending status.
Title: Re: Paypal IPN: HTTP1.0 to HTTP1.1 - php coding
Post by: jenkinhill on August 23, 2013, 10:49:02 AM
An updated 1.1 version is in the latest VM release, 2.0.22b