我正在使用 PayPal 自己的 .NET 库来验证 IPN,特别是 IPNMessage.cs在 PayPalCoreSDK 1.5.0可通过NuGet获得(2014-09-09 发布)。
我是这样使用它的:
[HttpPost]
public ActionResult Ipn()
{
try
{
byte[] bytes = Request.BinaryRead(Request.ContentLength);
IPNMessage message = new IPNMessage(bytes);
string description = string.Format("PayPal IPN {0} {1} {2}",
message.IpnValue("txn_id"),
message.IpnValue("payment_type"),
message.IpnValue("payment_status"));
Trace.TraceInformation(description + " Received");
if (message.Validate())
{
Trace.TraceInformation(description + " Valid");
// do work here
}
else
{
Trace.TraceError(description + " Invalid");
}
}
catch (Exception e)
{
Trace.TraceError("PayPal IPN Exception: " + e.Message);
}
return null;
}
我的日志告诉我(txnId 已更改):
Application: 2014-09-11T19:52:40 PID[11584] Information PayPal IPN ABC536DEFP96XYZ3U instant Completed Received
Application: 2014-09-11T19:52:40 PID[11584] Error PayPal IPN ABC536DEFP96XYZ3U instant Completed Invalid
IPN 本身充满了我期望的所有键/值。当我登录 PayPal 并查看即时付款通知 (IPN) 历史记录部分时,我看到 IPN 具有匹配的交易 ID,并且其状态为“已发送”。我刚从 Validate()
返回 false
,因此 PayPal 不能回复“已验证”。没有抛出异常,我该如何调试?
最佳答案
原来我的应用程序甚至没有与 PayPal 通信。
PayPalCoreSDK 在 app.config/web.config 中需要以下内容:
<configuration>
<configSections>
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" />
</configSections>
<paypal>
<settings>
<add name="mode" value="sandbox" /> <!-- "live" or "sandbox" -->
</settings>
</paypal>
</configuration>
归功于 James Dibble
关于c# - 如何调试 PayPalCoreSDK IPN 验证失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25796377/