c# - 如何调试 PayPalCoreSDK IPN 验证失败?

标签 c# asp.net asp.net-mvc paypal paypal-ipn

我正在使用 PayPal 自己的 .NET 库来验证 IPN,特别是 IPNMessage.csPayPalCoreSDK 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/

相关文章:

c# - ADOMDCommand ExecuteCellSet 与 ExecuteReader

asp.net - IIS7 windows 2008启用双跳委派的步骤

c# - 防止在 ASP.NET MVC 和 Entity Framework 中更新未更改的值

c# - 如果每个 async 都有一个 await,并且每个 await 都应用于一个 async,那么它在哪里以及如何结束?

c# - CNG、CryptoServiceProvider 和 HashAlgorithm 的托管实现

c# - 绘制控件后如何在 Visual Studio 2010 RC Windows 窗体设计器中取回光标?

c# - 序列不包含元素

c# - 如何将来自外部项目的 Controller 和 View 包含到 MVC6 中?

asp.net-mvc - ASP.Net MVC : Request. IsAuthenticated 在成功登录后变为 false

c# - ASP.NET Core .css 扩展转到 Controller