News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Paypal IPN: HTTP1.0 to HTTP1.1 - php coding

Started by alvinwang21, August 23, 2013, 01:58:52 AM

Previous topic - Next topic

alvinwang21

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);

alvinwang21

Now we see our customers paid in paypal are in pending status.

jenkinhill

An updated 1.1 version is in the latest VM release, 2.0.22b
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum