当买方支付订阅费用时,notify_url 从不调用

2021-12-29 00:00:00 php subscription paypal paypal-ipn sandbox

现在我正在尝试使用贝宝沙盒从我的网站制定订阅计划.我已经在企业帐户中设置了 notify_url 并打开了此功能.退货和取消退货是正确的工作.但是当用买家(个人)帐户测试并同意订阅付款时,没有交易日志永远不会调用我的网站notify_url.

Now i am trying to make subscription plan from my website with paypal sandbox. I was already setup notify_url in business account and turn on this feature. return and cancel return is correctly work. But when test with buyer(personal)account and agree subscription payment, no transaction log never call to my website notify_url.

我的问题与 [question] 类似:notify_url 未到达或可能是沙箱 paypal 中的错误响应

My problem is similar with [question]:notify_url is not reached or may be false response in sandbox paypal

感谢您的帮助.

推荐答案

如果您的帐户启用了 IPN,请登录该帐户并查看 IPN 历史记录.您应该能够从这里判断您的 IPN 是否正在发送,或者它们是否处于重试或失败状态.如果您在此处看到您的 IPN,您可以单击消息 ID,它会显示您的服务器正在返回的状态(如果它正在返回).这可能有助于隔离问题的原因.此外,以下是一些可能有助于解决 IPN 问题的基本故障排除步骤.

If you have IPN enabled in your account, log into the account and look at the IPN history. You should be able to tell from here if your IPN's are being sent out, or if they are in a retrying or failed status. If you see your IPN's in here, you can click on the message id and it will show you what status is being returned by your server if it is returing one. This may help to isolate the cause of the issue. Also, here are some basic troubleshooting steps that may help with IPN issues.

此外,如果您使用的是自定义脚本,请尝试使用 PayPal 的示例 IPN 脚本.它们是非常基本的脚本,但它们是经过测试的工作示例.这有助于确定这是您的脚本还是一般 IPN 的问题.

Also if you are using a custom script, try using one of PayPal’s sample IPN scripts. They are very basic scripts, but they are tested working examples. This can help to determine if it’s an issue with your script or with IPN in general.

IPN 故障排除技巧

这些是在使用 IPN 时影响开发人员的最常见问题.还指出了最常见的解决方案.希望这些信息可以帮助到那里的人!

These are the most common problems affecting developers when working with IPN. The most common solutions are noted as well. Hope this information helps someone out there!

无效的原因

  • 确保您发回所有变量/值.

为了让 PayPal 返回 VERIFIED,您的 IPN 脚本首先需要回发所有已发送给它的变量.换句话说,如果您的脚本只需要操作 1 或 2 个变量,那么仅将您的脚本涉及的变量/值回发到 PayPal 是不够的.您的脚本应该回发最初从 PayPal 发布到它的所有内容.这是 PayPal 返回 VERIFIED 的唯一方式

For PayPal to return VERIFIED, your IPN script needs to post back ALL the variables that were posted to it in the first place. In other words, if your script only needs to manipulate 1 or 2 variables, it is not enough to post back to PayPal only the variables/values your script is concerned with. Your script should post back EVERYTHING that was initially posted to it from PayPal. This is the only way PayPal will return VERIFIED

  • 确保您没有发回错误的网址.

如果您在 Sandbox 中进行测试,您需要确保您的脚本发回 www.sandbox.paypal.com.如果您在实时站点上,脚本应该回发到 www.paypal.com.如果您在沙盒中进行测试并且您的脚本发布回实时站点(反之亦然),您将收到 INVALID

If you are testing in the Sandbox, you need to ensure your script posts back to www.sandbox.paypal.com. If you are on the live site, the script should post back to www.paypal.com. You will receive INVALID if you are testing in the Sandbox and your script posts back to the live site (or vice versa)

  • 编码

