aRo` automating your e-commerce

This blog has been neglected due to the success of Solidshops.com
27Mar/10

paypal ipn postback on a custom port.

When we were developping the paypal IPN script for our ecommerce project solidshops.com, we ran into a strange limition.

Apparently paypal does not allow you to post back to a url with a custom port. Only http(80) and https(443) are allowed.

We solved it by using the paypal ipn proxy below. You should put this script on a different server and it will post all the IPN data to your application on port 8080.

The $url should be changed to the webapplication(on custom port) where the paypal data is processed.

PHP:
  1. $url = 'http://www.yourdomain.com:8080/ipnscript.php';
  2.        
  3. $fields = $_POST;
  4. if (count ( $fields )> 0) {
  5.            
  6.     //url-ify the data for the POST
  7.     foreach ( $fields as $key => $value ) {
  8.         $fields_string .= $key . '=' . $value . '&';
  9.     }
  10.     rtrim ( $fields_string, '&' );
  11.            
  12.     //open connection
  13.     $ch = curl_init ();
  14.            
  15.     //set the url, number of POST vars, POST data
  16.     curl_setopt ( $ch, CURLOPT_URL, $url );
  17.     curl_setopt ( $ch, CURLOPT_POST, count ( $fields ) );
  18.     curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields_string );
  19.            
  20.     //execute post
  21.     $result = curl_exec ( $ch );
  22.            
  23.     //close connection
  24.     curl_close ( $ch );
  25. }

Popularity: 2% [?]

Filed under: php No Comments