1

I am using CakePHP 1.3.10 version and want to integrate PayPal IPN for Payment Process.

I have found some ready made plug-ins though not working properly and returning bunch of errors.

I would like your suggestions, Any body in community using the same with success and any tutorial to integrate in easy steps.

Your response would be appreciated.

Thanks !

Aditya P Bhatt
  • 21,431
  • 18
  • 85
  • 104
  • when i enable PayPal IPN in my sandbox developer account, it says `IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.` Why? – Aditya P Bhatt Jul 20 '11 at 12:14
  • have you set up the url to handle paypal request yet? – Anh Pham Jul 21 '11 at 06:01
  • i am trying to set URL, but gives above error, when i keep any live website, it works, but whenever some IP like 202.. a live working IP from browser, is not accepted there – Aditya P Bhatt Jul 21 '11 at 08:16

2 Answers2

4

I just discovered a nice PHP class, that runs all the PayPal IPN.

https://github.com/Quixotix/PHP-PayPal-IPN/

I turned it into a Component for my CakePhp project. For this just create a new Component in you app/Controller/Components/ folder and paste the code from that project. Then Change:

class IpnListener {
...

to

class IpnListener extends Component {
...

Then go back to the controller you want to you PayPal Ipn with and add:

public $components = array('IpnListener');

You can than access the class using:

$this->IpnListener->foo

within your controller functions

Hope this helps

slevon
  • 329
  • 2
  • 9
0

I used Paypal IPN with cake before, and it's simple enough to not have to reply on a plugin. Are you using that to track getting payment in a cake app? You can create the paypal form/button in your paypal account, set the url callback so paypal can notify you. Create a table in DB if you want to record the info paypal sends you. Have a method in the controller to handle the POST data from paypal. Here's my code example:

function blah() {
   $this->autoRender = false;
   // post back to PayPal system to validate
   $req = 'cmd=_notify-validate';
   foreach ($_POST as $key => $value) {
      $value = urlencode(stripslashes($value));
      $req .= "&$key=$value";
   }
   $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
   $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
   $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
   $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
   if (!$fp) {// HTTP ERROR, we should record the data still..?
   } else {
      fputs($fp, $header . $req);
      while (!feof($fp)) {
         $res = fgets($fp, 1024);
         if (strcmp($res, "VERIFIED") == 0) {// verified from paypal, processing...
         } else if (strcmp($res, "INVALID") == 0) {
            // oh no, someone is hijacking us...
         }
      }
      fclose($fp);
   }
}

What fields to have in the table depends on what you want to keep. Look up the IPN API, and you can setup sandbox testing with paypal.

Anh Pham
  • 5,431
  • 3
  • 23
  • 27