PayPal 的 IPN 服务器期望您的脚本将回发所有发送给它的变量,更重要的是,它们的编码方式与发送到您的脚本的方式相同.如果您的脚本无意中更改了一个字符的编码或将一个编码字符解释为另一个字符并回传,您可能会看到 INVALID.这可能偶尔发生,并且往往会发生,例如,当收到付款并且买家的姓名中可能带有重音字符,或者订单是针对某些项目名称中包含非标准字符的项目时.这些实例很难排除故障,但在此处列出,因为当您期望 VERIFIED 时,它可能会导致 INVALID.当您看到某些 IPN 无效而其他所有 IPN 均已验证时,请查找此问题.

PayPal's IPN server expects that your script will POST back all variables that were posted to it and more importantly, that they are encoded the same way as they were sent to your script. If your script inadvertently changed the encoding of a character or interprets an encoded character as another character and POSTs back, you will likely see INVALID. This can happen sporadically and tends to occur, for example, when a payment is received and the buyer may have an accented character in their name or the order is for some item with a non-standard character in the item name. These instances are tricky to troubleshoot but it is listed here as it can cause INVALID when you would expect VERIFIED. Look for this issue when you are seeing that certain IPNs are INVALID and all the rest are VERIFIED.

故障排除提示 - IPN 未发布!

TROUBLESHOOTING TIPS - IPN is not POSTing!

  • 接收帐户的电子邮件地址.

请确保您已确认接收付款的帐户的电子邮件地址.

Make sure you've confirmed the e-mail address on the account the payment is being sent to.

  • 访问日志

如果您觉得 IPN 没有发布到您的脚本,您可以通过检查您的服务器的访问日志来验证这一点.服务器访问日志会告诉您 PayPal 是否命中您的脚本".访问日志跟踪访问服务器的计算机的 IP 地址和/或主机名.您可以访问服务器的访问日志取决于服务器管理员.如果您不知道日志在哪里,请与他们联系.

If you feel IPN is not posting to your script, you can verify this by checking your server's access logs. The server access logs will tell you if PayPal is "hitting your script" at all. An access log tracks the IP addresses and/or hostnames of computers that access the server. That you can access your server's access logs is up to the server admin. Check with them if you do not know where the logs are.

  • 错误日志如果在运行脚本时发生错误,大多数脚本语言会输出到错误日志.如果您在访问日志中看到 PayPal 正在发送 IPN,但您没有看到脚本的预期最终结果,很可能是脚本中存在逻辑或语法错误.检查您的错误日志以进行验证.同样,如果您不知道如何或在何处查看这些日志,则需要咨询服务器管理员.

  • Error logs Most scripting languages output to error logs if an error occurs when running the script. If you see in your access logs that PayPal is sending the IPN but you are not seeing the intended end result from your script, odds are you have a logic or syntax error in the script. Check your error logs to verify. Again, if you don't know how or where to check these logs, you would need to consult your server's administrator.

检查路径

一个容易犯的错误.在测试/使用 IPN 时,始终确保脚本的路径是正确的,并且您会看到没有收到 IPN 帖子.例如,避免使用localhost"网址.由于这是后端服务器到服务器的通信,因此设置到 localhost 的路径将导致 IPN 尝试向自身而不是在网络外部发送到您自己的服务器/脚本.

An easy mistake to make. Always ensure the path to your script is correct when testing/using IPN and you see that you are not getting an IPN post. For example avoid using "localhost" urls. Since this is a back end server to server communication setting a path to localhost will cause the IPN to try to post to itself rather than outside the network to your own server/script.

  • 防火墙

IPN 是从 PayPal 发起的 HTTP POST.如果您的服务器上有防火墙,请确保您的防火墙没有阻止来自 PayPal 的帖子.

IPN is an HTTP POST initiated from PayPal. If you have a firewall on your server, make sure your firewall is not blocking the post from PayPal.

  • 测试以确保您的脚本按预期工作.

