沙盒模式下的Paypal IPN

时间:2013-08-06 22:29:00

标签: php paypal paypal-ipn

我在我的帐户上安装了IPN,这似乎是在IPN模拟器上工作,但是在沙盒模式下测试时,它无法正常工作。 这是我的代码,我有什么不对吗?

<?php
  $req = 'cmd=_notify-validate';

  foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
  }

  //Set up the acknowledgement request headers
  $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header .= "Host: www.sandbox.paypal.com\r\n";
  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

  //Open a socket for the acknowledgement request
  $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

  // Post request back to PayPal for validation
  fputs ($fp, $header . $req);


   while (!feof($fp)) {                     // While not EOF
    $res = fgets ($fp, 1024);              // Get the acknowledgement response

    if (strcmp ($res, "VERIFIED") == 0) {  // Response is VERIFIED

      // Send an email announcing the IPN message is VERIFIED
      $mail_From = "IPN@example.com";
      $mail_To = "me@gmail.com";
      $mail_Subject = "VERIFIED IPN";
      $mail_Body = $req;
      mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
    }
    else if (strcmp ($res, "INVALID") == 0) { // Response is INVALID

      // Notification protocol is NOT complete, begin error handling

      // Send an email announcing the IPN message is INVALID
      $mail_From = "IPN@example.com";
      $mail_To = "me@gmail.com";
      $mail_Subject = "INVALID IPN";
      $mail_Body = $req;
      mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

    }
  }

  fclose ($fp);
?>

这是我在代码中出错的原因还是来自Paypal的问题?我该如何解决这个问题?

另一方面,我的帐户已通过Paypal验证

2 个答案:

答案 0 :(得分:0)

我遇到了同样的麻烦,

但问题是来自Paypal沙盒界面,服务器没有调用我的通知网址。

现在好像,

请再试一次!

:)

答案 1 :(得分:0)

显然这是Paypal文档中的问题,昨天我发现我需要执行以下步骤:

  • 在developer.paypal.com中为真实账户(卖方账户)创建两个账户,在沙盒模式下创建买方账户。
  • 管理sandbox.paypal.com上的卖家帐户为高级帐户,您需要仔细检查您是否在沙盒卖家帐户上启用了IPN! (我之所以失踪,因为我认为设置与paypal.com上的真实账户相同)

代码工作正常,这是一个神秘的设置问题。