cakephp PayPal IPN集成

时间:2011-07-20 09:45:07

标签: cakephp paypal integration paypal-ipn

我正在使用CakePHP 1.3.10版本,并希望将PayPal IPN集成到付款流程中。

我找到了一些现成的插件,但工作不正常并且返回了大量错误。

我想要你的建议,社区中的任何团体都使用相同的成功和任何教程来集成简单的步骤。

您的回复将不胜感激。

谢谢!

2 个答案:

答案 0 :(得分:4)

我刚刚发现了一个很好的PHP类,它运行所有的PayPal IPN。

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

我把它变成了CakePhp项目的一个组件。 为此,只需在app / Controller / Components /文件夹中创建一个新组件,然后粘贴该项目的代码。 然后改变:

class IpnListener {
...

class IpnListener extends Component {
...

然后回到你想要的PayPal Ipn控制器并添加:

public $components = array('IpnListener');

您可以使用以下方式访问该课程:

$this->IpnListener->foo

在您的控制器功能

希望这有帮助

答案 1 :(得分:0)

之前我使用过Paypal IPN和蛋糕,而且很简单,无需回复插件。您是否正在使用它来跟踪蛋糕应用程序中的付款?您可以在PayPal帐户中创建paypal表单/按钮,设置url回调,以便paypal可以通知您。如果要记录paypal发送给您的信息,请在DB中创建一个表。在控制器中有一个方法来处理来自paypal的POST数据。这是我的代码示例:

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

表中的字段取决于您要保留的内容。查找IPN API,您可以使用paypal设置沙箱测试。