如果您的脚本中有语法或逻辑错误,您很可能看不到正确的结果.测试脚本的一种简单方法是向脚本发送虚拟"帖子,并在 PayPal 的响应无效时编写一些代码来执行某些操作".本质上,如果您将想要在来自 PayPal 的响应被验证时触发的代码复制到响应无效时运行的脚本部分,您可以向脚本发送一个虚拟帖子,以查看您的代码是否有效.由于脚本的虚拟帖子将返回 INVALID(因为帖子不是来自 PayPal),这就是您想要将代码添加到脚本的if INVALID"部分的原因.

If your script has a syntax or logic error in it, odds are you will not see the correct result. An easy way to test your script is by sending a "dummy" post to the script and writing some code to "do something" if the response from PayPal is INVALID. Essentially, if you copy the code that you want to fire when the response from PayPal is VERIFIED to the part of the script that runs if the response is INVALID, you can send a dummy post to the script to see if your code works. Since a dummy post to the script will return INVALID (since the post was not originated from PayPal), this is why you want to add the code to the 'if INVALID' part of your script.

  • 发布到您的返回 URL(返回方法)

某些商家的设置是,他们希望将 IPN 数据发布到其按钮代码(返回)中返回变量的值中.这是在进行 PayPal 付款后买家被定向到的 URL.要将 IPN 数据发布到您的返回 URL,您必须在按钮代码中将 rm 变量设置为等于2",否则您可能看不到任何 IPN 数据发布到您的返回 URL.有关更多信息,请参阅此帖子.** 请注意,此信息是关于可以通过返回传递的 IPN 数据以及它如何与您的返回 URL(按钮代码变量返回")一起使用.如果您启用了 PDT 的自动返回,则此信息不适用于您,因为 PDT 是其自己的独立功能.可在此处找到有关 PDT 的更多信息.

Some merchants are setup such that they would like to get IPN data posted to the value of their return variable in their button code (return). This is the URL the buyer is directed to after a PayPal payment has been made. To have IPN data POSTed to your return URL you must set the rm variable equal to "2" in your button code or you may not see any IPN data POSTed to your return URL. For more information see this post. ** Note that this information is about IPN data can be passed through the return and how it works with your return URL (button code variable 'return'). If you have Auto Return with PDT enabled this information does not apply to you as PDT is its own separate feature. More information on PDT can be found here.

故障排除提示 - IPN 延迟

在大多数情况下,当您的服务器对许多事务 IPN 没有响应 200ok 时,会导致 IPN 的持续延迟.例如,当您的服务器没有回复 200ok 时,PayPal 会尝试重新发布数据.在多次转发未收到 200ok 的数据后,您的 IPN 将移至较慢的循环服务器,因此会出现延迟.

In most cases consistent delays in IPNs are caused when your server is not responding with a 200ok for to many of your transaction IPNs. For example, when your sever does not reply with a 200ok PayPal attempts a repost of the data. After so many reposts of the data that do not receive the 200ok your IPNs get moved to a slower cycling server, hence the delays.

首先检查您的 IPN 日志以了解 POST 的状态:

First check your IPN Logs for the status of the POSTs:

在您帐户的历史记录部分下,您应该有一个IPN 历史记录"部分,您可以在其中查看过去 28 天的 IPN 值,并且在某些情况下可以重新发送它们.如果没有出现此链接,请登录您的帐户,然后转到此处:https://www.paypal.com/us/cgi-bin/webscr?cmd=_display-ipns-history

In your account under the history section you should have a "IPN History" section where you can see the last 28 days worth of IPNs and is some cases can resend them. If this link doe not appear for you log into your account than go here: https://www.paypal.com/us/cgi-bin/webscr?cmd=_display-ipns-history

这些日志会有几种不同的状态:

These logs will have a couple different statuses:

