开发者

cakephp PayPal IPN Integration

开发者 https://www.devze.com 2023-03-21 09:28 出处:网络
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 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 w开发者_如何学运维ould be appreciated.

Thanks !


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号