Paypal sandbox IPN simulator - 502 Bad Gateway

1k views Asked by At

I've just finish implementing a Payment Gateway Server that supports Paypal. The gateway also has an adaptive IPN server for Paypal and Skrill notifications. During implementation and tests, I used the documentation provided by Paypal's IPN manual. During tests, everything went "All Okay". I test it with the example given by the documentation, "All Okay":

mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User&notify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00

The problem started when we deployed the gateway to our production server, and went testing with the simulation form provided by Paypal's IPN Simulator. Well, when I clicked the Send IPN button, the message didn't reached my server, and after a few seconds (more like minutes), an HTTP error status response appeared: enter image description here

Yes 502 Bad Gateway! What the heck is that?!? The message did not even got to server. A few remarks, we are not using the standard 80/443 ports, and we only support "POST" messages. Again the IPN message is not getting into our server, we test it with other testing tools, and the message arrives successfully.

Please help!

>> We are using Express Checkout by the way!

1

There are 1 answers

1
nmos On

You should avoid putting the host in your headers.
Change this:

    $header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Host: www.paypal.com\r\n"; *****DELETE THIS LINE*****
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

For this:

    $header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";