已发送 - 表示 PayPal 已将消息发送给您的 IPN 侦听器失败 - 表示 PayPal 未收到对原始 POST 尝试或重新 POST 消息的确认 (200ok)排队 - 表示 PayPal 已准备好发送消息Retrying - 表示 PayPal 没有收到 200ok 并且消息被重新发送了 1 到 15 次,并且 PayPal 正在继续重新发送消息已禁用 - 表示由于 IPN/帐户已被禁用,将不会重新发送消息

Sent - indicates that PayPal sent the message to your IPN listener Failed - indicates that PayPal did not receive an acknowledgement (200ok) to the message for the original POST attempt or re-POSTs Queued - indicates that PayPal is ready to send the message Retrying - indicates that PayPal did not receive a 200ok and the message was resent between 1 and 15 times and that PayPal is continuing to resend the message Disabled - indicates that the message will not be resent because IPN/The account has been disabled

如果您看到 Failed 或 Retrying 这很可能是解决此问题的原因,您将需要查看您的服务器日志以确定 200ok 没有被发送回 PayPal IPN 的原因.一旦确定并解决此问题,并且您的服务器以 200ok 响应,它就会从该限制中降低该百分比/计数,并且它将开始从正常周期服务器发布 IPN.

If you see Failed or Retrying this is most likely the cause to resolve this, you will need to go through your server logs to determine why the 200ok is not being sent back to PayPal IPN. Once this is determined and remedied and your server responds with a 200ok it brings this percentage/count down from that limit and it will begin posting IPNs from the normal cycle server.

如果没有失败,则可能是 PayPal 服务器本身出现延迟,在这种情况下,您需要创建一个到 PayPal 商家技术服务的票证作为 paypal.com/mts 以供进一步审查.

If there are no failed it may be a delay on PayPal Servers themselves in which case you will want to create a ticket to PayPal Merchant Technical Services as paypal.com/mts for further review.

Curl 与 fsockopen:这通常是个人偏好,但在某些情况下,您要使用的主机提供商不支持其中一个,因此您可能需要在两者之间切换.下面是一个使用 fsockopen 的例子:

Curl vs fsockopen: This is most often a personal preference but in some cases the host provider you are going to does not support one or the other so you may need to switch between the two. Here is an example of using fsockopen:

$header = "POST /cgi-bin/webscr HTTP/1.1
";
$header .= "Host: www.paypal.com
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "
";
$header .= "Connection: Close

";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

这是同样的事情,但使用 curl:

Here is the same thing but using curl:

$url= 'https://www.sandbox.paypal.com/cgi-bin/webscr';

$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);   
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$res = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);

基本上,如果您在使用一种方法时遇到问题,并且您认为这可能是由于您的主机/服务器不支持一种方法,而不是简单地将您正在使用的一种方法替换为另一种方法.

Basically if you are having trouble with one and you think it may be to one method not being supported by your host/server than simply replace the one you are using with the other.

本地测试:
这可能是生产和测试任何脚本中最重要的步骤之一.关于 IPN,这可用于将您需要的任何参数传递给您自己的脚本,以测试语法以及该脚本如何使用预期的变量运行.所有这一切真正需要的是设置一个表单,其中包含对您自己的 IPN 处理程序的 post 操作以及您要测试的变量/值的隐藏输入.

Local Testing:
This is probably on of the most important steps in production and testing any script. In regards to IPN this can be used to pass any parameter you need to your own script to test syntax and how that script will function with the variables expected. All this really would need is to set up a form with a post action to your own IPN handler and the hidden inputs for the variables/values you want to test.

例如:

<form target="_new" method="post" action="https://www.YourDomain.com/Path/IPNhandler.php">
<input type="hidden"  name="SomePayPalVar" value="SomeValue1"/>
<input type="hidden"  name="SomeOtherPPVar" value="SomeValue2"/>

Than etc for all  other variables you want to test with.

</br>
<input  type="submit"/>
</form>

正如在angelleye 的许多主题中所列出的,这里是一个很好的例子的链接本地测试,他已经设置了.

As listed in many of angelleye's threads here is a link to a good example of local testing that he has set up.

相关文章